-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
94 lines (59 loc) · 2.37 KB
/
Copy pathapp.py
File metadata and controls
94 lines (59 loc) · 2.37 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from flask import Flask, render_template, session, redirect, url_for, session
from flask_wtf import FlaskForm
from wtforms import TextField,SubmitField
from wtforms.validators import NumberRange
import numpy as np
from tensorflow.keras.models import load_model
import joblib
def return_prediction(model,scaler,sample_json):
# For larger data features, you should probably write a for loop
# That builds out this array for you
p1 = sample_json['param1']
p2 = sample_json['param2']
p3 = sample_json['param3']
p4 = sample_json['param4']
pjoint = [[p1,p2,p3,p4]]
pjoint = scaler.transform(pjoint)
classes = np.array(['Healthy', 'Non-Covid ILI', 'COVID'])
class_ind = model.predict_classes(pjoint)
return classes[class_ind][0]
app = Flask(__name__)
# Configure a secret SECRET_KEY
# We will later learn much better ways to do this!!
app.config['SECRET_KEY'] = 'someRandomKey'
# REMEMBER TO LOAD THE MODEL AND THE SCALER!
my_model = load_model("final_iris_model.h5")
my_scaler = joblib.load("iris_scaler.pkl")
# Now create a WTForm Class
# Lots of fields available:
# http://wtforms.readthedocs.io/en/stable/fields.html
class FlowerForm(FlaskForm):
param1 = TextField('param1')
param2 = TextField('param2')
param3 = TextField('param3')
param4 = TextField('param4')
submit = SubmitField('Predict')
@app.route('/', methods=['GET', 'POST'])
def index():
# Create instance of the form.
form = FlowerForm()
# If the form is valid on submission (we'll talk about validation next)
if form.validate_on_submit():
# Grab the data from the breed on the form.
session['param1'] = form.param1.data
session['param2'] = form.param2.data
session['param3'] = form.param3.data
session['param4'] = form.param4.data
return redirect(url_for("prediction"))
return render_template('home.html', form=form)
@app.route('/prediction')
def prediction():
content = {}
content['param1'] = float(session['param1'])
content['param2'] = float(session['param2'])
content['param3'] = float(session['param3'])
content['param4'] = float(session['param4'])
results = return_prediction(model=my_model,scaler=my_scaler,sample_json=content)
return render_template('prediction.html',results=results)
if __name__ == '__main__':
app.run(debug=True)