forked from avinassh/pytorch-flask-api-heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
28 lines (21 loc) · 832 Bytes
/
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
import os
from flask import Flask, render_template, request, redirect
from inference import get_prediction
from commons import format_class_name
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files.get('file')
if not file:
return
img_bytes = file.read()
class_id, class_name = get_prediction(image_bytes=img_bytes)
class_name = format_class_name(class_name)
return render_template('result.html', class_id=class_id,
class_name=class_name)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True, port=int(os.environ.get('PORT', 5000)))