Sathishkumar commited on
Commit
ad6132e
1 Parent(s): 8b3e147

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from flask import Flask, request, jsonify, render_template
3
+ import pickle
4
+ from sklearn.preprocessing import normalize
5
+
6
+ app = Flask(__name__)
7
+ model = pickle.load(open('model.pkl', 'rb'))
8
+
9
+ @app.route('/')
10
+ def home():
11
+ return render_template('index.html')
12
+
13
+ @app.route('/predict',methods=['POST'])
14
+ def predict():
15
+ '''
16
+ For rendering results on HTML GUI
17
+ '''
18
+ Age=float(request.form['Age'])
19
+ CigsPerDay=float(request.form['CigsPerDay'])
20
+ Cholestrol=float(request.form['Cholestrol'])
21
+ SysBP=float(request.form['SysBP'])
22
+ DIaBP=float(request.form['DIaBP'])
23
+ BMI=float(request.form['BMI'])
24
+ HeartRate=float(request.form['HeartRate'])
25
+ GlucoseLevel=float(request.form['GlucoseLevel'])
26
+ Gender=float(request.form['Gender'])
27
+ BpMedication=float(request.form['BpMedication'])
28
+ PrevalentStroke=float(request.form['PrevalentStroke'])
29
+ Smoker=float(request.form['Smoker'])
30
+ list_to_be_normalised=np.array([ Age,CigsPerDay, Cholestrol, SysBP,DIaBP, BMI,HeartRate,GlucoseLevel]).reshape(1,-1)
31
+ normalized = normalize(list_to_be_normalised)
32
+ boolean = [Gender,BpMedication,PrevalentStroke,Smoker]
33
+ final_features = np.append(normalized,boolean).reshape(1, -1)
34
+ print(final_features)
35
+ prediction = model.predict(final_features)
36
+
37
+ if prediction == 1:
38
+ return render_template('problem.html')
39
+ else:
40
+ return render_template('healthy.html')
41
+ # @app.route('/predict_api',methods=['POST'])
42
+ # def predict_api():
43
+ # '''
44
+ # For direct API calls trought request
45
+ # '''
46
+ # data = request.get_json(force=True)
47
+ # prediction = model.predict([np.array(list(data.values()))])
48
+
49
+ # output = prediction[0]
50
+ # return jsonify(output)
51
+
52
+ if __name__ == "__main__":
53
+ app.run(debug=True)