-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_server.py
More file actions
75 lines (58 loc) · 2.32 KB
/
ai_server.py
File metadata and controls
75 lines (58 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# app.py - 완전 자동화된 AI 얼굴 등록 및 삭제 서버 (응답 형식 통일)
from flask import Flask, request, jsonify
import os
import shutil
import subprocess
from update import update_photos
from delete_user import delete_user
app = Flask(__name__)
UPLOAD_DIR = 'uploads'
os.makedirs(UPLOAD_DIR, exist_ok=True)
@app.route('/health', methods=['GET'])
def health():
return jsonify({'success': True}), 200
@app.route('/register_face', methods=['POST'])
def register_face():
try:
pid = request.form.get('identifier')
file = request.files.get('file')
if not pid or not file:
return jsonify({'success': False, 'error': 'Missing identifier or file'}), 400
video_path = os.path.join(UPLOAD_DIR, f"{pid}.mp4")
file.save(video_path)
# 등록 및 재학습 수행
update_photos(pid=pid, video_path=video_path, every_n_frames=5)
# 자동 삭제
if os.path.exists(video_path):
os.remove(video_path)
return jsonify({'success': True}), 200
except subprocess.CalledProcessError:
return jsonify({'success': False, 'error': 'Classifier training failed'}), 500
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/delete_face', methods=['POST'])
def delete_face():
try:
pid = request.form.get('identifier')
remove_folder = request.form.get('remove_folder', 'false').lower() == 'true'
if not pid:
return jsonify({'success': False, 'error': 'Missing identifier'}), 400
delete_user(pid, remove_folder=remove_folder)
return jsonify({'success': True}), 200
except subprocess.CalledProcessError:
return jsonify({'success': False, 'error': 'Classifier training failed'}), 500
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/clear_uploads', methods=['POST'])
def clear_uploads():
try:
shutil.rmtree(UPLOAD_DIR)
os.makedirs(UPLOAD_DIR, exist_ok=True)
return jsonify({'success': True}), 200
except Exception as e:
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/')
def home():
return '✅ AI 서버가 정상 작동 중입니다.'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False)