Spaces:
Running
Running
fix: render video via native <video> HTML to bypass gradio SSRF-download of HF xet CDN
Browse files
app.py
CHANGED
|
@@ -139,11 +139,20 @@ def _format_meta(model: str, task: dict[str, Any], idx: int, total: int) -> str:
|
|
| 139 |
|
| 140 |
def _load_item(pool_order: list[int], idx: int) -> tuple[str, str, str]:
|
| 141 |
if idx < 0 or idx >= len(pool_order):
|
| 142 |
-
return "", "**All done!** No more items.", ""
|
| 143 |
model, task_id = POOL[pool_order[idx]]
|
| 144 |
task = TASK_BY_ID[task_id]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
return (
|
| 146 |
-
|
| 147 |
_format_meta(model, task, idx, len(pool_order)),
|
| 148 |
_extract_prompt(task),
|
| 149 |
)
|
|
@@ -161,9 +170,9 @@ def start_session(annotator: str, state: dict):
|
|
| 161 |
rng = random.Random(f"{annotator}-{int(time.time())}")
|
| 162 |
rng.shuffle(order)
|
| 163 |
state = {"annotator": annotator, "order": order, "idx": 0}
|
| 164 |
-
|
| 165 |
status = f"✅ Logged in as `{annotator}` — {len(order)} items to annotate."
|
| 166 |
-
return state,
|
| 167 |
|
| 168 |
|
| 169 |
def submit_and_next(state: dict, score: float, note: str):
|
|
@@ -186,16 +195,16 @@ def submit_and_next(state: dict, score: float, note: str):
|
|
| 186 |
}
|
| 187 |
_append_annotation(record)
|
| 188 |
state["idx"] = idx + 1
|
| 189 |
-
|
| 190 |
-
return state,
|
| 191 |
|
| 192 |
|
| 193 |
def skip_and_next(state: dict):
|
| 194 |
if not state or "order" not in state:
|
| 195 |
return state, "", "⚠️ Please log in first.", "", 3, "", "⚠️ Not logged in."
|
| 196 |
state["idx"] = state["idx"] + 1
|
| 197 |
-
|
| 198 |
-
return state,
|
| 199 |
|
| 200 |
|
| 201 |
# ---------------------------------------------------------------------------
|
|
@@ -228,7 +237,12 @@ with gr.Blocks(title="MBench-V Annotation", theme=gr.themes.Soft()) as demo:
|
|
| 228 |
|
| 229 |
with gr.Row():
|
| 230 |
with gr.Column(scale=3):
|
| 231 |
-
video = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
with gr.Column(scale=2):
|
| 233 |
meta_md = gr.Markdown()
|
| 234 |
prompt_tb = gr.Textbox(
|
|
|
|
| 139 |
|
| 140 |
def _load_item(pool_order: list[int], idx: int) -> tuple[str, str, str]:
|
| 141 |
if idx < 0 or idx >= len(pool_order):
|
| 142 |
+
return "<div style='padding:24px;color:#888'>All done — no more items.</div>", "**All done!** No more items.", ""
|
| 143 |
model, task_id = POOL[pool_order[idx]]
|
| 144 |
task = TASK_BY_ID[task_id]
|
| 145 |
+
url = _video_url(model, task_id)
|
| 146 |
+
# Render a native <video> so the browser streams directly from HF CDN,
|
| 147 |
+
# bypassing gradio's server-side SSRF-protected download (which blocks
|
| 148 |
+
# the xet-bridge hostnames).
|
| 149 |
+
video_html = (
|
| 150 |
+
f'<video src="{url}" controls autoplay loop muted playsinline '
|
| 151 |
+
f'style="width:100%;max-height:520px;background:#000;border-radius:8px;">'
|
| 152 |
+
f'Your browser does not support HTML5 video.</video>'
|
| 153 |
+
)
|
| 154 |
return (
|
| 155 |
+
video_html,
|
| 156 |
_format_meta(model, task, idx, len(pool_order)),
|
| 157 |
_extract_prompt(task),
|
| 158 |
)
|
|
|
|
| 170 |
rng = random.Random(f"{annotator}-{int(time.time())}")
|
| 171 |
rng.shuffle(order)
|
| 172 |
state = {"annotator": annotator, "order": order, "idx": 0}
|
| 173 |
+
video_html, meta, prompt = _load_item(order, 0)
|
| 174 |
status = f"✅ Logged in as `{annotator}` — {len(order)} items to annotate."
|
| 175 |
+
return state, video_html, meta, prompt, status
|
| 176 |
|
| 177 |
|
| 178 |
def submit_and_next(state: dict, score: float, note: str):
|
|
|
|
| 195 |
}
|
| 196 |
_append_annotation(record)
|
| 197 |
state["idx"] = idx + 1
|
| 198 |
+
video_html, meta, prompt = _load_item(state["order"], state["idx"])
|
| 199 |
+
return state, video_html, meta, prompt, 3, "", f"✅ Submitted ({state['idx']}). Next →"
|
| 200 |
|
| 201 |
|
| 202 |
def skip_and_next(state: dict):
|
| 203 |
if not state or "order" not in state:
|
| 204 |
return state, "", "⚠️ Please log in first.", "", 3, "", "⚠️ Not logged in."
|
| 205 |
state["idx"] = state["idx"] + 1
|
| 206 |
+
video_html, meta, prompt = _load_item(state["order"], state["idx"])
|
| 207 |
+
return state, video_html, meta, prompt, 3, "", f"⏭️ Skipped. Position: {state['idx']}"
|
| 208 |
|
| 209 |
|
| 210 |
# ---------------------------------------------------------------------------
|
|
|
|
| 237 |
|
| 238 |
with gr.Row():
|
| 239 |
with gr.Column(scale=3):
|
| 240 |
+
video = gr.HTML(
|
| 241 |
+
value="<div style='padding:24px;color:#888;text-align:center'>"
|
| 242 |
+
"Enter your name above and click <b>Start</b> to load the first video."
|
| 243 |
+
"</div>",
|
| 244 |
+
label="Generated video",
|
| 245 |
+
)
|
| 246 |
with gr.Column(scale=2):
|
| 247 |
meta_md = gr.Markdown()
|
| 248 |
prompt_tb = gr.Textbox(
|