Spaces:
Running
Running
Added Streamlit loan approval app
Browse files- bankloan.py +46 -0
- requirements.txt +5 -0
bankloan.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
# Load the trained model from Hugging Face
|
7 |
+
model_path = hf_hub_download(repo_id="ifiecas/LoanApproval-DT-v1.0", filename="best_pruned_dt.pkl")
|
8 |
+
model = joblib.load(model_path)
|
9 |
+
|
10 |
+
# Streamlit app title
|
11 |
+
st.title("🏦 AI-Powered Loan Approval System")
|
12 |
+
st.write("Enter your details to check your loan approval status.")
|
13 |
+
|
14 |
+
# Input fields
|
15 |
+
applicant_income = st.number_input("Applicant's Monthly Income ($)", min_value=0)
|
16 |
+
coapplicant_income = st.number_input("Co-Applicant's Monthly Income ($)", min_value=0)
|
17 |
+
loan_amount = st.number_input("Loan Amount Requested ($)", min_value=0)
|
18 |
+
loan_term = st.number_input("Loan Term (days)", min_value=0, value=360)
|
19 |
+
credit_history = st.selectbox("Credit History", [1, 0], format_func=lambda x: "Good (1)" if x == 1 else "Bad (0)")
|
20 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
21 |
+
marital_status = st.selectbox("Marital Status", ["Married", "Not Married"])
|
22 |
+
education = st.selectbox("Education Level", ["Graduate", "Under Graduate"])
|
23 |
+
self_employed = st.selectbox("Self-Employed", ["Yes", "No"])
|
24 |
+
location = st.selectbox("Property Location", ["Urban", "Semiurban", "Rural"])
|
25 |
+
|
26 |
+
def preprocess_input():
|
27 |
+
# Convert categorical inputs to numerical format (you may need encoding based on your dataset)
|
28 |
+
gender_num = 1 if gender == "Male" else 0
|
29 |
+
marital_status_num = 1 if marital_status == "Married" else 0
|
30 |
+
education_num = 1 if education == "Graduate" else 0
|
31 |
+
self_employed_num = 1 if self_employed == "Yes" else 0
|
32 |
+
location_num = {"Urban": 2, "Semiurban": 1, "Rural": 0}[location]
|
33 |
+
|
34 |
+
return np.array([[
|
35 |
+
applicant_income, coapplicant_income, loan_amount, loan_term, credit_history,
|
36 |
+
gender_num, marital_status_num, education_num, self_employed_num, location_num
|
37 |
+
]])
|
38 |
+
|
39 |
+
# Predict button
|
40 |
+
if st.button("Check Loan Approval"):
|
41 |
+
input_data = preprocess_input()
|
42 |
+
prediction = model.predict(input_data)
|
43 |
+
result = "✅ Approved" if prediction[0] == "Y" else "❌ Rejected"
|
44 |
+
st.subheader(f"Loan Status: {result}")
|
45 |
+
|
46 |
+
st.write("📌 AI-driven decision-making for faster loan approvals.")
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
joblib
|
3 |
+
numpy
|
4 |
+
scikit-learn
|
5 |
+
huggingface_hub
|