Update 'face_recognition/app/app.py'

anpassen der api, noch kritisch
This commit is contained in:
fabrice 2019-06-23 16:53:54 +00:00
parent f01c6ff6ab
commit e240ae0f58

View File

@ -5,6 +5,7 @@ import os
import uuid
import pickle
import face_recognition
from werkzeug.datastructures import ImmutableMultiDict
app = Flask(__name__)
minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False)
@ -32,26 +33,32 @@ def new_user_id():
minioClient.fput_object('users', str(id), '/tmp/demo_object.pkl')
return(id)
@app.route('/init_face')
#call like https://face.sguba.de/init_face?id=123&upload_id=123
@app.route('/init_face', methods=["POST"])
#call like https://face.sguba.de/init_face?id=123&encoded_string=abc
def new_face():
id = request.args.get('id', None)
upload_id = request.args.get('upload_id', None)
minioClient.fget_object('uploads', upload_id, '/tmp/'+str(upload_id))
face = face_recognition.load_image_file('/tmp/'+str(upload_id))
data = dict(request.form)
img=data['content']
imgdata = base64.b64decode(img)
with open('/tmp/'+str(id), 'wb') as file:
file.write(imgdata)
face = face_recognition.load_image_file('/tmp/'+str(id))
face_encoding = face_recognition.face_encodings(face)[0]
with open('/tmp/'+str(id)+'.pkl', 'wb') as file:
pickle.dump(face_encoding, file)
minioClient.fput_object('users', str(id), '/tmp/'+str(id)+'.pkl')
return str(id) + str(upload_id)
@app.route('/check_face')
#call like https://face.sguba.de/check_face?id=123&upload_id=123
@app.route('/check_face', methods=["POST"])
#call like https://face.sguba.de/check_face?id=123&encoded_string=abc
def check_face():
id = request.args.get('id', None)
upload_id = request.args.get('upload_id', None)
minioClient.fget_object('uploads', upload_id, '/tmp/'+str(upload_id))
face = face_recognition.load_image_file('/tmp/'+str(upload_id))
data = dict(request.form)
img=data['content']
imgdata = base64.b64decode(img)
with open('/tmp/'+str(id), 'wb') as file:
file.write(imgdata)
face = face_recognition.load_image_file('/tmp/'+str(id))
face_encoding = face_recognition.face_encodings(face)[0]
minioClient.fget_object('users', str(id), '/tmp/'+str(id))
with open('/tmp/'+str(id), 'rb') as file: