-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.py
60 lines (52 loc) · 1.83 KB
/
app.py
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
from flask import Flask, render_template ,request, send_from_directory,Response
from flask import jsonify
import json
import re
import os
import scipy.misc
import warnings
import sys
import compare_image
import time
import detect_face
from werkzeug.utils import secure_filename
app = Flask(__name__)
@app.route('/api/v1/compare_faces', methods=['POST'])
def compare_faces():
target = request.files['target']
faces = request.files.getlist("faces")
target_filename=secure_filename(target.filename)
response=[]
for face in faces:
start = time.time()
distance,result = compare_image.main(target,face)
end=time.time()
json_contect={
'result':str(result),
'distance':round(distance,2),
'time_taken':round(end-start,3),
'target':target_filename,
'face':secure_filename(face.filename)
}
response.append(json_contect)
python2json = json.dumps(response)
return app.response_class(python2json, content_type='application/json')
@app.route('/api/v1/detect_faces', methods=['POST'])
def detect_faces():
faces = request.files.getlist("faces")
# target_filename=secure_filename(target.filename)
response=[]
for face in faces:
start = time.time()
_,result = detect_face.get_coordinates(face)
end=time.time()
json_contect={
'coordinates':result,
'time_taken':round(end-start,3),
'image_name':secure_filename(face.filename)
}
response.append(json_contect)
python2json = json.dumps(response)
return app.response_class(python2json, content_type='application/json')
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=8000)