multimodalart HF Staff commited on
Commit
db0cf7d
·
verified ·
1 Parent(s): 4e1f6db

Fix video decode: PyAV reader replaces removed torchvision.io.read_video; Examples rule fix

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import os
2
 
3
  os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
 
 
 
4
 
5
  import spaces # noqa: E402 (must precede any torch import)
6
- import json # noqa: E402
7
  import re # noqa: E402
8
  import time # noqa: E402
9
  import html # noqa: E402
@@ -12,6 +14,13 @@ import torch # noqa: E402
12
  import gradio as gr # noqa: E402
13
  from transformers import AutoProcessor, Qwen3VLForConditionalGeneration # noqa: E402
14
  from qwen_vl_utils import process_vision_info # noqa: E402
 
 
 
 
 
 
 
15
 
16
  MODEL_ID = "TengfeiLiuCoder/RefCaptioner"
17
  MAX_REFS = 6
@@ -140,11 +149,11 @@ def highlight_tags(caption: str) -> str:
140
  def generate_caption(
141
  video,
142
  ref_1,
143
- ref_2,
144
- ref_3,
145
- ref_4,
146
- ref_5,
147
- ref_6,
148
  progress=gr.Progress(track_tqdm=True),
149
  ):
150
  """Generate a reference-grounded caption for a video.
@@ -284,14 +293,13 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
284
  examples=[
285
  # border collie running through a barley field; refs: a golden-retriever-like dog
286
  # (loose visual match the model may or may not ground) + a husky (clear distractor).
287
- ["examples/border_collie_running.mp4", "examples/dog.jpg", "examples/husky_dog.jpg",
288
- None, None, None, None],
289
  # man jumping rope on a city sidewalk; refs: white sneakers (worn in the video)
290
  # + a night city skyline (distractor — the video is daytime, no skyline).
291
- ["examples/man_jumping_rope.mp4", "examples/sneakers_white_studio.jpg", "examples/city_skyline_night.jpg",
292
- None, None, None, None],
293
  ],
294
- inputs=[video_in, *ref_components],
 
295
  outputs=[caption_html, caption_text, stats_md],
296
  fn=generate_caption,
297
  cache_examples=True,
 
1
  import os
2
 
3
  os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
4
+ # The runtime's torchvision (>=0.28) removed `torchvision.io.read_video`, which
5
+ # qwen-vl-utils 0.0.14 needs; pin the dispatch and swap in a PyAV decoder below.
6
+ os.environ.setdefault("FORCE_QWENVL_VIDEO_READER", "torchvision")
7
 
8
  import spaces # noqa: E402 (must precede any torch import)
 
9
  import re # noqa: E402
10
  import time # noqa: E402
11
  import html # noqa: E402
 
14
  import gradio as gr # noqa: E402
15
  from transformers import AutoProcessor, Qwen3VLForConditionalGeneration # noqa: E402
16
  from qwen_vl_utils import process_vision_info # noqa: E402
17
+ import qwen_vl_utils.vision_process as _vp # noqa: E402
18
+
19
+ import video_av_reader # noqa: E402
20
+
21
+ # PyAV bundles its own FFmpeg (no system libs needed) and mirrors the official
22
+ # torchvision backend 1:1 (smart_nframes + linspace indices + same metadata).
23
+ _vp.VIDEO_READER_BACKENDS["torchvision"] = video_av_reader.read_video_pyav
24
 
25
  MODEL_ID = "TengfeiLiuCoder/RefCaptioner"
26
  MAX_REFS = 6
 
149
  def generate_caption(
150
  video,
151
  ref_1,
152
+ ref_2=None,
153
+ ref_3=None,
154
+ ref_4=None,
155
+ ref_5=None,
156
+ ref_6=None,
157
  progress=gr.Progress(track_tqdm=True),
158
  ):
159
  """Generate a reference-grounded caption for a video.
 
293
  examples=[
294
  # border collie running through a barley field; refs: a golden-retriever-like dog
295
  # (loose visual match the model may or may not ground) + a husky (clear distractor).
296
+ ["examples/border_collie_running.mp4", "examples/dog.jpg", "examples/husky_dog.jpg"],
 
297
  # man jumping rope on a city sidewalk; refs: white sneakers (worn in the video)
298
  # + a night city skyline (distractor — the video is daytime, no skyline).
299
+ ["examples/man_jumping_rope.mp4", "examples/sneakers_white_studio.jpg", "examples/city_skyline_night.jpg"],
 
300
  ],
301
+ # Examples fill video + <Image_1> + <Image_2>; ref_3..ref_6 stay at their defaults.
302
+ inputs=[video_in, r1, r2],
303
  outputs=[caption_html, caption_text, stats_md],
304
  fn=generate_caption,
305
  cache_examples=True,