derektan commited on
Commit
7af86d2
Β·
1 Parent(s): 208b0a9

Added in slider after episode is completed

Browse files
Files changed (1) hide show
  1. app.py +59 -8
app.py CHANGED
@@ -131,8 +131,18 @@ def process_search_tta(
131
  ):
132
  """Run both TTA and non-TTA search episodes concurrently and stream both heat-maps."""
133
 
134
- # Disable Run button and clear image/status outputs
135
- yield gr.update(interactive=False), gr.update(value=None), gr.update(value=None), gr.update(value="Initializing model…"), gr.update(value="Initializing model…")
 
 
 
 
 
 
 
 
 
 
136
 
137
  # Bail early if satellite image missing
138
  if sat_path is None:
@@ -246,7 +256,17 @@ def process_search_tta(
246
 
247
  # Emit update if we have a new frame OR if the status label has changed
248
  if updated or status_tta != prev_status_tta or status_no != prev_status_no:
249
- yield gr.update(interactive=False), last_tta, last_no, gr.update(value=status_tta), gr.update(value=status_no)
 
 
 
 
 
 
 
 
 
 
250
  prev_status_tta = status_tta
251
  prev_status_no = status_no
252
 
@@ -270,8 +290,24 @@ def process_search_tta(
270
  sent_no.add(fp)
271
  last_no = fp
272
 
273
- # Final emit after both finish (and after final scan)
274
- yield gr.update(interactive=True), last_tta, last_no, gr.update(value="Done."), gr.update(value="Done.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
276
 
277
  # ────────────────────────── Gradio UI ─────────────────────────────────
@@ -333,9 +369,24 @@ with gr.Blocks(title="Search-TTA (Simplified)", theme=gr.themes.Base()) as demo:
333
  # gr.Markdown("### Live Heatmap (with TTA)")
334
  display_img_tta = gr.Image(label="Heatmap (TTA per 20 steps)", type="filepath", height=400) # 512
335
  status_tta = gr.Markdown("")
336
- # gr.Markdown("### Live Heatmap (without TTA)")
 
337
  display_img_no_tta = gr.Image(label="Heatmap (no TTA)", type="filepath", height=400) # 512
338
  status_no_tta = gr.Markdown("")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  # Bind callback
341
 
@@ -362,7 +413,7 @@ with gr.Blocks(title="Search-TTA (Simplified)", theme=gr.themes.Base()) as demo:
362
  ],
363
  ],
364
  inputs=[sat_input, ground_input, taxonomy_input],
365
- outputs=[run_btn, display_img_tta, display_img_no_tta, status_tta, status_no_tta],
366
  fn=process_search_tta,
367
  cache_examples=False,
368
  )
@@ -371,7 +422,7 @@ with gr.Blocks(title="Search-TTA (Simplified)", theme=gr.themes.Base()) as demo:
371
  run_btn.click(
372
  fn=process_search_tta,
373
  inputs=[sat_input, ground_input, taxonomy_input],
374
- outputs=[run_btn, display_img_tta, display_img_no_tta, status_tta, status_no_tta],
375
  )
376
 
377
  # Footer to point out to model and data from app page.
 
131
  ):
132
  """Run both TTA and non-TTA search episodes concurrently and stream both heat-maps."""
133
 
134
+ # Disable Run button and clear image/status outputs, hide sliders, clear frame states
135
+ yield (
136
+ gr.update(interactive=False),
137
+ gr.update(value=None),
138
+ gr.update(value=None),
139
+ gr.update(value="Initializing model…"),
140
+ gr.update(value="Initializing model…"),
141
+ gr.update(visible=False),
142
+ gr.update(visible=False),
143
+ [],
144
+ [],
145
+ )
146
 
147
  # Bail early if satellite image missing
148
  if sat_path is None:
 
256
 
257
  # Emit update if we have a new frame OR if the status label has changed
