| import streamlit as st |
| import requests |
| import pandas as pd |
|
|
| |
| API_URL = "http://127.0.0.1:8000" |
|
|
| |
| st.set_page_config(page_title="Loan Risk Analysis Dashboard", layout="wide") |
|
|
| st.title("π Loan Risk Analysis Dashboard") |
|
|
| |
| 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" |
| ], |
| ) |
|
|
| |
| 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 |
|
|
| |
| 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) |
|
|
| |
| 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) |
|
|
| |
| 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"]) |
|
|
| |
| elif page == "Credit History Impact": |
| st.subheader("π Credit History Impact") |
| data = fetch_data("credit_history_impact") |
| if data: |
| st.write(data) |
|
|
| |
| 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"]) |
|
|
| |
| elif page == "Loan Intent Analysis": |
| st.subheader("π Loan Intent Analysis") |
| data = fetch_data("loan_intent_analysis") |
| if data: |
| st.write(data) |
|
|
| |
| elif page == "Collection Effectiveness": |
| st.subheader("π Collection Effectiveness") |
| data = fetch_data("collection_effectiveness") |
| if data: |
| st.write(data) |
|
|
| |
| 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) |
|
|
| |
| st.sidebar.info("π’ Select an option from the navigation to analyze loan risk insights.") |
|
|