-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
105 lines (94 loc) · 4.05 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from flask import Flask, request, render_template, flash, redirect, url_for , session
from flask import send_from_directory
import os
from werkzeug import secure_filename
import subprocess
# Flask constructor
app = Flask(__name__)
app.secret_key = "super secret key"
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
image_path = os.getcwd()
app.config['UPLOAD_IMAGE'] = image_path+"\\test_image"
# A decorator used to tell the application
# which URL is associated function
@app.route('/', methods =["GET", "POST"])
def addName():
if request.method == "POST":
# getting input with name = fname in HTML form
first_name = request.form.get("fname")
# getting input with name = lname in HTML form
#last_name = request.form.get("lname")
#give path to location where you want to create folder
path = os.getcwd();
path = path+"\\faceImages\\"+first_name
os.mkdir(path)
app.config['UPLOAD_FOLDER'] = path
return redirect(url_for("uploadpicture") )
return render_template("index.html")
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route("/uploadpicture", methods =["GET", "POST"])
def uploadpicture():
if request.method == 'POST':
# check if the post request has the file part
"""if 'file' not in request.files:
flash('No file part')
return redirect(url_for("uploadpicture"))
"""
#file = request.files['file']
files = request.files.getlist('file')
# if user does not select file, browser also
# submit an empty part without filename
for file in files:
if file.filename == '':
flash('No selected file')
return redirect(url_for("uploadpicture"))
if file and allowed_file(file.filename):
filename = file.filename
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for("addName"))
return render_template("uploadpicture.html")
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],filename)
@app.route('/run_embedding')
def run_embedding():
result = subprocess.check_output("python generateFaceEmbedded.py", shell=True)
return render_template('index.html', **locals(), embedding = "Uploaded Images are Embedded")
@app.route('/train_model')
def train_model():
subprocess.getoutput("python encryptedClassification.py")
return render_template('index.html', **locals(), training = "Model is trained with the uploaded images")
@app.route('/recognize_face')
def recognize_face():
subprocess.getoutput("python faceRecognizer.py")
return render_template('index.html', **locals())
@app.route('/recognize_faceImage')
def recognize_faceImage():
subprocess.getoutput("python encryptedPrediction.py")
return render_template('index.html', **locals())
@app.route("/uploadFaceImage", methods =["GET", "POST"])
def uploadFaceImage():
if request.method == 'POST':
# check if the post request has the file part
"""if 'file' not in request.files:
flash('No file part')
return redirect(url_for("uploadpicture"))
"""
#file = request.files['file']
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
flash('No selected file')
return render_template("index.html")
if file and allowed_file(file.filename):
filename = file.filename
file.save(os.path.join(app.config['UPLOAD_IMAGE'], filename))
#return redirect(url_for("addName"))
return render_template("index.html")
return render_template("index.html")
if __name__=='__main__':
#app.run()
app.run(debug = True)