prakharg24 commited on
Commit
0733035
·
verified ·
1 Parent(s): f79b630

Create information_loss.py

Browse files
Files changed (1) hide show
  1. my_pages/information_loss.py +65 -0
my_pages/information_loss.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import go_to
3
+ import random
4
+
5
+ # Sample list of possible features
6
+ ALL_FEATURES = [
7
+ "Credit Score", "Annual Income", "Loan Amount Requested",
8
+ "Number of Previous Loans", "Debt-to-Income Ratio",
9
+ "Employment Stability", "Length of Credit History",
10
+ "Collateral Value", "Marital Status", "Number of Dependents"
11
+ ]
12
+
13
+ def render():
14
+ st.title("Information Loss Demo")
15
+
16
+ # Session state setup
17
+ if "available_features" not in st.session_state:
18
+ st.session_state.available_features = ALL_FEATURES.copy()
19
+ if "selected_features" not in st.session_state:
20
+ st.session_state.selected_features = []
21
+
22
+ # --- TOP HALF ---
23
+ col1, col2 = st.columns([1, 1])
24
+
25
+ # Top left: loan applicant icon/image
26
+ with col1:
27
+ st.image(
28
+ "https://cdn-icons-png.flaticon.com/512/1048/1048949.png",
29
+ caption="Loan Applicant",
30
+ width=200
31
+ )
32
+
33
+ # Top right: clickable "feature cloud"
34
+ with col2:
35
+ st.markdown("### Available Features (click to add approximation)")
36
+ random.shuffle(st.session_state.available_features) # scatter order each run
37
+
38
+ for feature in st.session_state.available_features:
39
+ if st.button(feature, key=feature):
40
+ # Show popup / message
41
+ with st.spinner(f"Adding approximation for '{feature}'..."):
42
+ st.session_state.selected_features.append(feature + " (approx)")
43
+ st.session_state.available_features.remove(feature)
44
+ st.session_state.show_message = f"Sorry, '{feature}' cannot be precisely collected. Adding approximation instead."
45
+
46
+ # Show popup message in center if exists
47
+ if "show_message" in st.session_state:
48
+ st.markdown(
49
+ f"<div style='text-align:center; color:red; font-weight:bold;'>{st.session_state.show_message}</div>",
50
+ unsafe_allow_html=True
51
+ )
52
+ del st.session_state.show_message # remove after showing
53
+
54
+ st.markdown("---")
55
+
56
+ # --- BOTTOM HALF: Dataset table ---
57
+ st.markdown("### Current Dataset")
58
+ if st.session_state.selected_features:
59
+ # Create table with placeholder values
60
+ import pandas as pd
61
+ cols = st.session_state.selected_features + ["Target Label"]
62
+ df = pd.DataFrame(columns=cols)
63
+ st.dataframe(df, use_container_width=True)
64
+ else:
65
+ st.info("No features added yet. Click a feature above to add it to the dataset.")