-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (37 loc) · 1.42 KB
/
app.py
File metadata and controls
43 lines (37 loc) · 1.42 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
from flask import Flask, request, render_template, send_from_directory
from web_predict import predict
import os
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLDER = 'static/img/uploaded'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET','POST'])
def hello_world():
if request.method == 'GET':
return render_template('index.html')
if request.method == 'POST':
print(request.files)
target = os.path.join(APP_ROOT,'static/img/uploaded')
if 'file' not in request.files:
print('file not uploaded')
return render_template('index.html')
# return
file = request.files['file']
if file and allowed_file(file.filename):
filename = file.filename
dest = 'static/img/uploaded/'+filename
file.stream.seek(0)
file.save(dest)
print(dest)
file.stream.seek(0)
image = file.read()
probs,name = predict(image)
return render_template('result.html',name=name.capitalize(),probs=probs[0],image_file=dest)
@app.route('/uploads/<filename>')
def send_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
if __name__ == '__main__':
app.run(debug=True)