-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
117 lines (105 loc) · 4.19 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import joblib
import pandas as pd
import gradio as gr
from credit_score_modelling.credit_score import CreditScoreScaling
from credit_score_modelling.modeling.woe_logistic_regression import WOELogisticRegression
from credit_score_modelling.config import INFERENCE_CONFIG
model = WOELogisticRegression.from_file(INFERENCE_CONFIG.model_file)
credit_score_scaling = CreditScoreScaling(model.pipeline, INFERENCE_CONFIG.pdo, INFERENCE_CONFIG.odds, INFERENCE_CONFIG.scorecard_points)
def predict_credit_score(
person_age,
person_income,
person_home_ownership,
person_emp_length,
loan_intent,
loan_grade,
loan_amnt,
loan_int_rate,
loan_percent_income,
cb_person_default_on_file,
cb_person_cred_hist_length,
):
input_df = pd.DataFrame(
{
"person_age": [person_age],
"person_income": [person_income],
"person_home_ownership": [person_home_ownership],
"person_emp_length": [person_emp_length],
"loan_intent": [loan_intent],
"loan_grade": [loan_grade],
"loan_amnt": [loan_amnt],
"loan_int_rate": [loan_int_rate],
"loan_percent_income": [loan_percent_income],
"cb_person_default_on_file": [cb_person_default_on_file],
"cb_person_cred_hist_length": [cb_person_cred_hist_length],
}
)
credit_scores_df = credit_score_scaling.calculate_credit_score(input_df.copy(deep=False))
return int(credit_scores_df["credit_score"][0])
inputs = [
gr.Number(label="Person Age", minimum=18, value=25, step=1),
gr.Number(label="Person Annual Income (USD)", minimum=0.0, value=50_000.0, step=1000.0),
gr.Radio(label="Home Ownership", choices=["RENT", "OWN", "MORTGAGE", "OTHER"]),
gr.Number(label="Employment Length (Years)", minimum=0.0, maximum=50.0, value=5.0, step=1.0),
gr.Dropdown(
label="Loan Intent",
choices=["PERSONAL", "EDUCATION", "HOMEIMPROVEMENT", "DEBTCONSOLIDATION", "VENTURE", "MEDICAL", "OTHER"]
),
gr.Dropdown(label="Loan Grade", choices=["A", "B", "C", "D", "E", "F", "G"]),
gr.Number(label="Loan Amount (USD)", minimum=0, value=10000, step=500),
gr.Number(label="Interest Rate (%)", minimum=0.0, maximum=100.0, value=10.0, step=0.1),
gr.Number(
label="Loan Amount as Percentage of Income",
minimum=0.0,
maximum=1.0,
value=0.0,
step=0.01
),
gr.Radio(label="Default on File", choices=["Y", "N"]),
gr.Number(label="Credit History Length (Years)", minimum=0, value=10, step=1)
]
outputs = ["number"]
examples = [
[27,34000,"OWN",7.0,"EDUCATION","C",8000,12.53,0.24,"N",10],
[36,45600,"MORTGAGE",8.0,"MEDICAL","A",18000,6.91,0.39,"N",11],
[33,75000,"MORTGAGE",2.0,"DEBTCONSOLIDATION","B",7500,10.08,0.1,"N",9],
[24,79632,"RENT",0.0,"EDUCATION","C",25000,13.35,0.31,"N",4],
]
title = "Credit Score App"
description = "Enter the details of the loan applicant?"
article = "This app is a part of my credit-score-modelling project from GitHub which can be access through https://github.com/marcellinus-witarsah/credit-score-modelling"
gr.Interface(
fn=predict_credit_score,
inputs=inputs,
outputs=outputs,
examples=examples,
title=title,
description=description,
article=article,
theme=gr.themes.Soft(),
).launch()
# if __name__ == "__main__":
# person_age = 27
# person_income = 56525
# person_home_ownership = "MORTGAGE"
# person_emp_length = 4.0
# loan_intent = "MEDICAL"
# loan_grade = "D"
# loan_amnt = 12000
# loan_int_rate = 15.95
# loan_percent_income = 0.18
# cb_person_default_on_file = "N"
# cb_person_cred_hist_length = 10
# print("Credit Score: {}".format(predict_credit_score(
# person_age=person_age,
# person_income=person_income,
# person_home_ownership=person_home_ownership,
# person_emp_length=person_emp_length,
# loan_intent=loan_intent,
# loan_grade=loan_grade,
# loan_amnt=loan_amnt,
# loan_int_rate=loan_int_rate,
# loan_percent_income=loan_percent_income,
# cb_person_default_on_file=cb_person_default_on_file,
# cb_person_cred_hist_length=cb_person_cred_hist_length,
# )))