murphylmf commited on
Commit
a566eee
·
1 Parent(s): d162fb9
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -393,9 +393,9 @@ else:
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,7 +403,6 @@ 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
- # 2. Normal Flow
407
  yield get_loading_html("Processing...")
408
 
409
  output_dir = tempfile.mkdtemp()
@@ -448,11 +447,11 @@ def predict(video_path, start_time=0.0, end_time=10.0):
448
  # 7. UI Construction
449
  # ==========================================
450
 
451
- # --- CRITICAL FIX: Ensure examples have 3 elements to match inputs=[video, start, end] ---
 
452
  examples_list = []
453
  if os.path.exists(EXAMPLES_DIR):
454
- # Padding with default start=0.0, end=10.0
455
- examples_list = [[os.path.join("examples", f), 0.0, 10.0] for f in os.listdir(EXAMPLES_DIR) if f.endswith(".mp4")]
456
 
457
  js_scrub = """(val) => {
458
  var video = document.querySelector('#input-video video');
@@ -519,9 +518,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", radius_size="md"), css
519
 
520
  if examples_list:
521
  gr.Markdown("### 🎥 Examples")
 
 
 
 
 
522
  gr.Examples(
523
  examples=examples_list,
524
- inputs=[input_video, start_time, end_time],
525
  label="Click to try:",
526
  cache_examples=False
527
  )
 
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
  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
  # 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")]
 
455
 
456
  js_scrub = """(val) => {
457
  var video = document.querySelector('#input-video video');
 
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
  )