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