-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver2.py
73 lines (54 loc) · 2.21 KB
/
server2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
import faceRecognizer
import os
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from flask_socketio import SocketIO, send, emit
import base64
import Image
faceRecognizer.enroll_faces()
app = Flask(__name__)
app.config['SECRET_KEY'] = 'mysecret'
socketio = SocketIO(app)
dir_path = os.path.dirname(os.path.realpath(__file__))
app.config['UPLOAD_FOLDER'] = 'user_uploads/'
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpg', 'jpeg', 'gif'])
@socketio.on('faceverify')
def faceverify(payload):
img_data = payload['picture'][23:]
imgdata = base64.b64decode(payload['picture'][23:])
fh = open("./dump/imageToSave.webp", "wb")
fh.write(img_data.decode('base64'))
fh.close()
im = Image.open("./dump/imageToSave.webp").convert("RGB")
im.save("./actual/final_image.jpg","jpeg")
try:
account_id = faceRecognizer.facerec(dir_path + '/actual/final_image.jpg')
print('AccountId: ',account_id)
emit('faceverify',{'acc_no':account_id})
except:
print('Boohoo')
emit('faceverify',{'acc_no':'0000'})
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload():
file = request.files['file']
if file and allowed_file(file.filename):
filename = file.filename
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
@app.route('/uploads/<filename>')
def uploaded_file(filename):
faceRecognizer.enroll_faces() #TO-DO: Yeh bakwass hai faaltu ka slowdown. Remove this in the future
account_id = faceRecognizer.facerec(dir_path + '/user_uploads/'+ filename)
return account_id
#print account_id
#return send_from_directory(app.config['UPLOAD_FOLDER'],
# filename)
#Use port 7979 for listening in. Cheers bruh
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', debug = True, port = 3111, use_reloader = True) #Open localhost:3110 to run this in your browser -.-