Diff of /flask/app.py [000000] .. [1a09bc]

Switch to unified view

a b/flask/app.py
1
import numpy as np
2
import pandas as pd
3
from flask import Flask, request, jsonify, render_template
4
import pickle
5
6
app = Flask(__name__)
7
model = pickle.load(open('model.pkl', 'rb'))
8
9
dataset = pd.read_csv('diabetes.csv')
10
11
dataset_X = dataset.iloc[:,[1, 2, 5, 7]].values
12
13
from sklearn.preprocessing import MinMaxScaler
14
sc = MinMaxScaler(feature_range = (0,1))
15
dataset_scaled = sc.fit_transform(dataset_X)
16
17
18
@app.route('/')
19
def home():
20
    return render_template('index.html')
21
22
@app.route('/predict',methods=['POST'])
23
def predict():
24
    '''
25
    For rendering results on HTML GUI
26
    '''
27
    float_features = [float(x) for x in request.form.values()]
28
    final_features = [np.array(float_features)]
29
    prediction = model.predict( sc.transform(final_features) )
30
31
    if prediction == 1:
32
        pred = "You have Diabetes, please consult a Doctor."
33
    elif prediction == 0:
34
        pred = "You don't have Diabetes."
35
    output = pred
36
37
    return render_template('index.html', prediction_text='{}'.format(output))
38
39
if __name__ == "__main__":
40
    app.run(debug=True)