-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (59 loc) · 3.28 KB
/
app.py
File metadata and controls
78 lines (59 loc) · 3.28 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
from src.logger import logging
from src.pipelines.predict_pipeline import Predict, NewData
from flask import Flask, request, render_template
application = Flask(__name__)
app = application
# route for home page
@app.route('/')
def home():
return render_template('home_page.html')
# route for predict page
@app.route('/predictdata', methods=['GET', 'POST'])
def predict():
if request.method == 'GET':
return render_template('predict_page.html')
else:
logging.info("POST Request has been made.")
data = NewData( gender = request.form.get('Gender'),
SeniorCitizen = request.form.get('Senior Citizen'),
Partner = request.form.get('Partner'),
Dependents = request.form.get('Dependents'),
tenure = request.form.get('Tenure (months)'),
PhoneService = request.form.get('Phone Service'),
MultipleLines = request.form.get('Multiple Lines'),
InternetService = request.form.get('Internet Service'),
OnlineSecurity = request.form.get('Online Security'),
OnlineBackup = request.form.get('Online Backup'),
DeviceProtection = request.form.get('Device Protection'),
TechSupport = request.form.get('Tech Support'),
StreamingTV = request.form.get('Streaming TV'),
StreamingMovies = request.form.get('Streaming Movies'),
Contract = request.form.get('Contract Type'),
PaperlessBilling = request.form.get('Paperless Billing'),
PaymentMethod = request.form.get('Payment Method'),
MonthlyCharges = float(request.form.get('Monthly Charges')),
TotalCharges = float(request.form.get('Total Charges')) )
df = data.get_data_as_dataframe()
logging.info("Data has been converted in to a DataFrame.")
logging.info(f"DataFrame: \n{df.head()}")
print(df.head())
prediction = Predict()
result = prediction.predict_data(df)
print("Prediction result:", result)
logging.info("Prediction Result: {result}")
result_text = ""
if result == 0:
result_text = "Your customer will not churn from your business."
else:
result_text = "Your customer will churn from your business."
return render_template('predict_page.html', result=result[0], result_text = result_text)
#except Exception as e:
# return render_template('predict_page.html', error=str(e))
#else:
#return render_template('predict_page.html')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000, debug=True, use_reloader=False)
# host='0.0.0.0' is for aws eks, to make the app public
# port=8000 to match the port in deployment.yaml and dockerfile
# debug=False for production debug=True mode can cause issues
# when deployed in eks the above app.run() command is ignored as gunicorn is used (in dockerfile) to run the app