app.py
2.68 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
76
77
78
79
80
81
82
83
84
85
86
87
88
import sys
import os
from flask.helpers import url_for
from face_emotion_recognition import face_recognition, video4
from flask import Flask, render_template
from flask.globals import request
from werkzeug.utils import redirect, secure_filename
def find_face_imgs():
face_imgs = []
id = 1
for img_name in os.listdir('static/img'):
if(img_name.rsplit('.')[1] == 'jpg' or img_name.rsplit('.')[1] == 'png'):
face_imgs.append(
{
'id': id,
'name': img_name.rsplit('.')[0],
'imgUrl': 'img/' + img_name
})
id += 1
return face_imgs
# Flask 객체 인스턴스 생성
app = Flask(__name__)
@app.route('/', methods=('GET', 'POST')) # 접속하는 url
def index():
if request.method == 'POST':
return render_template('index.html', face_imgs=find_face_imgs())
elif request.method == 'GET':
return render_template('index.html', face_imgs=find_face_imgs())
@app.route('/goTest', methods=('GET', 'POST')) # 접속하는 url
def test():
if request.method == 'GET':
return render_template('test.html')
@app.route('/uploadFace', methods=('GET', 'POST'))
def upload_face():
if request.method == 'GET':
return render_template('upload.html')
elif request.method == 'POST':
f = request.files.get('file')
f.save("./static/img/" + secure_filename(f.filename))
face_recognition.face_to_npy()
return redirect(url_for('index'))
@app.route('/deleteFace/<string:face_name>')
def delete_face(face_name):
print("request좀 보여줘", face_name)
os.remove("./static/img/" + face_name + '.jpg')
face_recognition.face_to_npy()
return redirect(url_for('index'))
@app.route('/uploadVideo', methods=('GET', 'POST'))
def upload_video():
if request.method == 'POST':
f = request.files.get('video')
f.save("./static/video/" + secure_filename(f.filename))
return redirect(url_for('test'))
@app.route('/faceEmotionRecognition', methods=('GET', 'POST'))
def faceEmotionRecognition():
if request.method == 'POST':
f = request.files.get('video')
f.save("./static/video/" + secure_filename(f.filename))
seconds = float(request.form['seconds'])
face_emotion_dict = video4.videoDetector(
seconds, secure_filename(f.filename))
print(face_emotion_dict)
file_name = 'video/' + secure_filename(f.filename)
return render_template('result.html', face_emotion_dict=face_emotion_dict, face_imgs=find_face_imgs(), file_name=file_name)
return redirect(url_for('test'))
if __name__ == "__main__":
app.debug = True
app.run()