258
  if updated or status_tta != prev_status_tta or status_no != prev_status_no:
259
+ yield (
260
+ gr.update(interactive=False),
261
+ last_tta,
262
+ last_no,
263
+ gr.update(value=status_tta, visible=True),
264
+ gr.update(value=status_no, visible=True),
265
+ gr.update(visible=False),
266
+ gr.update(visible=False),
267
+ gr.update(),
268
+ gr.update(),
269
+ )
270
  prev_status_tta = status_tta
271
  prev_status_no = status_no
272
 
 
290
  sent_no.add(fp)
291
  last_no = fp
292
 
293
+ # Prepare frames list and slider configs
294
+ frames_tta = sorted(glob.glob(os.path.join(gifs_dir_tta, "*.png")), key=lambda p: int(os.path.splitext(os.path.basename(p))[0]))
295
+ frames_no = sorted(glob.glob(os.path.join(gifs_dir_no, "*.png")), key=lambda p: int(os.path.splitext(os.path.basename(p))[0]))
296
+ n_tta = len(frames_tta) or 1 # prevent zero-range slider
297
+ n_no = len(frames_no) or 1
298
+
299
+ # Final emit: re-enable button, hide statuses, show sliders set to last frame
300
+ yield (
301
+ gr.update(interactive=True),
302
+ last_tta,
303
+ last_no,
304
+ gr.update(visible=False),
305
+ gr.update(visible=False),
306
+ gr.update(visible=True, minimum=1, maximum=n_tta, value=n_tta),
307
+ gr.update(visible=True, minimum=1, maximum=n_no, value=n_no),
308
+ frames_tta,
309
+ frames_no,
310
+ )
311
 
312
 
313
  # ────────────────────────── Gradio UI ─────────────────────────────────
 
369
  # gr.Markdown("### Live Heatmap (with TTA)")
370
  display_img_tta = gr.Image(label="Heatmap (TTA per 20 steps)", type="filepath", height=400) # 512
371
  status_tta = gr.Markdown("")
372
+ slider_tta = gr.Slider(label="TTA Frame", minimum=1, maximum=1, step=1, value=1, visible=False)
373
+
374
  display_img_no_tta = gr.Image(label="Heatmap (no TTA)", type="filepath", height=400) # 512
375
  status_no_tta = gr.Markdown("")
376
+ slider_no = gr.Slider(label="No-TTA Frame", minimum=1, maximum=1, step=1, value=1, visible=False)
377
+
378
+ frames_state_tta = gr.State([])
379
+ frames_state_no = gr.State([])
380
+
381
+ # Slider callbacks (updates image when user drags slider)
382
+ def _show_frame(idx: int, frames: list[str]):
383
+ # Slider is 1-indexed; convert to 0-indexed list access
384
+ if 1 <= idx <= len(frames):
385
+ return frames[idx - 1]
386
+ return gr.update()
387
+
388
+ slider_tta.change(_show_frame, inputs=[slider_tta, frames_state_tta], outputs=display_img_tta)
389
+ slider_no.change(_show_frame, inputs=[slider_no, frames_state_no], outputs=display_img_no_tta)
390
 
391
  # Bind callback
392
 
 
413
  ],
414
  ],
415
  inputs=[sat_input, ground_input, taxonomy_input],
416
+ outputs=[run_btn, display_img_tta, display_img_no_tta, status_tta, status_no_tta, slider_tta, slider_no, frames_state_tta, frames_state_no],
417
  fn=process_search_tta,
418
  cache_examples=False,
419
  )
 
422
  run_btn.click(
423
  fn=process_search_tta,
424
  inputs=[sat_input, ground_input, taxonomy_input],
425
+ outputs=[run_btn, display_img_tta, display_img_no_tta, status_tta, status_no_tta, slider_tta, slider_no, frames_state_tta, frames_state_no],
426
  )
427
 
428
  # Footer to point out to model and data from app page.