File size: 3,302 Bytes
0a4d346 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import streamlit as st
import requests
import pandas as pd
# Set FastAPI backend URL
API_URL = "http://127.0.0.1:8000" # Change this if deployed elsewhere
# Streamlit UI
st.set_page_config(page_title="Loan Risk Analysis Dashboard", layout="wide")
st.title("π Loan Risk Analysis Dashboard")
# Sidebar for Navigation
st.sidebar.header("Navigation")
page = st.sidebar.radio(
"Go to",
[
"Loan Status Distribution",
"Payment Timeline Analysis",
"Principal Amount Patterns",
"Credit History Impact",
"Customer Profile Analysis",
"Loan Intent Analysis",
"Collection Effectiveness",
"Risk Score Development"
],
)
# Function to fetch data from FastAPI backend
def fetch_data(endpoint):
try:
response = requests.get(f"{API_URL}/{endpoint}")
if response.status_code == 200:
return response.json()
else:
st.error(f"Error fetching data: {response.json()['detail']}")
return None
except requests.exceptions.RequestException as e:
st.error(f"API request failed: {e}")
return None
# Loan Status Distribution
if page == "Loan Status Distribution":
st.subheader("π Loan Status Distribution")
data = fetch_data("loan_status_distribution")
if data:
st.write(data)
st.bar_chart(pd.DataFrame([data], index=["Loan Status"]).T)
# Payment Timeline Analysis
elif page == "Payment Timeline Analysis":
st.subheader("π Payment Timeline Analysis")
data = fetch_data("payment_timeline_analysis")
if data:
st.write(data)
st.bar_chart(pd.DataFrame(data["average_loan_amount_by_status"], index=["Loan Amount"]).T)
# Principal Amount Patterns
elif page == "Principal Amount Patterns":
st.subheader("π Principal Amount Patterns")
data = fetch_data("principal_amount_patterns")
if data:
df = pd.DataFrame(data)
st.write(df)
st.bar_chart(df.set_index("loan_status")["count"])
# Credit History Impact
elif page == "Credit History Impact":
st.subheader("π Credit History Impact")
data = fetch_data("credit_history_impact")
if data:
st.write(data)
# Customer Profile Analysis
elif page == "Customer Profile Analysis":
st.subheader("π Customer Profile Analysis")
data = fetch_data("customer_profile_analysis")
if data:
df = pd.DataFrame(data["customer_profile_analysis"])
st.write(df)
st.bar_chart(df.set_index("person_age")["success_rate"])
# Loan Intent Analysis
elif page == "Loan Intent Analysis":
st.subheader("π Loan Intent Analysis")
data = fetch_data("loan_intent_analysis")
if data:
st.write(data)
# Collection Effectiveness
elif page == "Collection Effectiveness":
st.subheader("π Collection Effectiveness")
data = fetch_data("collection_effectiveness")
if data:
st.write(data)
# Risk Score Development
elif page == "Risk Score Development":
st.subheader("π Risk Score Development")
data = fetch_data("risk_score_development")
if data:
st.write(data)
st.bar_chart(pd.DataFrame(data, index=["Risk Score"]).T)
# Run Streamlit
st.sidebar.info("π’ Select an option from the navigation to analyze loan risk insights.")
|