tharu22 commited on
Commit
0a4d346
Β·
1 Parent(s): fd2aabb

first commit

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