Spaces:
Sleeping
Sleeping
fixing other issues
Browse files- src/streamlit_app.py +17 -14
src/streamlit_app.py
CHANGED
@@ -31,18 +31,18 @@ intent_mapping = {
|
|
31 |
default_mapping = {"Yes": 1, "No": 0}
|
32 |
|
33 |
# App header
|
34 |
-
st.
|
35 |
-
st.markdown("
|
36 |
|
37 |
-
# Sidebar
|
38 |
with st.sidebar:
|
39 |
st.markdown(
|
40 |
"<h2 style='color: #ff6347;'>βΉοΈ About This App</h2>"
|
41 |
"<p>This app predicts the risk of default for loan applicants using a trained <strong>Random Forest</strong> model.</p>"
|
42 |
-
"<p><strong>
|
43 |
"<strong>Framework:</strong> Streamlit<br>"
|
44 |
"<strong>Deployed on:</strong> Hugging Face π€</p>"
|
45 |
-
"<a href='https://github.com/ZeeshanWattoo2052/credit-risk-analysis' target='_blank'>π GitHub Repo</a>",
|
46 |
unsafe_allow_html=True
|
47 |
)
|
48 |
|
@@ -53,15 +53,14 @@ st.markdown(
|
|
53 |
unsafe_allow_html=True
|
54 |
)
|
55 |
|
56 |
-
#
|
57 |
-
user_name = st.text_input("π€ Enter Your Name", placeholder="Enter your name")
|
58 |
-
|
59 |
|
60 |
# Input form
|
61 |
col1, col2 = st.columns(2)
|
62 |
|
63 |
with col1:
|
64 |
-
age = st.slider("π Age", 18, 100, 30
|
65 |
income = st.number_input("π° Annual Income ($)", min_value=0.0, value=50000.0, step=1000.0)
|
66 |
emp_length = st.slider("π Employment Length (years)", 0, 50, 5)
|
67 |
intent = st.selectbox("π¦ Loan Purpose", ["education", "home_improvement", "medical", "personal", "venture"])
|
@@ -73,6 +72,7 @@ with col2:
|
|
73 |
default = st.radio("β οΈ Previous Default", ["Yes", "No"])
|
74 |
cred_length = st.slider("π Credit History Length (years)", 0, 50, 10)
|
75 |
|
|
|
76 |
if income == 0:
|
77 |
st.warning("β οΈ Annual income must be greater than 0.")
|
78 |
st.stop()
|
@@ -94,7 +94,7 @@ input_df = pd.DataFrame({
|
|
94 |
"Cred_length": [cred_length]
|
95 |
})
|
96 |
|
97 |
-
# Prediction
|
98 |
if st.button("π Predict Credit Risk"):
|
99 |
prediction = model.predict(input_df)
|
100 |
proba = model.predict_proba(input_df)[0]
|
@@ -102,12 +102,15 @@ if st.button("π Predict Credit Risk"):
|
|
102 |
if prediction[0] == 0:
|
103 |
# Fully Paid
|
104 |
st.balloons()
|
105 |
-
st.success(f"π **Congratulations, {user_name}!** You are eligible to get the loan. π°")
|
106 |
st.markdown("β
**Prediction:** π’ Fully Paid")
|
107 |
st.metric(label="Loan Risk Score (Default)", value=f"{proba[1]*100:.1f}%")
|
108 |
else:
|
109 |
# Charged Off
|
110 |
-
st.warning(
|
|
|
|
|
|
|
111 |
st.markdown("β **Prediction:** π΄ Charged Off")
|
112 |
st.metric(label="Loan Risk Score (Default)", value=f"{proba[1]*100:.1f}%")
|
113 |
|
@@ -138,10 +141,10 @@ if st.button("π Predict Credit Risk"):
|
|
138 |
mime="text/csv"
|
139 |
)
|
140 |
|
141 |
-
# Footer
|
142 |
st.markdown("---")
|
143 |
st.markdown(
|
144 |
-
"<div style='text-align: center;'>"
|
145 |
"Made with β€οΈ by Zeeshan Ahmad Wattoo"
|
146 |
"</div>",
|
147 |
unsafe_allow_html=True
|
|
|
31 |
default_mapping = {"Yes": 1, "No": 0}
|
32 |
|
33 |
# App header
|
34 |
+
st.markdown("<h1 style='color: #007acc;'>πΌ Credit Risk Prediction App</h1>", unsafe_allow_html=True)
|
35 |
+
st.markdown("<p style='font-size: 16px;'>π <strong>Enter applicant details to predict the likelihood of loan repayment or default.</strong></p>", unsafe_allow_html=True)
|
36 |
|
37 |
+
# Sidebar with colorful style
|
38 |
with st.sidebar:
|
39 |
st.markdown(
|
40 |
"<h2 style='color: #ff6347;'>βΉοΈ About This App</h2>"
|
41 |
"<p>This app predicts the risk of default for loan applicants using a trained <strong>Random Forest</strong> model.</p>"
|
42 |
+
"<p><strong>Created By:</strong> Zeeshan Ahmad Wattoo<br>"
|
43 |
"<strong>Framework:</strong> Streamlit<br>"
|
44 |
"<strong>Deployed on:</strong> Hugging Face π€</p>"
|
45 |
+
"<a href='https://github.com/ZeeshanWattoo2052/credit-risk-analysis' target='_blank' style='color: #4caf50; text-decoration: none;'>π GitHub Repo</a>",
|
46 |
unsafe_allow_html=True
|
47 |
)
|
48 |
|
|
|
53 |
unsafe_allow_html=True
|
54 |
)
|
55 |
|
56 |
+
# Name input with placeholder only
|
57 |
+
user_name = st.text_input("π€ Enter Your Name", value="", placeholder="Enter your name")
|
|
|
58 |
|
59 |
# Input form
|
60 |
col1, col2 = st.columns(2)
|
61 |
|
62 |
with col1:
|
63 |
+
age = st.slider("π Age", 18, 100, 30)
|
64 |
income = st.number_input("π° Annual Income ($)", min_value=0.0, value=50000.0, step=1000.0)
|
65 |
emp_length = st.slider("π Employment Length (years)", 0, 50, 5)
|
66 |
intent = st.selectbox("π¦ Loan Purpose", ["education", "home_improvement", "medical", "personal", "venture"])
|
|
|
72 |
default = st.radio("β οΈ Previous Default", ["Yes", "No"])
|
73 |
cred_length = st.slider("π Credit History Length (years)", 0, 50, 10)
|
74 |
|
75 |
+
# Validate income
|
76 |
if income == 0:
|
77 |
st.warning("β οΈ Annual income must be greater than 0.")
|
78 |
st.stop()
|
|
|
94 |
"Cred_length": [cred_length]
|
95 |
})
|
96 |
|
97 |
+
# Prediction button
|
98 |
if st.button("π Predict Credit Risk"):
|
99 |
prediction = model.predict(input_df)
|
100 |
proba = model.predict_proba(input_df)[0]
|
|
|
102 |
if prediction[0] == 0:
|
103 |
# Fully Paid
|
104 |
st.balloons()
|
105 |
+
st.success(f"π **Congratulations, {user_name or 'Applicant'}!** You are eligible to get the loan. π°")
|
106 |
st.markdown("β
**Prediction:** π’ Fully Paid")
|
107 |
st.metric(label="Loan Risk Score (Default)", value=f"{proba[1]*100:.1f}%")
|
108 |
else:
|
109 |
# Charged Off
|
110 |
+
st.warning(
|
111 |
+
f"β οΈ **Sorry, {user_name or 'Applicant'}.** Based on our analysis, there is a high risk of default for this application. "
|
112 |
+
f"Unfortunately, you are currently **not eligible for the loan**."
|
113 |
+
)
|
114 |
st.markdown("β **Prediction:** π΄ Charged Off")
|
115 |
st.metric(label="Loan Risk Score (Default)", value=f"{proba[1]*100:.1f}%")
|
116 |
|
|
|
141 |
mime="text/csv"
|
142 |
)
|
143 |
|
144 |
+
# Centered Footer
|
145 |
st.markdown("---")
|
146 |
st.markdown(
|
147 |
+
"<div style='text-align: center; color: #888;'>"
|
148 |
"Made with β€οΈ by Zeeshan Ahmad Wattoo"
|
149 |
"</div>",
|
150 |
unsafe_allow_html=True
|