-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
155 lines (120 loc) · 4.79 KB
/
main.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from flask import Flask, render_template, request
import pickle
app = Flask(__name__)
# machine learning
def PredictBC(data):
model = pickle.load(open('breast-dataset/model.pkl', 'rb'))
pred = model.predict([data])
if pred[0]==2:
pred = 'Benign'
else:
pred = 'Malignant'
return pred
def PredictLC(data):
model = pickle.load(open('lung-dataset/lung_reg.sav','rb'))
pred = model.predict([data])
pred = pred[0]*100
return str(pred)+'%'
def PredictPC(data):
model = pickle.load(open('prostate-dataset/prostate.sav','rb'))
pred = model.predict([data])
pred = pred[0]*100
return str(pred)+'%'
# routes
@app.route('/')
def index():
title = 'Cancer Prediction'
return render_template("home.html",title=title)
@app.route('/team')
def team():
title = 'Team'
return render_template("team.html",title=title)
@app.route('/breastcancer')
def breastCancer():
title = 'Breast Cancer'
return render_template("index.html", title=title)
@app.route('/lungcancer')
def lungCancer():
title = 'Lung Cancer'
return render_template("index2.html", title=title)
@app.route('/prostateCancer')
def prostateCancer():
title = 'Prostate Cancer'
return render_template("index3.html", title = title)
# processing the data from the webpages
@app.route('/lungresult', methods= ["POST"])
def lungResult():
title = 'Prediction'
data = []
try:
q = ''
q = (request.form.get('gender'))
if q=='F':
data.append(0)
elif q=='M':
data.append(1)
else:
return render_template('invalid.html',title=title,output='Invalid Gender')
data.append(int(request.form.get('age')))
data.append(int(request.form.get('smoking')))
data.append(int(request.form.get('yellow_fingers')))
data.append(int(request.form.get('anxiety')))
data.append(int(request.form.get('peer_pressure')))
data.append(int(request.form.get('chronic_disease')))
data.append(int(request.form.get('fatigue')))
data.append(int(request.form.get('allergy')))
data.append(int(request.form.get('wheezing')))
data.append(int(request.form.get('alcohol_consuming')))
data.append(int(request.form.get('coughing')))
data.append(int(request.form.get('shortness_of_breath')))
data.append(int(request.form.get('swallowing_difficulty')))
data.append(int(request.form.get('chest_pain')))
print(data)
output = PredictLC(data)
return render_template("lungPredict.html", title=title,output = output )
except:
return render_template('invalid.html',title=title,output='Invalid data format')
@app.route('/breastResult',methods = ["POST"])
def breastResult():
title = 'Prediction'
data = []
# for i in range(0,len(breastCancerCols)):
# info = request.form.get(breastCancerCols[i])
# print(info)
# if info.isdigit:
# data.append(int(info))
# print(data)
try:
data.append(int(request.form.get('clump_thickness')))
data.append(int(request.form.get('uniform_cell_size')))
data.append(int(request.form.get('uniform_cell_shape')))
data.append(int(request.form.get('marginal_adhesion')))
data.append(int(request.form.get('single_epithelial_size')))
data.append(int(request.form.get('bare_nuclei')))
data.append(int(request.form.get('bland_chromatin')))
data.append(int(request.form.get('normal_nucleoli')))
data.append(int(request.form.get('mitoses')))
output = PredictBC(data)
return render_template("breastPredict.html", title=title,output = output)
except:
return render_template("invalid.html", title=title, output= 'Invalid data format')
@app.route('/prostateResult', methods = ["POST"])
def prostateResult():
title = 'Prediction'
data = []
try:
data.append(int(request.form.get('radius')))
data.append(int(request.form.get('texture')))
data.append(int(request.form.get('perimeter')))
data.append(int(request.form.get('area')))
data.append(float(request.form.get('smoothness')))
data.append(float(request.form.get('compactness')))
data.append(float(request.form.get('symmetry')))
data.append(float(request.form.get('fractal_dimension')))
output = PredictPC(data)
return render_template("prostatePredict.html", title=title,output = output )
except:
return render_template("invalid.html",title=title,output="Invalid data format")
# driver code
if __name__ == '__main__':
app.run(debug=True)