Last active
October 2, 2020 05:23
-
-
Save peterjpxie/3717609b51c4b52d569305c8206ebc6a to your computer and use it in GitHub Desktop.
flask_server_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
import os | |
import json | |
from face_util import compare_faces, face_rec | |
app = Flask(__name__) | |
@app.route('/face_match', methods=['POST']) | |
def face_match(): | |
if request.method == 'POST': | |
# check if the post request has the file part | |
if ('file1' in request.files) and ('file2' in request.files): | |
file1 = request.files.get('file1') | |
file2 = request.files.get('file2') | |
ret = compare_faces(file1, file2) | |
resp_data = {"match": bool(ret)} # convert numpy._bool to bool for json.dumps | |
return json.dumps(resp_data) | |
@app.route('/face_rec', methods=['POST']) | |
def face_recognition(): | |
if request.method == 'POST': | |
# check if the post request has the file part | |
if 'file' in request.files: | |
file = request.files.get('file') | |
name = face_rec(file) | |
resp_data = {'name': name } | |
return json.dumps(resp_data) | |
# When debug = True, code is reloaded on the fly while saved | |
app.run(host='0.0.0.0', port='5001', debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment