face-recognition-app/face_recognition/app/app.py

64 lines
1.8 KiB
Python
Raw Normal View History

2019-06-08 17:25:13 +00:00
from flask import Flask
2019-06-08 19:08:20 +00:00
from minio import Minio
2019-06-10 09:59:39 +00:00
from minio.error import (ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists)
2019-06-08 18:59:15 +00:00
import os
2019-06-10 10:31:07 +00:00
import uuid
2019-06-11 10:17:19 +00:00
import pickle
2019-06-08 17:11:05 +00:00
app = Flask(__name__)
2019-06-11 09:44:32 +00:00
minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False)
2019-06-08 17:11:05 +00:00
@app.route('/')
def hello_docker():
return 'Hello, I run in a docker container'
2019-06-08 18:59:15 +00:00
@app.route('/acces_minio')
def access_minio():
2019-06-10 09:46:47 +00:00
for bucket in minioClient.list_buckets():
2019-06-10 10:35:09 +00:00
print(bucket.name, bucket.creation_date, flush=True)
2019-06-10 09:41:07 +00:00
return('Connection Succesfull')
2019-06-11 09:24:06 +00:00
@app.route('/new_user_id')
def new_user_id():
2019-06-11 11:04:42 +00:00
#demo objekt speichern um id zu 'speichern'. Später mit if (type(object)==list oä überschreiben mit face_encoding.pkl
2019-06-11 09:24:06 +00:00
id = None
for limited_try in range(0,5):
2019-06-11 09:41:28 +00:00
id = str(uuid.uuid4())
2019-06-11 09:38:30 +00:00
if check_id(id) == False:
2019-06-11 09:24:06 +00:00
break
2019-06-11 10:17:19 +00:00
demo_object = ['test']
2019-06-11 10:42:46 +00:00
with open('/tmp/demo_object.pkl', 'wb') as f:
2019-06-11 10:28:25 +00:00
pickle.dump(demo_object, f)
2019-06-11 10:43:39 +00:00
minioClient.fput_object('users', str(id), '/tmp/demo_object.pkl')
2019-06-11 09:24:06 +00:00
return(id)
2019-06-13 11:31:17 +00:00
2019-06-13 11:38:40 +00:00
@app.route('/init_face')
def new_face():
id = request.args.get('id', None)
2019-06-13 11:31:17 +00:00
return id
2019-06-11 09:24:06 +00:00
def check_id(id):
2019-06-11 10:17:19 +00:00
#return True -> id bereits verwendet
2019-06-11 09:24:06 +00:00
#return False -> id noch nicht verwendet
users = minioClient.list_objects('users')
known = False
for user in users:
2019-06-11 10:54:43 +00:00
if id == user.object_name:
2019-06-11 09:24:06 +00:00
known = True
else:
pass
return known
2019-06-10 10:31:07 +00:00
2019-06-10 09:59:39 +00:00
def setup():
try:
minioClient.make_bucket("users")
2019-06-10 10:37:12 +00:00
except BucketAlreadyOwnedByYou as err:
2019-06-10 09:59:39 +00:00
pass
2019-06-10 10:37:12 +00:00
except BucketAlreadyExists as err:
2019-06-10 09:59:39 +00:00
pass
2019-06-10 10:37:12 +00:00
except ResponseError as err:
2019-06-10 09:59:39 +00:00
raise
2019-06-08 17:11:05 +00:00
if __name__ == '__main__':
2019-06-11 09:07:04 +00:00
setup()
2019-06-08 17:11:05 +00:00
app.run(host='0.0.0.0')