prakharg24 commited on
Commit
6e2c065
·
verified ·
1 Parent(s): 93a1da5

Update my_pages/information_loss.py

Browse files
Files changed (1) hide show
  1. my_pages/information_loss.py +24 -54
my_pages/information_loss.py CHANGED
@@ -1,7 +1,5 @@
1
- import streamlit as st
2
- from utils import go_to
3
- import random
4
  import pandas as pd
 
5
 
6
  ALL_FEATURES = [
7
  "Credit Score", "Annual Income", "Loan Amount Requested",
@@ -11,76 +9,48 @@ ALL_FEATURES = [
11
  ]
12
 
13
  def render():
14
- st.title("Information Loss Demo")
15
 
16
- # --- SESSION STATE ---
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
- if "cloud_positions" not in st.session_state:
22
- # Pre-generate random positions for each feature
23
- st.session_state.cloud_positions = {
24
- feature: (random.randint(0, 80), random.randint(0, 80))
25
- for feature in ALL_FEATURES
26
- }
27
 
28
- # --- LAYOUT ---
29
- col1, col2 = st.columns([1, 2])
30
 
31
- # TOP LEFT: Loan applicant icon
32
- with col1:
33
  st.image(
34
  "https://cdn-icons-png.flaticon.com/512/1048/1048949.png",
35
  caption="Loan Applicant",
36
- width=200
37
- )
38
-
39
- # TOP RIGHT: Feature cloud
40
- with col2:
41
- st.markdown("### Available Features")
42
-
43
- # Create a fixed-height area for the cloud
44
- cloud_html = "<div style='position: relative; height: 300px; border: 1px dashed #ccc;'>"
45
-
46
- for feature in st.session_state.available_features:
47
- top, left = st.session_state.cloud_positions[feature]
48
- # Button styled as text link in random position
49
- button_html = f"""
50
- <form action="" method="get" style="position: absolute; top: {top}%; left: {left}%; transform: translate(-50%, -50%);">
51
- <button name="feature_click" value="{feature}" style="background:none; border:none; color:blue; text-decoration:underline; cursor:pointer;">
52
- {feature}
53
- </button>
54
- </form>
55
- """
56
- cloud_html += button_html
57
-
58
- cloud_html += "</div>"
59
- st.markdown(cloud_html, unsafe_allow_html=True)
60
-
61
- # --- CLICK HANDLING ---
62
- clicked_feature = st.query_params.get("feature_click")
63
- if clicked_feature and clicked_feature in st.session_state.available_features:
64
- st.session_state.selected_features.append(clicked_feature + " (approx)")
65
- st.session_state.available_features.remove(clicked_feature)
66
- st.session_state.show_message = (
67
- f"Sorry, '{clicked_feature}' cannot be precisely collected. Adding approximation instead."
68
  )
69
- # Clear the query param to avoid re-adding on refresh
70
- st.query_params.clear()
71
- st.experimental_rerun()
72
 
73
- # --- MESSAGE ---
 
 
 
 
 
 
 
 
 
 
 
 
74
  if "show_message" in st.session_state:
75
  st.markdown(
76
- f"<div style='text-align:center; color:red; font-weight:bold; margin:20px 0;'>{st.session_state.show_message}</div>",
77
- unsafe_allow_html=True
78
  )
79
  del st.session_state.show_message
80
 
81
  st.markdown("---")
82
 
83
- # --- BOTTOM HALF: Dataset table ---
84
  st.markdown("### Current Dataset")
85
  if st.session_state.selected_features:
86
  cols = st.session_state.selected_features + ["Target Label"]
 
 
 
 
1
  import pandas as pd
2
+ import streamlit as st
3
 
4
  ALL_FEATURES = [
5
  "Credit Score", "Annual Income", "Loan Amount Requested",
 
9
  ]
10
 
11
  def render():
12
+ st.title("Information Loss")
13
 
14
+ # Session state init
15
  if "available_features" not in st.session_state:
16
  st.session_state.available_features = ALL_FEATURES.copy()
17
+
18
  if "selected_features" not in st.session_state:
19
  st.session_state.selected_features = []
 
 
 
 
 
 
20
 
21
+ # Top left: applicant image
22
+ top_left, top_right = st.columns([1, 1])
23
 
24
+ with top_left:
 
25
  st.image(
26
  "https://cdn-icons-png.flaticon.com/512/1048/1048949.png",
27
  caption="Loan Applicant",
28
+ width=260,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  )
 
 
 
30
 
31
+ # Top right: simple clickable list of features
32
+ with top_right:
33
+ st.markdown("**Available Features**")
34
+ for feature in st.session_state.available_features.copy():
35
+ if st.button(feature, key=feature):
36
+ st.session_state.selected_features.append(f"{feature} (approx)")
37
+ st.session_state.available_features.remove(feature)
38
+ st.session_state.show_message = (
39
+ f"Sorry, '{feature}' cannot be precisely collected. Adding approximation instead."
40
+ )
41
+ st.rerun()
42
+
43
+ # Centered message
44
  if "show_message" in st.session_state:
45
  st.markdown(
46
+ f"<div style='text-align:center; color:#c0392b; font-weight:600; margin:14px 0;'>{st.session_state.show_message}</div>",
47
+ unsafe_allow_html=True,
48
  )
49
  del st.session_state.show_message
50
 
51
  st.markdown("---")
52
 
53
+ # Bottom half: dataset table
54
  st.markdown("### Current Dataset")
55
  if st.session_state.selected_features:
56
  cols = st.session_state.selected_features + ["Target Label"]