-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
34 lines (27 loc) · 1.04 KB
/
app.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
from flask import Flask, render_template, request
import os
import cv2
from PIL import Image
from infer import infer_one
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return render_template('index.html', contents=None)
@app.route('/upload', methods=['POST'])
def upload_file():
uploaded_file = request.files['file']
if uploaded_file.filename != '':
image = Image.open(uploaded_file)
image.save('/home/Aket95/mysite/static/this.png')
#call infer.py here
result, conf_score = infer_one(imgpath='/home/Aket95/mysite/static/this.png')
##############################
contents = '_'.join(uploaded_file.filename.split('_')[2:3]) + ' is '
contents += 'stable' if result else 'unstable'
contents += ' with ' + str(conf_score) + f'% confidence'
return render_template('index.html', contents=contents)
else:
return render_template('index.html', contents=None)
if __name__ == '__main__':
print('WORK DIR', os.getcwd())
app.run(debug=False)