[1a09bc]: / flask / app.py

Download this file

41 lines (30 with data), 1.1 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
import numpy as np
import pandas as pd
from flask import Flask, request, jsonify, render_template
import pickle
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
dataset = pd.read_csv('diabetes.csv')
dataset_X = dataset.iloc[:,[1, 2, 5, 7]].values
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0,1))
dataset_scaled = sc.fit_transform(dataset_X)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
float_features = [float(x) for x in request.form.values()]
final_features = [np.array(float_features)]
prediction = model.predict( sc.transform(final_features) )
if prediction == 1:
pred = "You have Diabetes, please consult a Doctor."
elif prediction == 0:
pred = "You don't have Diabetes."
output = pred
return render_template('index.html', prediction_text='{}'.format(output))
if __name__ == "__main__":
app.run(debug=True)