-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (64 loc) · 3.49 KB
/
app.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
from flask import Flask, render_template, request
import joblib, sqlite3
import pandas as pd
app = Flask(__name__)
pipeline = joblib.load('backup_pipeline.pkl')
@app.route("/")
def home():
return render_template('index.html')
@app.route("/predict",methods=['GET','POST'])
def predict():
if request.method == 'POST':
yes_no_mapping = {"Yes": 1, "No": 0}
total_good_debt = float(request.form['total_good_debt'])
applicant_gender_male = float(yes_no_mapping[request.form['applicant_gender_male']])
income_type_working = float(yes_no_mapping[request.form['income_type_working']])
job_title_laborers = float(yes_no_mapping[request.form['job_title_laborers']])
family_status_married = float(yes_no_mapping[request.form['family_status_married']])
total_income = float(request.form['total_income'])
total_children = float(request.form['total_children'])
years_of_working = float(request.form['years_of_working'])
applicant_age = float(request.form['applicant_age'])
income_type_state_servant = float(yes_no_mapping[request.form['income_type_state_servant']])
data = pd.DataFrame([[total_good_debt,
applicant_gender_male,
income_type_working,
job_title_laborers,
family_status_married,
total_income,
total_children,
years_of_working,
applicant_age,
income_type_state_servant]],columns=['Total_Good_Debt',
'Applicant_Gender_M',
'Income_Type_Working',
'Job_Title_Laborers',
'Family_Status_Married',
'Total_Income',
'Total_Children',
'Years_of_Working',
'Applicant_Age',
'Income_Type_State servant'])
pred = pipeline.predict(data)[0]
complete_data = [total_good_debt,
applicant_gender_male,
income_type_working,
job_title_laborers,
family_status_married,
total_income,
total_children,
years_of_working,
applicant_age,
income_type_state_servant,
pred]
conn = sqlite3.connect("credit_card_application.db")
cursor = conn.cursor()
cursor.execute(f"INSERT INTO CREDIT_APPLICATION VALUES {tuple(complete_data)}")
conn.commit()
conn.close()
if pred == 0:
return render_template('index.html',prediction_text="Your credit card application is likely to be rejected.")
elif pred == 1:
return render_template('index.html',prediction_text="Bravo! Your credit card application is likely to be approved.")
if __name__ == '__main__':
app.run(port=8000)