multimodalart HF Staff commited on
Commit
f1eb7df
·
verified ·
1 Parent(s): 7517214

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -78,9 +78,12 @@ def extract_frames(video_path: str, num_frames: int = NUM_FRAMES,
78
  raise RuntimeError(f"Cannot open video: {video_path}")
79
 
80
  fps = cap.get(cv2.CAP_PROP_FPS)
81
- cap.set(cv2.CAP_PROP_POS_AVI_RATIO, 1)
82
- clip_duration = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000.0
83
- cap.set(cv2.CAP_PROP_POS_MSEC, 0)
 
 
 
84
  if clip_duration <= 0 or fps <= 0:
85
  cap.release()
86
  return [], 0.0
@@ -298,7 +301,7 @@ CSS = """
298
  .dark .gradio-container { color: var(--body-text-color); }
299
  """
300
 
301
- with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
302
  with gr.Column(elem_id="col-container"):
303
  gr.Markdown(
304
  """
@@ -327,9 +330,9 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
327
  label="Max new tokens")
328
 
329
  with gr.Column(scale=1):
330
- answer_out = gr.Textbox(label="Answer + grounded evidence", lines=12, show_copy_button=True)
331
- timeline_out = gr.Image(label="Evidence timeline", height=140, show_download_button=False)
332
- json_out = gr.Textbox(label="Model output (JSON)", lines=6, show_copy_button=True)
333
 
334
  gr.Markdown(
335
  """
@@ -364,4 +367,4 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
364
  api_name="answer_submit",
365
  )
366
 
367
- demo.launch(mcp_server=True)
 
78
  raise RuntimeError(f"Cannot open video: {video_path}")
79
 
80
  fps = cap.get(cv2.CAP_PROP_FPS)
81
+ n_total = cap.get(cv2.CAP_PROP_FRAME_COUNT)
82
+ clip_duration = (n_total / fps) if (fps and fps > 0 and n_total and n_total > 0) else 0.0
83
+ if clip_duration <= 0: # some muxers report no frame count — seek to the end instead
84
+ cap.set(cv2.CAP_PROP_POS_AVI_RATIO, 1)
85
+ clip_duration = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000.0
86
+ cap.set(cv2.CAP_PROP_POS_MSEC, 0)
87
  if clip_duration <= 0 or fps <= 0:
88
  cap.release()
89
  return [], 0.0
 
301
  .dark .gradio-container { color: var(--body-text-color); }
302
  """
303
 
304
+ with gr.Blocks() as demo:
305
  with gr.Column(elem_id="col-container"):
306
  gr.Markdown(
307
  """
 
330
  label="Max new tokens")
331
 
332
  with gr.Column(scale=1):
333
+ answer_out = gr.Textbox(label="Answer + grounded evidence", lines=12, buttons=["copy"])
334
+ timeline_out = gr.Image(label="Evidence timeline", height=140, buttons=[])
335
+ json_out = gr.Textbox(label="Model output (JSON)", lines=6, buttons=["copy"])
336
 
337
  gr.Markdown(
338
  """
 
367
  api_name="answer_submit",
368
  )
369
 
370
+ demo.launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True)