"""PadCaptioner: omni-modal dense video captioning with parallelized autoregressive decoding. Paper: "Parallelized Autoregressive Decoding for Omni-Modal Dense Video Captioning" (ECCV 2026). Code: https://github.com/showlab/PadCaptioner Model: wenzhengzeng/PadCaptioner-3B The app mirrors the authors' reference test loop (`qwenvl/train/train_qwen_modified.py`, `scripts_run/test.sh`) exactly: the same preprocessing (LazySupervisedDataset with base_interval=0.5s, 64..256 frames, per-frame pixel budgets), the same inference options (grounding threshold 0.7, snap window 1, coverage mask, branch interval attention, dedup IoU 0.75), and the same post-processing (interval insertion into the placeholders, NMS over records). """ import os import subprocess import sys # Vendored transformers 4.51.3 (the version PadCaptioner was trained/evaluated with). # PyPI's transformers 4.51.3 metadata pins huggingface-hub<1.0, which conflicts with # gradio 6.x's huggingface-hub>=1.16 at pip-resolution time, so the vendored wheel's # metadata relaxes the cap to >=0.30.0 — the code itself is untouched. Installed with # --no-deps because its real deps are listed in requirements.txt. _HERE = os.path.dirname(os.path.abspath(__file__)) _VENDORED_WHEEL = os.path.join(_HERE, "vendor", "transformers-4.51.3-py3-none-any.whl") try: import transformers # noqa: F401 from transformers import __version__ as _tf_version # noqa: F401 if _tf_version != "4.51.3": raise ImportError("wrong transformers version") except Exception: subprocess.run( [sys.executable, "-m", "pip", "install", "--no-deps", "--quiet", _VENDORED_WHEEL], check=True, ) import spaces # MUST come before torch / transformers CUDA init import json import re import tempfile import time from types import SimpleNamespace import gradio as gr # The bundled qwenvl package (from github.com/showlab/PadCaptioner) sits next to app.py. sys.path.insert(0, _HERE) import torch # noqa: E402 (after spaces) import transformers # noqa: E402 from transformers import AutoTokenizer, WhisperFeatureExtractor # noqa: E402 from qwenvl.data.dataset import LazySupervisedDataset # noqa: E402 from qwenvl.data.image_processing_qwen2_vl_fast import Qwen2VLImageProcessorFast # noqa: E402 from qwenvl.model.modeling_qwen2_5_vl import video_SALMONN2_plus # noqa: E402 MODEL_ID = "wenzhengzeng/PadCaptioner-3B" # ---- Inference settings: the released-model evaluation settings from scripts_run/test.sh ---- MAX_PIXELS = 61250 MIN_PIXELS = 784 MIN_FRAMES = 64 MAX_FRAMES = 256 BASE_INTERVAL = 0.5 GROUNDING_THRESHOLD = 0.7 GROUNDING_MERGE_GAP = 0 GROUNDING_SNAP_WINDOW = 1 MAX_PLANNING_EVENTS = 24 DVC_DEDUP_IOU = 0.75 MAX_NEW_TOKENS = 1026 # task_body_cap default 1024 + 2 ( and EOS) # The dvc prompt used by the authors' test annotations (DATASET.md / test_dvc2000.json). DVC_PROMPT = ( "" in b or "