Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, jsonify, request, redirect, url_for
|
2 |
+
from prediction import getAgeGender
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
|
7 |
+
mediaDir = "./static/uploaded/"
|
8 |
+
|
9 |
+
|
10 |
+
@app.route("/", methods = ['GET'])
|
11 |
+
def index():
|
12 |
+
if request.method=='GET':
|
13 |
+
return render_template("index.html")
|
14 |
+
else:
|
15 |
+
print("Post request sent on Home Page.")
|
16 |
+
return render_template("index.html")
|
17 |
+
|
18 |
+
|
19 |
+
@app.route("/predict", methods = ['GET', 'POST'])
|
20 |
+
def predict():
|
21 |
+
if request.method=='GET':
|
22 |
+
return redirect(url_for('index'))
|
23 |
+
else:
|
24 |
+
f = request.files['upload']
|
25 |
+
if f.filename != "":
|
26 |
+
image_path = mediaDir+f.filename
|
27 |
+
uploaded_file_path = "uploaded/"+f.filename
|
28 |
+
f.save(image_path)
|
29 |
+
age, gender = getAgeGender(image_path)
|
30 |
+
return render_template("prediction.html", AGE=age, GENDER=gender, FILEPATH=uploaded_file_path)
|
31 |
+
else:
|
32 |
+
return render_template("no_image.html")
|
33 |
+
|
34 |
+
|
35 |
+
@app.errorhandler(404)
|
36 |
+
def page_not_found(error):
|
37 |
+
return render_template('404.html'), 404
|
38 |
+
|
39 |
+
|
40 |
+
if __name__ == '__main__':
|
41 |
+
app.run(host="0.0.0.0", port=80, use_reloader=True, debug=True)
|