-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
101 lines (78 loc) · 3.55 KB
/
Copy pathapp.py
File metadata and controls
101 lines (78 loc) · 3.55 KB
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
from flask import Flask, render_template, request
import os
import pandas as pd
from mlProject import logger
from mlProject.pipeline.prediction import PredictionPipeline
app = Flask(__name__) # initializing a flask app
@app.route('/',methods=['GET']) # route to display the home page
def homePage():
return render_template("index.html")
@app.route('/train',methods=['GET']) # route to train the pipeline
def training():
os.system("python main.py")
return "Training Successful!"
@app.route('/predict',methods=['POST','GET']) # route to show the predictions in a web UI
def index():
if request.method == 'POST':
try:
# reading the inputs given by the user
credit_score =int(request.form['credit_score'])
geography =request.form['geography']
gender =request.form['gender']
age =int(request.form['age'])
tenure =int(request.form['tenure'])
balance =float(request.form['balance'])
num_of_products =int(request.form['num_of_products'])
has_cr_card =int(request.form['has_cr_card'])
is_active_member =int(request.form['is_active_member'])
estimated_salary =float(request.form['estimated_salary'])
data_headers = ["RowNumber",
"CustomerId",
"Surname",
"CreditScore",
"Geography",
"Gender",
"Age",
"Tenure",
"Balance",
"NumOfProducts",
"HasCrCard",
"IsActiveMember",
"EstimatedSalary"]
data_values = [1,
1,
"no name",
credit_score,
geography,
gender,
age,
tenure,
balance,
num_of_products,
has_cr_card,
is_active_member,
estimated_salary]
data = pd.DataFrame([data_values], columns=data_headers)
####################################################################### Prediction stage #######################################################################
STAGE_NAME = "Prediction stage"
try:
logger.info(f">>>>>> stage {STAGE_NAME} started <<<<<<")
prediction = PredictionPipeline()
predict = prediction.main(data)
if predict == 1:
result = "Exited"
else:
result = "Not Exited"
logger.info(f">>>>>> stage {STAGE_NAME} completed <<<<<<\n\nx==========x")
except Exception as e:
logger.exception(e)
raise e
################################################################################################################################################################
return render_template('results.html', prediction = result)
except Exception as e:
print('The Exception message is: ',e)
return 'something is wrong'
else:
return render_template('index.html')
if __name__ == "__main__":
app.run(host="0.0.0.0", port = 8080, debug=True)