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.")