Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (44 loc) · 1.63 KB
/
Copy pathapp.py
File metadata and controls
59 lines (44 loc) · 1.63 KB
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
import sys
import os
absolute_path = os.path.dirname(__file__)
sys.path.insert(0, absolute_path)
from flask import Flask, render_template, request
from models import ResNet, EyeQ
import os
import glob
from math import floor
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join(app.root_path, 'static/uploads')
model = ResNet()
model_quality = EyeQ()
@app.route('/')
def index():
# delete all uploaded files
files = glob.glob(app.config['UPLOAD_FOLDER']+r'/*')
for f in files:
os.remove(f)
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/infer', methods=['POST'])
def success():
if request.method == 'POST':
f = request.files['file']
saveLocation = os.path.join(app.config['UPLOAD_FOLDER'], f.filename )
f.save(saveLocation)
print(saveLocation)
quality_image= model_quality.infer(saveLocation)
inference, confidence, prep_img, heat_img = model.infer(saveLocation)
# make a percentage with 2 decimal points
confidence = floor(confidence * 10000) / 100
#save pil image prep_img
imgLocation= os.path.join(app.config['UPLOAD_FOLDER'], 'prep_eye.jpg' )
prep_img.save(imgLocation)
heat_Location= os.path.join(app.config['UPLOAD_FOLDER'], 'heat_eye.jpg' )
heat_img.save(heat_Location)
# respond with the inference
return render_template('inference.html', name=inference, confidence=confidence, quality_input=quality_image )
if __name__ == '__main__':
#port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0')