murphylmf commited on
Commit
2fb2b9e
·
1 Parent(s): a566eee
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -393,9 +393,9 @@ else:
393
  return func(*args, **kwargs)
394
  return wrapper
395
 
396
- # Adding default values to prevent "Too many arguments" errors in Gradio examples
397
  @gpu_decorator
398
  def predict(video_path, start_time=0.0, end_time=10.0):
 
399
  duration_input = end_time - start_time
400
  if duration_input > 10.0:
401
  raise gr.Error(f"Video limit exceeded ({duration_input:.1f}s). Please keep it under 10 seconds.")
@@ -403,6 +403,7 @@ def predict(video_path, start_time=0.0, end_time=10.0):
403
  if start_time >= end_time:
404
  raise gr.Error("Error: End time must be greater than Start time.")
405
 
 
406
  yield get_loading_html("Processing...")
407
 
408
  output_dir = tempfile.mkdtemp()
@@ -447,8 +448,8 @@ def predict(video_path, start_time=0.0, end_time=10.0):
447
  # 7. UI Construction
448
  # ==========================================
449
 
450
- # NOTE: Examples list only contains video path.
451
- # Inputs for examples are set to [input_video] to match the data structure.
452
  examples_list = []
453
  if os.path.exists(EXAMPLES_DIR):
454
  examples_list = [[os.path.join("examples", f)] for f in os.listdir(EXAMPLES_DIR) if f.endswith(".mp4")]
@@ -518,16 +519,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", radius_size="md"), css
518
 
519
  if examples_list:
520
  gr.Markdown("### 🎥 Examples")
521
- # Clean UI: Only showing video column.
522
- # Logic: Clicking an example populates 'input_video'.
523
- # The 'input_video.change' event then triggers 'update_slider_range',
524
- # which calculates duration and updates sliders automatically.
525
- # 'predict' handles default start/end times if not explicitly set.
526
  gr.Examples(
527
  examples=examples_list,
528
  inputs=[input_video],
529
  label="Click to try:",
530
- cache_examples=False
 
531
  )
532
 
533
  with gr.Column(scale=7):
@@ -557,15 +558,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", radius_size="md"), css
557
  dur = round(dur, 2)
558
  return gr.update(maximum=dur, value=0), gr.update(maximum=dur, value=dur)
559
 
 
560
  input_video.change(fn=update_slider_range, inputs=[input_video], outputs=[start_time, end_time])
561
  input_video.upload(fn=update_slider_range, inputs=[input_video], outputs=[start_time, end_time])
562
 
 
563
  input_video.change(fn=None, inputs=[], outputs=[], js=js_reset_video)
564
  input_video.upload(fn=None, inputs=[], outputs=[], js=js_reset_video)
565
 
 
566
  start_time.change(fn=None, inputs=[start_time], outputs=None, js=js_scrub)
567
  end_time.change(fn=None, inputs=[end_time], outputs=None, js=js_scrub)
568
 
 
569
  submit_btn.click(
570
  fn=predict,
571
  inputs=[input_video, start_time, end_time],
 
393
  return func(*args, **kwargs)
394
  return wrapper
395
 
 
396
  @gpu_decorator
397
  def predict(video_path, start_time=0.0, end_time=10.0):
398
+ # 1. Limit Check
399
  duration_input = end_time - start_time
400
  if duration_input > 10.0:
401
  raise gr.Error(f"Video limit exceeded ({duration_input:.1f}s). Please keep it under 10 seconds.")
 
403
  if start_time >= end_time:
404
  raise gr.Error("Error: End time must be greater than Start time.")
405
 
406
+ # 2. Normal Flow
407
  yield get_loading_html("Processing...")
408
 
409
  output_dir = tempfile.mkdtemp()
 
448
  # 7. UI Construction
449
  # ==========================================
450
 
451
+ # CRITICAL FIX: Only include video path in Examples list
452
+ # We removed the extra time columns to keep the UI clean
453
  examples_list = []
454
  if os.path.exists(EXAMPLES_DIR):
455
  examples_list = [[os.path.join("examples", f)] for f in os.listdir(EXAMPLES_DIR) if f.endswith(".mp4")]
 
519
 
520
  if examples_list:
521
  gr.Markdown("### 🎥 Examples")
522
+ # CRITICAL FIX: Explicitly tell Gradio that clicking an example ONLY updates 'input_video'.
523
+ # Do NOT trigger the 'predict' function automatically.
524
+ # The 'run_on_click=False' and 'fn=None' are implied when fn isn't provided,
525
+ # but ensuring 'inputs' matches the 'examples_list' structure (1 column -> 1 input) is key.
 
526
  gr.Examples(
527
  examples=examples_list,
528
  inputs=[input_video],
529
  label="Click to try:",
530
+ cache_examples=False,
531
+ run_on_click=False # Explicitly disable auto-run to avoid parameter mismatch
532
  )
533
 
534
  with gr.Column(scale=7):
 
558
  dur = round(dur, 2)
559
  return gr.update(maximum=dur, value=0), gr.update(maximum=dur, value=dur)
560
 
561
+ # 1. Update sliders when video changes (works for both Upload and Examples click)
562
  input_video.change(fn=update_slider_range, inputs=[input_video], outputs=[start_time, end_time])
563
  input_video.upload(fn=update_slider_range, inputs=[input_video], outputs=[start_time, end_time])
564
 
565
+ # 2. UI Helper: Reset video player visual
566
  input_video.change(fn=None, inputs=[], outputs=[], js=js_reset_video)
567
  input_video.upload(fn=None, inputs=[], outputs=[], js=js_reset_video)
568
 
569
+ # 3. UI Helper: Update video current time when slider moves
570
  start_time.change(fn=None, inputs=[start_time], outputs=None, js=js_scrub)
571
  end_time.change(fn=None, inputs=[end_time], outputs=None, js=js_scrub)
572
 
573
+ # 4. Main Inference Trigger
574
  submit_btn.click(
575
  fn=predict,
576
  inputs=[input_video, start_time, end_time],