Spaces:
Runtime error

MRM5 commited on
Commit
8610087
·
verified ·
1 Parent(s): 9eecc41

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -17
src/streamlit_app.py CHANGED
@@ -16,7 +16,7 @@ st.set_page_config(
16
  # Absolute path handling for Docker/HF environment
17
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
18
 
19
- # 2. Ultra-Rigid CSS: Total Layout Locking
20
  st.markdown("""
21
  <style>
22
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&display=swap');
@@ -27,7 +27,7 @@ st.markdown("""
27
  font-family: 'Plus Jakarta Sans', sans-serif;
28
  }
29
 
30
- /* SIDEBAR LOCK: Fixed width to prevent horizontal jitter */
31
  [data-testid="stSidebar"] {
32
  background-color: #0f172a !important;
33
  border-right: 1px solid #1e293b;
@@ -35,18 +35,26 @@ st.markdown("""
35
  max-width: 260px !important;
36
  }
37
 
38
- /* METRIC LOCK: Static height prevents vertical shifts */
 
 
 
 
 
 
 
39
  .metric-card {
40
  background: rgba(15, 23, 42, 0.6);
41
  backdrop-filter: blur(16px);
42
  border: 1px solid rgba(16, 185, 129, 0.2);
43
  border-radius: 1rem;
44
- padding: 1.5rem;
45
  text-align: center;
46
  min-height: 100px;
47
  }
 
48
 
49
- /* PRIMARY ACTION BUTTON */
50
  div[class="stButton"] > button {
51
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
52
  color: #ffffff !important;
@@ -56,6 +64,7 @@ st.markdown("""
56
  font-weight: 800;
57
  width: 100%;
58
  text-transform: uppercase;
 
59
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
60
  }
61
  </style>
@@ -81,7 +90,8 @@ def load_assets():
81
  model, class_indices = load_assets()
82
 
83
  def predict_disease(image):
84
- img = image.convert("RGB") # Fixes channel mismatch
 
85
  img = img.resize((224, 224))
86
  img_array = np.array(img).astype('float32') / 255.
87
  predictions = model.predict(np.expand_dims(img_array, axis=0))
@@ -106,7 +116,7 @@ with m2: st.markdown('<div class="metric-card"><h3>CNN Accuracy</h3><h2>96.5%</h
106
 
107
  st.divider()
108
 
109
- # 5. Fixed 2x2 Clinical Grid
110
  st.markdown("### Clinical Specimens")
111
  samples = [
112
  ("Apple Rot", "apple_black rot.jpeg"),
@@ -118,35 +128,35 @@ samples = [
118
  if 'active_img' not in st.session_state:
119
  st.session_state.active_img = None
120
 
121
- # Row 1 (Items 1 & 2)
122
- c1, c2 = st.columns(2)
123
- for i, col in enumerate([c1, c2]):
124
  name, filename = samples[i]
125
  img_path = os.path.join(BASE_DIR, filename)
126
  with col:
127
  if os.path.exists(img_path):
128
- st.image(Image.open(img_path), width=130) # Fixed pixel width
129
  if st.button(f"Analyze {name}", key=f"btn_{i}"):
130
  st.session_state.active_img = Image.open(img_path)
131
 
132
- # Row 2 (Items 3 & 4)
133
- c3, c4 = st.columns(2)
134
- for i, col in enumerate([c3, c4], start=2):
135
  name, filename = samples[i]
136
  img_path = os.path.join(BASE_DIR, filename)
137
  with col:
138
  if os.path.exists(img_path):
139
- st.image(Image.open(img_path), width=130) # Fixed pixel width
140
  if st.button(f"Analyze {name}", key=f"btn_{i}"):
141
  st.session_state.active_img = Image.open(img_path)
142
 
143
  st.divider()
144
 
145
- # 6. Analysis Hub (File Uploader Completely Removed)
146
  col_up, col_res = st.columns([1.2, 1])
147
  with col_up:
148
  if st.session_state.active_img:
149
- st.image(st.session_state.active_img, width=320) # Rigid display constraint
150
  else:
151
  # Static placeholder to prevent layout collapse
152
  st.markdown('<div style="border: 1px solid #1e293b; border-radius: 1rem; height: 320px; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.4); color: #64748b; text-align: center; padding: 20px;">Select a clinical specimen above to begin automated pathology assessment</div>', unsafe_allow_html=True)
 
16
  # Absolute path handling for Docker/HF environment
17
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
18
 
19
+ # 2. Ultra-Stable CSS: Rigid Container Locking & Jitter Fixes
20
  st.markdown("""
21
  <style>
22
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&display=swap');
 
27
  font-family: 'Plus Jakarta Sans', sans-serif;
28
  }
29
 
30
+ /* SIDEBAR LOCK: Strict width prevents horizontal jitter */
31
  [data-testid="stSidebar"] {
32
  background-color: #0f172a !important;
33
  border-right: 1px solid #1e293b;
 
35
  max-width: 260px !important;
36
  }
37
 
38
+ /* IMAGE CONTAINER LOCK: Reserves height to prevent shaking */
39
+ [data-testid="stImage"] {
40
+ background-color: rgba(15, 23, 42, 0.4);
41
+ border-radius: 0.8rem;
42
+ border: 1px solid #1e293b;
43
+ overflow: hidden;
44
+ }
45
+
46
  .metric-card {
47
  background: rgba(15, 23, 42, 0.6);
48
  backdrop-filter: blur(16px);
49
  border: 1px solid rgba(16, 185, 129, 0.2);
50
  border-radius: 1rem;
51
+ padding: 1rem;
52
  text-align: center;
53
  min-height: 100px;
54
  }
55
+ .metric-card h2 { color: #10b981; font-size: 1.8rem; font-weight: 800; margin: 0; }
56
 
57
+ /* HIGH-VISIBILITY PRIMARY ACTION BUTTON */
58
  div[class="stButton"] > button {
59
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
60
  color: #ffffff !important;
 
64
  font-weight: 800;
65
  width: 100%;
66
  text-transform: uppercase;
67
+ letter-spacing: 0.1em;
68
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
69
  }
70
  </style>
 
90
  model, class_indices = load_assets()
91
 
92
  def predict_disease(image):
93
+ # RGB conversion prevents depth mismatch (4 vs 3 channels)
94
+ img = image.convert("RGB")
95
  img = img.resize((224, 224))
96
  img_array = np.array(img).astype('float32') / 255.
97
  predictions = model.predict(np.expand_dims(img_array, axis=0))
 
116
 
117
  st.divider()
118
 
119
+ # 5. Fixed 2-Row, 2-Column Clinical Specimen Grid
120
  st.markdown("### Clinical Specimens")
121
  samples = [
122
  ("Apple Rot", "apple_black rot.jpeg"),
 
128
  if 'active_img' not in st.session_state:
129
  st.session_state.active_img = None
130
 
131
+ # Row 1 (Specimens 1 & 2)
132
+ r1_c1, r1_c2 = st.columns(2)
133
+ for i, col in enumerate([r1_c1, r1_c2]):
134
  name, filename = samples[i]
135
  img_path = os.path.join(BASE_DIR, filename)
136
  with col:
137
  if os.path.exists(img_path):
138
+ st.image(Image.open(img_path), width=130) # Fixed size
139
  if st.button(f"Analyze {name}", key=f"btn_{i}"):
140
  st.session_state.active_img = Image.open(img_path)
141
 
142
+ # Row 2 (Specimens 3 & 4)
143
+ r2_c1, r2_c2 = st.columns(2)
144
+ for i, col in enumerate([r2_c1, r2_c2], start=2):
145
  name, filename = samples[i]
146
  img_path = os.path.join(BASE_DIR, filename)
147
  with col:
148
  if os.path.exists(img_path):
149
+ st.image(Image.open(img_path), width=130) # Fixed size
150
  if st.button(f"Analyze {name}", key=f"btn_{i}"):
151
  st.session_state.active_img = Image.open(img_path)
152
 
153
  st.divider()
154
 
155
+ # 6. Analysis Hub (No Uploader Section)
156
  col_up, col_res = st.columns([1.2, 1])
157
  with col_up:
158
  if st.session_state.active_img:
159
+ st.image(st.session_state.active_img, width=320) # Rigid display width
160
  else:
161
  # Static placeholder to prevent layout collapse
162
  st.markdown('<div style="border: 1px solid #1e293b; border-radius: 1rem; height: 320px; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.4); color: #64748b; text-align: center; padding: 20px;">Select a clinical specimen above to begin automated pathology assessment</div>', unsafe_allow_html=True)