gaozhongpai commited on
Commit
f57d572
·
1 Parent(s): ea74719

Fix live example loading: use gr.update and factory function for proper state update

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -149,13 +149,13 @@ def on_example_change(task_name, example_choice):
149
  MAX_FRAMES = 60 # 1fps × 60s = up to 60 frames
150
 
151
 
152
- def load_live_example(example_idx):
153
- """Load a pre-built live example into the inference inputs."""
154
- if example_idx is None or example_idx < 0 or example_idx >= len(LIVE_EXAMPLES):
155
- return None, None, ""
156
- ex = LIVE_EXAMPLES[example_idx]
157
- images = [str(ROOT / fp) for fp in ex["frames"] if (ROOT / fp).exists()]
158
- return None, images, ex["question"]
159
 
160
 
161
  def extract_frames_1fps(video_path: str, max_frames: int = MAX_FRAMES) -> list:
@@ -431,7 +431,7 @@ with gr.Blocks(
431
 
432
  for idx, btn in example_btns:
433
  btn.click(
434
- fn=lambda i=idx: load_live_example(i),
435
  inputs=[],
436
  outputs=[video_input, image_input, infer_question],
437
  )
 
149
  MAX_FRAMES = 60 # 1fps × 60s = up to 60 frames
150
 
151
 
152
+ def make_load_live_example(example_idx):
153
+ """Create a loader function for a specific live example index."""
154
+ def _load():
155
+ ex = LIVE_EXAMPLES[example_idx]
156
+ images = [str(ROOT / fp) for fp in ex["frames"] if (ROOT / fp).exists()]
157
+ return gr.update(value=None), gr.update(value=images), gr.update(value=ex["question"])
158
+ return _load
159
 
160
 
161
  def extract_frames_1fps(video_path: str, max_frames: int = MAX_FRAMES) -> list:
 
431
 
432
  for idx, btn in example_btns:
433
  btn.click(
434
+ fn=make_load_live_example(idx),
435
  inputs=[],
436
  outputs=[video_input, image_input, infer_question],
437
  )