samin commited on
Commit
3951a6d
Β·
verified Β·
1 Parent(s): c389fac

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +40 -30
src/streamlit_app.py CHANGED
@@ -94,8 +94,7 @@ def _display_images(urls, caption_prefix="", max_per_row=3, fixed_height_px=None
94
  st.write("No images found.")
95
  return
96
 
97
- # 3 equal columns, pin to top so text doesn’t jiggle vertically
98
- cols = st.columns([1, 1, 1], vertical_alignment="top")
99
  for i, url in enumerate(urls):
100
  col = cols[i % max_per_row]
101
  with col:
@@ -118,31 +117,22 @@ def _display_images(urls, caption_prefix="", max_per_row=3, fixed_height_px=None
118
  # ──────────────────────────────────────────────────────────────────────────────
119
  # Global CSS to reduce β€œvibrating” / layout reflow
120
  # ──────────────────────────────────────────────────────────────────────────────
121
- def _inject_css(fixed_height_px: int | None):
122
- css = f"""
123
  <style>
124
- /* Keep base container tighter so jumps feel smaller */
125
- .block-container {{ padding-top: 0.75rem; }}
126
-
127
- /* Images rendered via st.image: constrain to container width and avoid overflow */
128
- [data-testid="stImage"] img {{
129
  width: 100%;
130
  height: auto;
131
  object-fit: contain;
132
  display: block;
133
- }}
134
-
135
- /* Smooth out font jank on Spaces (fonts can swap) */
136
- html * {{
137
  -webkit-font-smoothing: antialiased;
138
  -moz-osx-font-smoothing: grayscale;
139
  text-rendering: optimizeLegibility;
140
- }}
141
-
142
- /* When using fixed frames (custom HTML), give them a subtle background so size is obvious */
143
- .img-frame {{
144
- background: rgba(0,0,0,0.03);
145
- }}
146
  </style>
147
  """
148
  st.markdown(css, unsafe_allow_html=True)
@@ -154,25 +144,39 @@ def main():
154
  st.title("πŸ–ΌοΈ ImagenHub2 Data Visualization")
155
  st.markdown("Each task starts with **10** items β€” click **Show more** to load **+10**.")
156
 
157
- # Sidebar (put toggles before we render content)
 
 
 
 
158
  st.sidebar.header("Filters")
159
- fixed_height_on = st.sidebar.toggle("Stabilize grid with fixed image height", value=True, help="Pre-allocate space for images to prevent page β€˜vibrating’.")
160
- fixed_height_px = st.sidebar.number_input("Fixed image height (px)", min_value=120, max_value=1200, value=320, step=20, disabled=not fixed_height_on)
 
 
 
 
 
 
 
 
161
  _inject_css(fixed_height_px if fixed_height_on else None)
162
 
163
  selected_tasks = st.sidebar.multiselect("Select Tasks", DATA_DIRS, default=DATA_DIRS)
164
  search_query = st.sidebar.text_input("πŸ” Search in prompts", "")
165
- topic_filter = st.sidebar.text_input("Filter by topic id (exact match, optional)", "")
 
 
 
 
 
 
166
  subtopic_filter = st.sidebar.text_input("Filter by subtopic (optional)", "")
167
 
168
  st.sidebar.header("Task Descriptions")
169
  for t in selected_tasks:
170
  st.sidebar.write(f"**{t}**: {TASK_DESCRIPTIONS.get(t, '')}")
171
 
172
- # Load manifest
173
- with st.spinner("Loading manifest…"):
174
- per_task, _all_topics = load_manifest()
175
-
176
  # Tabs per selected task
177
  tabs = st.tabs(selected_tasks) if selected_tasks else []
178
  for task, tab in zip(selected_tasks, tabs):
@@ -187,7 +191,7 @@ def main():
187
  if sq and (sq not in it.get("prompt", "").lower()
188
  and sq not in it.get("prompt_refined", "").lower()):
189
  return False
190
- if topic_filter and it.get("topic", "") != topic_filter:
191
  return False
192
  if subtopic_filter and it.get("subtopic", "") != subtopic_filter:
193
  return False
@@ -222,10 +226,16 @@ def main():
222
 
223
  if cond_urls:
224
  st.write("**Condition Images:**")
225
- _display_images(cond_urls, "Condition", max_per_row=3, fixed_height_px=(fixed_height_px if fixed_height_on else None))
 
 
 
226
  if model_urls:
227
  st.write("**Model Output:**")
228
- _display_images(model_urls, "Model", max_per_row=3, fixed_height_px=(fixed_height_px if fixed_height_on else None))
 
 
 
229
  st.divider()
230
 
231
  # Pagination controls
 
94
  st.write("No images found.")
95
  return
96
 
97
+ cols = st.columns(max_per_row, vertical_alignment="top")
 
98
  for i, url in enumerate(urls):
99
  col = cols[i % max_per_row]
100
  with col:
 
117
  # ──────────────────────────────────────────────────────────────────────────────
118
  # Global CSS to reduce β€œvibrating” / layout reflow
119
  # ──────────────────────────────────────────────────────────────────────────────
120
+ def _inject_css(_fixed_height_px: int | None):
121
+ css = """
122
  <style>
123
+ .block-container { padding-top: 0.75rem; }
124
+ [data-testid="stImage"] img {
 
 
 
125
  width: 100%;
126
  height: auto;
127
  object-fit: contain;
128
  display: block;
129
+ }
130
+ html * {
 
 
131
  -webkit-font-smoothing: antialiased;
132
  -moz-osx-font-smoothing: grayscale;
133
  text-rendering: optimizeLegibility;
134
+ }
135
+ .img-frame { background: rgba(0,0,0,0.03); }
 
 
 
 
136
  </style>
137
  """
138
  st.markdown(css, unsafe_allow_html=True)
 
144
  st.title("πŸ–ΌοΈ ImagenHub2 Data Visualization")
145
  st.markdown("Each task starts with **10** items β€” click **Show more** to load **+10**.")
146
 
147
+ # Load manifest first (to get topic list)
148
+ with st.spinner("Loading manifest…"):
149
+ per_task, _all_topics = load_manifest()
150
+
151
+ # Sidebar
152
  st.sidebar.header("Filters")
153
+ fixed_height_on = st.sidebar.toggle(
154
+ "Stabilize grid with fixed image height",
155
+ value=True,
156
+ help="Pre-allocate space for images to prevent page β€˜vibrating’."
157
+ )
158
+ fixed_height_px = st.sidebar.number_input(
159
+ "Fixed image height (px)",
160
+ min_value=120, max_value=1200, value=320, step=20,
161
+ disabled=not fixed_height_on
162
+ )
163
  _inject_css(fixed_height_px if fixed_height_on else None)
164
 
165
  selected_tasks = st.sidebar.multiselect("Select Tasks", DATA_DIRS, default=DATA_DIRS)
166
  search_query = st.sidebar.text_input("πŸ” Search in prompts", "")
167
+ # Topic filter behaves like task filter (multiselect)
168
+ topic_filter = st.sidebar.multiselect(
169
+ "Select Topics",
170
+ _all_topics,
171
+ default=[],
172
+ help="Filter items by one or more topic IDs."
173
+ )
174
  subtopic_filter = st.sidebar.text_input("Filter by subtopic (optional)", "")
175
 
176
  st.sidebar.header("Task Descriptions")
177
  for t in selected_tasks:
178
  st.sidebar.write(f"**{t}**: {TASK_DESCRIPTIONS.get(t, '')}")
179
 
 
 
 
 
180
  # Tabs per selected task
181
  tabs = st.tabs(selected_tasks) if selected_tasks else []
182
  for task, tab in zip(selected_tasks, tabs):
 
191
  if sq and (sq not in it.get("prompt", "").lower()
192
  and sq not in it.get("prompt_refined", "").lower()):
193
  return False
194
+ if topic_filter and it.get("topic", "") not in topic_filter:
195
  return False
196
  if subtopic_filter and it.get("subtopic", "") != subtopic_filter:
197
  return False
 
226
 
227
  if cond_urls:
228
  st.write("**Condition Images:**")
229
+ _display_images(
230
+ cond_urls, "Condition", max_per_row=3,
231
+ fixed_height_px=(fixed_height_px if fixed_height_on else None)
232
+ )
233
  if model_urls:
234
  st.write("**Model Output:**")
235
+ _display_images(
236
+ model_urls, "Model", max_per_row=3,
237
+ fixed_height_px=(fixed_height_px if fixed_height_on else None)
238
+ )
239
  st.divider()
240
 
241
  # Pagination controls