import streamlit as st
import joblib
import numpy as np
from huggingface_hub import hf_hub_download
# Page configuration
st.set_page_config(
page_title="Loan Approval System",
page_icon="🏦",
layout="centered",
initial_sidebar_state="collapsed"
)
# Custom CSS for styling with the specified color theme
st.markdown("""
""", unsafe_allow_html=True)
# App header with banner image instead of title
st.markdown('', unsafe_allow_html=True)
# Load the trained model from Hugging Face
@st.cache_resource
def load_model():
model_path = hf_hub_download(repo_id="ifiecas/LoanApproval-DT-v1.0", filename="best_pruned_dt.pkl")
return joblib.load(model_path)
model = load_model()
# Initialize session state for restart functionality
if 'restart_clicked' not in st.session_state:
st.session_state.restart_clicked = False
# Create tabs for better organization
tab1, tab2 = st.tabs(["Loan Application", "About the System"])
with tab1:
# Reset all form values if restart was clicked
if st.session_state.restart_clicked:
st.session_state.restart_clicked = False # Reset flag
# Personal Information Section
st.markdown('
Unfortunately, based on your current information, we cannot approve your loan application.
Consider improving your credit score, reducing existing debt, or applying with a co-applicant with higher income.
""", unsafe_allow_html=True)
with tab2:
# Add custom CSS for better styling
st.markdown("""
""", unsafe_allow_html=True)
# Main content container
st.markdown('
', unsafe_allow_html=True)
# System overview section
st.markdown('
', unsafe_allow_html=True)
st.markdown('
About the Loan Approval System
', unsafe_allow_html=True)
st.markdown(
'
This prototype evaluates loan applications using machine learning and '
'industry-standard criteria. It analyzes financial information, credit history, and loan requirements'
'to provide fast, objective loan decisions.
', unsafe_allow_html=True
)
st.markdown('
', unsafe_allow_html=True)
# Model information section
st.markdown('
', unsafe_allow_html=True)
st.markdown('
About the ML Model
', unsafe_allow_html=True)
st.markdown(
'
The machine learning model powering this system is a Decision Tree classifier, '
'which outperformed several alternatives including KNN, Random Forest, Logistic Regression, and Support '
'Vector Machine in our testing phase. The model was refined using Cost Complexity Pruning (CCP) to identify '
'the optimal alpha value, preventing overfitting while maintaining high predictive accuracy.
',
unsafe_allow_html=True
)
st.markdown('
', unsafe_allow_html=True)
# Performance metrics section with cards
st.markdown('
', unsafe_allow_html=True)
st.markdown('
Model Performance Metrics
', unsafe_allow_html=True)
# Metrics cards using HTML for better styling
st.markdown(
'
'
'
'
'
83.61%
'
'
Accuracy
'
'
'
'
'
'
80.77%
'
'
Precision
'
'
'
'
'
'
100.00%
'
'
Recall
'
'
'
'
'
'
89.36%
'
'
F1 Score
'
'
'
'
',
unsafe_allow_html=True
)
# Link to documentation/more info
st.markdown(
'
For more information about the modeling process (from loading the dataset to fine-tuning '
'the model), check here: Github
',
unsafe_allow_html=True
)
# YouTube video section
st.markdown('
Brief Explanation
', unsafe_allow_html=True)
st.markdown('
Watch this video for a brief explanation of the assessment:
', unsafe_allow_html=True)
# YouTube embed with responsive container
st.markdown("""
""", unsafe_allow_html=True)
st.markdown('
', unsafe_allow_html=True)
# Author section with profile
st.markdown('
Inspired by an assessment in BCO6008 Predictive Analytics class in Victoria University '
'(Melbourne) with Dr. Omid Ameri Sianaki. Enjoyed doing this and learned a lot! 😊