Spaces:
Sleeping
Sleeping
| import os | |
| os.environ["XDG_CONFIG_HOME"] = "/tmp/.streamlit" | |
| os.makedirs("/tmp/.streamlit", exist_ok=True) | |
| import streamlit as st | |
| import joblib | |
| import pandas as pd | |
| os.environ["XDG_CONFIG_HOME"] = "/tmp/.streamlit" | |
| # Load the trained model | |
| model_path = os.path.join(os.path.dirname(__file__), "model.pkl") | |
| model, expected_columns = joblib.load(model_path) | |
| st.title("💳 Loan Default Prediction App") | |
| st.markdown("Enter applicant information to predict the likelihood of default.") | |
| # Collect input | |
| input_data = { | |
| "RevolvingUtilizationOfUnsecuredLines": st.slider("Revolving Utilization", 0.0, 1.0, 0.3), | |
| "age": st.slider("Age", 18, 100, 45), | |
| "NumberOfTime30-59DaysPastDueNotWorse": st.number_input("30-59 Days Past Due", 0, 100, 0), | |
| "DebtRatio": st.slider("Debt Ratio", 0.0, 2.0, 0.8), | |
| "MonthlyIncome": st.number_input("Monthly Income", 0, 100000, 5000), | |
| "NumberOfOpenCreditLinesAndLoans": st.number_input("Open Credit Lines", 0, 50, 6), | |
| "NumberOfTimes90DaysLate": st.number_input("Times 90 Days Late", 0, 100, 0), | |
| "NumberRealEstateLoansOrLines": st.number_input("Real Estate Loans", 0, 50, 1), | |
| "NumberOfTime60-89DaysPastDueNotWorse": st.number_input("60-89 Days Past Due", 0, 100, 0), | |
| "NumberOfDependents": st.number_input("Number of Dependents", 0, 20, 2) | |
| } | |
| if st.button("Predict"): | |
| input_df = pd.DataFrame([input_data]) | |
| prediction = model.predict(input_df)[0] | |
| result = "🚨 Will Default" if prediction == 1 else "✅ Will Not Default" | |
| st.subheader(f"Prediction: {result}") | |