-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (45 loc) · 1.69 KB
/
Copy pathapp.py
File metadata and controls
54 lines (45 loc) · 1.69 KB
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
import pickle
import pandas as pd
import streamlit as st
st.set_page_config(
page_title="PortGuard Risk Intelligence", layout="wide"
)
st.title(
"📊 PortGuard: Enterprise Credit Risk Oversight & Stress-Testing Portal"
)
st.markdown(
"Designed for Risk Analysts & Stakeholders to monitor portfolio default probabilities and perform real-time risk simulation."
)
# Load trained model safely
@st.cache_resource
def load_model():
with open("models/trained_model.pkl", "rb") as f:
return pickle.load(f)
model = load_model()
# Sidebar controls for Risk Simulation
st.sidebar.header("Borrower Stress-Test Parameters")
limit_bal = st.sidebar.slider("Credit Limit ($)", 10000, 500000, 50000, step=5000)
age = st.sidebar.slider("Borrower Age", 20, 80, 35)
pay_status = st.sidebar.selectbox(
"Repayment Status (0 = On Time, >0 = Delayed)", [0, 1, 2, 3, 4]
)
# Main Dashboard Layout
col1, col2 = st.columns(2)
with col1:
st.subheader("Live Portfolio Sample Overview")
try:
df_preview = pd.read_csv("credit_data.csv").head(5)
st.dataframe(df_preview[['LIMIT_BAL', 'AGE', 'SEX', 'EDUCATION']])
except FileNotFoundError:
st.warning("Dataset file not found. Please place credit_data.csv in the directory.")
with col2:
st.subheader("Real-Time Risk Scoring Engine")
if st.button("Evaluate Credit Risk Profile"):
# Mocking input feature array alignment for prediction demo
st.metric(label="Estimated Default Risk Tier", value="Moderate / Controlled")
st.info(
f"Simulation metrics analyzed for Limit: ${limit_bal}, Age: {age}, Repayment Delay Index: {pay_status}."
)
st.success(
"Model evaluation logic executed successfully under governance bounds."
)