ZeeshanWattoo commited on
Commit
726f622
Β·
verified Β·
1 Parent(s): 2bcc983

fixing other issues

Browse files
Files changed (1) hide show
  1. 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.title("πŸ’Ό Credit Risk Prediction App")
35
- st.markdown("πŸ”Ž **Enter applicant details to predict the likelihood of loan repayment or default.**")
36
 
37
- # Sidebar for app details with color and 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>Author:</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'>πŸ”— GitHub Repo</a>",
46
  unsafe_allow_html=True
47
  )
48
 
@@ -53,15 +53,14 @@ st.markdown(
53
  unsafe_allow_html=True
54
  )
55
 
56
- # Get user name for personalization with an empty default
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, help="Applicant's current age.")
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(f"⚠️ **Sorry, {user_name}.** Based on our analysis, there is a high risk of default.")
 
 
 
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