-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
56 lines (41 loc) · 1.35 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# coding: utf-8
# In[36]:
# Importing essential libraries
from flask import Flask, render_template, request
import pickle
import numpy as np
import sys
# In[37]:
# Load the Random Forest CLassifier model
filename = 'diabetes.pkl'
classifier = pickle.load(open(filename, 'rb'))
# In[44]:
app = Flask(__name__,static_url_path='', static_folder='./templates')
@app.route('/')
def home():
try:
return render_template('./home.html')
except:
ops = str(sys.exc_info())
return('<h1>Oops!' + ops + 'occurred</h1>')
@app.route('/predict', methods=['POST'])
def predict():
try:
if request.method == 'POST':
preg = request.form['pregnancies']
glucose = request.form['glucose']
bp = request.form['bloodpressure']
st = request.form['skinthickness']
insulin = request.form['insulin']
bmi = request.form['bmi']
dpf = request.form['dpf']
age = request.form['age']
data = np.array([[preg, glucose, bp, st, insulin, bmi, dpf, age]])
my_prediction = classifier.predict(data)
return render_template('./result.html', prediction=my_prediction)
except:
ops = str(sys.exc_info())
return('<h1>Oops!' + ops + 'occurred</h1>')
if __name__ == '__main__':
app.run(debug=True)