-
Notifications
You must be signed in to change notification settings - Fork 23
/
hello.py
41 lines (28 loc) · 953 Bytes
/
hello.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
import numpy as np
from flask import Flask, request, render_template
import pickle
from fastai.vision import *
from fastai import *
import os
cwd = os.getcwd()
path = Path()
application = Flask(__name__)
model = load_learner(path, 'model/export.pkl')
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
#labels = ['grizzly','black','teddy']
file = request.files['file']
#Store the uploaded images in a temporary folder
if file:
filename = file.filename
file.save(os.path.join("resources/tmp", filename))
to_predict = "resources/tmp/"+filename
img = open_image(to_predict)
#Getting the prediction from the model
prediction = model.predict(img)[0]
#Render the result in the html template
return render_template('index.html', prediction_text='Your Prediction : {} '.format(prediction))