CoolFace
Apppublic

swapnapapireddy3/Credict-Risk-Modelling-using-classification

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
app.py233 linesDownload Raw Back to root
1import streamlit as st
2from prediction_helper import predict
3
4# ------------------ PAGE CONFIG ------------------
5st.set_page_config(
6    page_title="Lauki Finance: Credit Risk Modelling",
7    page_icon="๐Ÿ“Š",
8    layout="wide"
9)
10
11st.title("๐Ÿ“Š Lauki Finance: Credit Risk Modelling")
12
13# ------------------ CUSTOM CSS ------------------
14
15st.markdown("""
16<style>
17
18.main{
19    background-color:#f5f7fb;
20}
21
22h1{
23    color:#0E4C92;
24    text-align:center;
25    padding-bottom:20px;
26}
27
28/* Labels */
29
30label{
31    font-size:18px !important;
32    font-weight:600 !important;
33    color:#222 !important;
34}
35
36/* Number Inputs */
37
38.stNumberInput input{
39    height:55px !important;
40    font-size:18px !important;
41    border-radius:10px !important;
42}
43
44/* Select Boxes */
45
46.stSelectbox div[data-baseweb="select"]{
47    font-size:18px !important;
48    min-height:55px !important;
49}
50
51/* Button */
52
53div.stButton > button{
54    width:100%;
55    height:55px;
56    font-size:20px;
57    font-weight:bold;
58    border-radius:10px;
59    background:#0E4C92;
60    color:white;
61    border:none;
62}
63
64div.stButton > button:hover{
65    background:#1d70c9;
66    color:white;
67}
68
69/* Metric Card */
70
71.metric-card{
72    background:white;
73    padding:18px;
74    border-radius:12px;
75    border-left:6px solid #0E4C92;
76    box-shadow:0 3px 10px rgba(0,0,0,0.08);
77    margin-top:18px;
78}
79
80.metric-title{
81    font-size:18px;
82    font-weight:bold;
83    color:#555;
84}
85
86.metric-value{
87    font-size:26px;
88    color:#0E4C92;
89    font-weight:bold;
90}
91
92.result-box{
93    background:#ffffff;
94    padding:20px;
95    border-radius:12px;
96    box-shadow:0px 4px 10px rgba(0,0,0,0.08);
97    margin-top:25px;
98}
99
100</style>
101""", unsafe_allow_html=True)
102
103# ------------------ LAYOUT ------------------
104
105row1 = st.columns(3)
106row2 = st.columns(3)
107row3 = st.columns(3)
108row4 = st.columns(3)
109
110# ------------------ INPUTS ------------------
111
112with row1[0]:
113    age = st.number_input(
114        "Age",
115        min_value=18,
116        max_value=100,
117        value=28,
118        step=1
119    )
120
121with row1[1]:
122    income = st.number_input(
123        "Income",
124        min_value=0,
125        value=1200000
126    )
127
128with row1[2]:
129    loan_amount = st.number_input(
130        "Loan Amount",
131        min_value=0,
132        value=2560000
133    )
134
135# ------------------ LOAN TO INCOME ------------------
136
137loan_to_income_ratio = loan_amount / income if income > 0 else 0
138
139with row2[0]:
140    st.markdown(f"""
141    <div class="metric-card">
142        <div class="metric-title">Loan to Income Ratio</div>
143        <div class="metric-value">{loan_to_income_ratio:.2f}</div>
144    </div>
145    """, unsafe_allow_html=True)
146
147with row2[1]:
148    loan_tenure_months = st.number_input(
149        "Loan Tenure (months)",
150        min_value=0,
151        value=36,
152        step=1
153    )
154
155with row2[2]:
156    avg_dpd_per_delinquency = st.number_input(
157        "Average DPD",
158        min_value=0,
159        value=20
160    )
161
162with row3[0]:
163    delinquency_ratio = st.number_input(
164        "Delinquency Ratio",
165        min_value=0,
166        max_value=100,
167        value=30,
168        step=1
169    )
170
171with row3[1]:
172    credit_utilization_ratio = st.number_input(
173        "Credit Utilization Ratio",
174        min_value=0,
175        max_value=100,
176        value=30,
177        step=1
178    )
179
180with row3[2]:
181    num_open_accounts = st.number_input(
182        "Open Loan Accounts",
183        min_value=1,
184        max_value=4,
185        value=2,
186        step=1
187    )
188
189with row4[0]:
190    residence_type = st.selectbox(
191        "Residence Type",
192        ["Owned", "Rented", "Mortgage"]
193    )
194
195with row4[1]:
196    loan_purpose = st.selectbox(
197        "Loan Purpose",
198        ["Education", "Home", "Auto", "Personal"]
199    )
200
201with row4[2]:
202    loan_type = st.selectbox(
203        "Loan Type",
204        ["Unsecured", "Secured"]
205    )
206
207# ------------------ PREDICTION ------------------
208
209if st.button("Calculate Risk"):
210
211    probability, credit_score, rating = predict(
212        age,
213        income,
214        loan_amount,
215        loan_tenure_months,
216        avg_dpd_per_delinquency,
217        delinquency_ratio,
218        credit_utilization_ratio,
219        num_open_accounts,
220        residence_type,
221        loan_purpose,
222        loan_type
223    )
224
225    st.markdown("<div class='result-box'>", unsafe_allow_html=True)
226
227    st.success(f"Default Probability : {probability:.2%}")
228
229    st.info(f"Credit Score : {credit_score}")
230
231    st.warning(f"Rating : {rating}")
232
233    st.markdown("</div>", unsafe_allow_html=True)