-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
114 lines (82 loc) · 3.3 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Importing essential libraries
from flask import Flask, render_template, request
import pickle
import numpy as np
import pandas as pd
# Load the Random Forest CLassifier model
import pickle
from pycaret.classification import load_model
loaded_model = load_model('rfmodel')
with open('model.pkl', 'wb') as file:
pickle.dump(loaded_model, file)
with open('model.pkl', 'rb') as file:
loaded_model = pickle.load(file)
#model2DT
loaded_model2 = load_model('dtmodel')
with open('model2.pkl', 'wb') as file:
pickle.dump(loaded_model2, file)
with open('model2.pkl', 'rb') as file:
loaded_model2 = pickle.load(file)
#model3lr
loaded_model3 = load_model('lrmodel')
with open('model3.pkl', 'wb') as file:
pickle.dump(loaded_model3, file)
with open('model3.pkl', 'rb') as file:
loaded_model3 = pickle.load(file)
#model4knn
loaded_model4= load_model('knnmodel')
with open('model4.pkl', 'wb') as file:
pickle.dump(loaded_model4, file)
with open('model4.pkl', 'rb') as file:
loaded_model4 = pickle.load(file)
#model5nb
loaded_model5= load_model('nbmodel')
with open('model5.pkl', 'wb') as file:
pickle.dump(loaded_model5, file)
with open('model5.pkl', 'rb') as file:
loaded_model5 = pickle.load(file)
#model6svm
loaded_model6= load_model('svmmodel')
with open('model6.pkl', 'wb') as file:
pickle.dump(loaded_model6, file)
with open('model6.pkl', 'rb') as file:
loaded_model6 = pickle.load(file)
app = Flask(__name__)
@app.route('/')
def home():
return render_template('main.html')
@app.route('/predict', methods=['GET','POST'])
def predict():
if request.method == 'POST':
age = int(request.form['age'])
sex = request.form.get('sex')
cp = request.form.get('cp')
trestbps = int(request.form['trestbps'])
chol = int(request.form['chol'])
fbs = request.form.get('fbs')
restecg = int(request.form['restecg'])
thalach = int(request.form['thalach'])
exang = request.form.get('exang')
oldpeak = float(request.form['oldpeak'])
slope = request.form.get('slope')
ca = int(request.form['ca'])
thal = request.form.get('thal')
sample_df = pd.DataFrame([[age, sex, cp, trestbps, chol, fbs, restecg, thalach,
exang, oldpeak, slope, ca, thal]], columns=['age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach',
'exang', 'oldpeak', 'slope', 'ca', 'thal'], index=['input'])
# Make predictions using the loaded model
predictions = loaded_model.predict(sample_df)
predictions2 = loaded_model2.predict(sample_df)
predictions3 = loaded_model3.predict(sample_df)
predictions4 = loaded_model4.predict(sample_df)
predictions5 = loaded_model5.predict(sample_df)
predictions6 = loaded_model6.predict(sample_df)
print(predictions)
print(predictions2)
print(predictions3)
print(predictions4)
print(predictions5)
print(predictions6)
return render_template('result.html', prediction=predictions, prediction2=predictions2, prediction3=predictions3, prediction4=predictions4, prediction5=predictions5, prediction6=predictions6)
if __name__ == '__main__':
app.run(debug=True)