|
a |
|
b/app.py |
|
|
1 |
from flask import Flask,request, url_for, redirect, render_template |
|
|
2 |
import pickle |
|
|
3 |
import numpy as np |
|
|
4 |
import sklearn |
|
|
5 |
from sklearn.preprocessing import StandardScaler |
|
|
6 |
|
|
|
7 |
app = Flask(__name__) |
|
|
8 |
|
|
|
9 |
#model = pickle.load(open('model.pkl','rb')) |
|
|
10 |
|
|
|
11 |
filename = 'Lung_Cancer.pkl' |
|
|
12 |
with open(filename, 'rb') as f: |
|
|
13 |
model = pickle.load(f) |
|
|
14 |
|
|
|
15 |
@app.route('/') |
|
|
16 |
def hello_world(): |
|
|
17 |
return render_template("lung_cancer.html") |
|
|
18 |
|
|
|
19 |
#Parameters used for Prediction |
|
|
20 |
# ['GENDER', 'AGE', 'SMOKING', 'YELLOW_FINGERS', 'ANXIETY', |
|
|
21 |
# 'PEER_PRESSURE', 'CHRONIC DISEASE', 'FATIGUE ', 'ALLERGY ', 'WHEEZING', |
|
|
22 |
# 'ALCOHOL CONSUMING', 'COUGHING', 'SHORTNESS OF BREATH', |
|
|
23 |
# 'SWALLOWING DIFFICULTY', 'CHEST PAIN', 'LUNG_CANCER'] |
|
|
24 |
|
|
|
25 |
@app.route('/predict',methods=['POST', 'GET']) |
|
|
26 |
def predict(): |
|
|
27 |
if request.method == 'POST': |
|
|
28 |
int_features = [int(x) for x in request.form.values()] |
|
|
29 |
final = np.reshape(int_features, (1, -1)) |
|
|
30 |
print(int_features) #Checking Inputs Successfully Added |
|
|
31 |
print(final) #Reshaping into numpy array for Prediction |
|
|
32 |
prediction = model.predict(final) |
|
|
33 |
print(prediction) # Checking the Prediction Value |
|
|
34 |
output = prediction |
|
|
35 |
if output == 0: |
|
|
36 |
return render_template('lung_cancer.html', pred='Person Has Lung Cancer {}'.format(output)) |
|
|
37 |
else: |
|
|
38 |
return render_template('lung_cancer.html', pred='Person Does Not Got Lung Cancer {}'.format(output)) |
|
|
39 |
else: |
|
|
40 |
return render_template('lung_cancer.html') |
|
|
41 |
|
|
|
42 |
if __name__ == '__main__': |
|
|
43 |
app.run(debug=True) |