-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
56 lines (47 loc) · 1.72 KB
/
server.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
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
import label_image
from werkzeug import secure_filename
def script_caller(image):
print("IN SCRIPT CALLER")
graph = "retrained_graph.pb" # on site
#image = "images/post/20.jpeg" # user input
textFile = "retrained_labels.txt" #on the site
return label_image.function(graph, image, textFile)
@app.after_request
def add_header(r):
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"
r.headers['Cache-Control'] = 'public, max-age=0'
return r
@app.route("/", methods=['GET', 'POST'])
def root():
return render_template('index.html')
@app.route('/uploader', methods = ['POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
print("BEFORE SAVE")
f.save('static/user_upload.jpeg')
print("AFTER SAVE")
return do_things('static/user_upload.jpeg')
# return 'file uploaded successfully'
@app.route('/results')
def do_things(image = None):
print("IN DO THINGS")
(labels, confidences) = script_caller(image)
print("AFTER SCRIPT CALLER")
the_label = "None"
for i in range(len(labels)):
if(confidences[i]) > 0.5:
the_label = labels[i]
the_confidence = confidences[i]
print("PRETTY MUCH DONE LOL")
return render_template('results.html', label = the_label, confidence = the_confidence)
if __name__ == "__main__":
app.run(host = "0.0.0.0", port = 8000, debug = True)