-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
90 lines (70 loc) · 2.95 KB
/
application.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
'''
Importing the libraries.
'''
# Web app.
from flask import Flask, request, render_template
# Data manipulation.
import numpy as np
import pandas as pd
# File handling.
import os
# Predictions.
from src.pipeline.predict_pipeline import InputData, PredictPipeline
application = Flask(__name__)
app = application
# Route for the home page.
# Route for the home page.
@app.route('/')
def index():
'''
Route handler for the home page.
This function handles the GET request for the home page. It renders the 'index.html' template, which serves as the
homepage for the customer credit risk prediction web application.
:return: The rendered home page.
:rtype: str
'''
return render_template('index.html')
# Route for prediction page.
@app.route('/predictdata', methods=['GET', 'POST'])
def predict_datapoint():
'''
Route handler for predicting credit risk.
This function handles the POST request for predicting credit risk based on input data. If the request is a GET request,
the function renders the 'home.html' template. If the request is a POST request, it collects input data from the form,
processes it to make a prediction, and returns the prediction result.
:return: The prediction result.
:rtype: str
'''
if request.method == 'GET':
return render_template('home.html')
else:
input_data = InputData(
customer_age=request.form.get('customer_age'),
gender=request.form.get('gender'),
dependent_count=request.form.get('dependent_count'),
education_level=request.form.get('education_level'),
marital_status=request.form.get('marital_status'),
income_category=request.form.get('income_category'),
card_category=request.form.get('card_category'),
months_on_book=request.form.get('months_on_book'),
total_relationship_count=request.form.get('total_relationship_count'),
months_inactive_12_mon=request.form.get('months_inactive_12_mon'),
contacts_count_12_mon=request.form.get('contacts_count_12_mon'),
credit_limit=request.form.get('credit_limit'),
total_revolving_bal=request.form.get('total_revolving_bal'),
total_amt_chng_q4_q1=request.form.get('total_amt_chng_q4_q1'),
total_trans_amt=request.form.get('total_trans_amt'),
total_trans_ct=request.form.get('total_trans_ct'),
total_ct_chng_q4_q1=request.form.get('total_ct_chng_q4_q1'),
avg_utilization_ratio=request.form.get('avg_utilization_ratio')
)
input_df = input_data.get_input_data_df()
print(input_df)
print('\nBefore prediction.')
predict_pipeline = PredictPipeline()
print('\nMid prediction')
prediction = predict_pipeline.predict(input_df)
print('\nAfter prediction.')
return prediction
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)