Spaces:
Running on Zero

vtwo commited on
Commit
d8d21fa
·
verified ·
1 Parent(s): 7d3ee2b

Restyle the page: plain theme, header, answer panel, example labels

Browse files
Files changed (1) hide show
  1. app.py +99 -31
app.py CHANGED
@@ -292,42 +292,110 @@ def answer(video: str, question: str, model_choice: str = SIZES[0], num_frames:
292
  return answers_table(rows, len(frames)), thumbnails(frames)
293
 
294
 
295
- INTRO = """# SpaceTimeVLM
296
-
297
- Ask a spatial question about a video of a scene: how many objects there are, how far apart two objects are, how
298
- large a room is. SpaceTimeVLM is Qwen3.5 with the frozen geometry encoder of VGGT-1B, read through a 3D-aware
299
- cross-attention, so every visual token has a position in the scene.
300
- Models: [2B](https://huggingface.co/DarioVajda/SpaceTimeVLM-2B),
301
- [4B](https://huggingface.co/DarioVajda/SpaceTimeVLM-4B),
302
- [9B](https://huggingface.co/DarioVajda/SpaceTimeVLM-9B).
303
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  """
305
 
306
- NOTES = """The models are released under CC BY-NC 4.0 (non-commercial use), because of the VGGT-1B weights.
307
- The example video is an excerpt of
308
- [UE4Arch.com - Viennese apartment](https://commons.wikimedia.org/wiki/File:UE4Arch.com_-_Viennese_apartment.webm)
309
- by UE4Arch.com (CC BY-SA 4.0)."""
310
-
311
  with gr.Blocks(title="SpaceTimeVLM") as demo:
312
- gr.Markdown(INTRO)
313
  clip = gr.State(None)
314
- with gr.Row():
315
- with gr.Column():
316
- video = gr.Video(label="Video", sources=["upload"])
317
- status = gr.Markdown()
318
  question = gr.Textbox(label="Question", placeholder="How many chairs are in this room?", lines=2)
319
- model_choice = gr.Radio(list(SIZES) + ([ALL] if len(SIZES) > 1 else []), value=SIZES[0], label="Model")
320
- num_frames = gr.Radio(FRAME_CHOICES, value=32, label="Frames")
 
321
  short_answer = gr.Checkbox(label="Short answer (VSI-Bench prompt)", value=False)
322
- ask = gr.Button("Ask", variant="primary")
323
- with gr.Column():
324
- result = gr.Markdown(label="Answer")
325
- seen = gr.Gallery(label="Frames the model saw", columns=4, height="auto")
326
- gr.Examples(
327
- examples=[[example_video(), "How many chairs are in this room?"],
328
- [example_video(), "What is the size of this room in square meters?"]],
329
- inputs=[video, question], cache_examples=False)
330
- gr.Markdown(NOTES)
 
 
 
331
 
332
  # The GPU steps share one queue, so a question sent while its video is still being prepared waits for it.
333
  gpu = dict(concurrency_id="gpu", concurrency_limit=1)
@@ -348,4 +416,4 @@ with gr.Blocks(title="SpaceTimeVLM") as demo:
348
  question.submit(answer, inputs, [result, seen], api_visibility="private", **gpu)
349
 
350
  if __name__ == "__main__":
351
- demo.launch(mcp_server=True)
 
292
  return answers_table(rows, len(frames)), thumbnails(frames)
293
 
294
 
295
+ # ---- page ----
296
+ MODEL_LINKS = "".join(f'<a href="https://huggingface.co/{REPO.format(s)}" target="_blank">{s}</a>'
297
+ for s in ("2B", "4B", "9B"))
298
+ HEADER = f"""<header id="head">
299
+ <h1>SpaceTimeVLM</h1>
300
+ <p class="lede">Ask a spatial question about a video of a scene: how many objects there are, how far apart two
301
+ objects are, how large a room is.</p>
302
+ <p class="about">SpaceTimeVLM is Qwen3.5 with the frozen geometry encoder of VGGT-1B, read through a 3D-aware
303
+ cross-attention, so every visual token has a position in the scene.</p>
304
+ <p class="models"><span>Models</span>{MODEL_LINKS}</p>
305
+ </header>"""
306
+
307
+ NO_ANSWER_YET = '<p class="empty">Add a video, write a question and press Ask. The answer appears here.</p>'
308
+
309
+ HOW_IT_WORKS = f"""- The video is decoded with ffmpeg, which applies the rotation flag of phone videos. Only the first
310
+ {MAX_VIDEO_SECONDS // 60} minutes are read.
311
+ - 8, 16 or 32 frames are sampled uniformly, as soon as the video is added. These are the frame counts the models
312
+ were trained with, and the frames are shown next to the answer.
313
+ - "Short answer" wraps the question in the VSI-Bench prompt used for the benchmark scores on the model cards."""
314
+
315
+ NOTES = """<footer id="notes">The models are released under CC BY-NC 4.0 (non-commercial use), because of the
316
+ VGGT-1B weights. The example video is an excerpt of
317
+ <a href="https://commons.wikimedia.org/wiki/File:UE4Arch.com_-_Viennese_apartment.webm" target="_blank">UE4Arch.com
318
+ - Viennese apartment</a> by UE4Arch.com (CC BY-SA 4.0).</footer>"""
319
+
320
+ # Plain look: white page, Open Sans, one dark-teal accent, thin borders, no shadows.
321
+ TEAL = gr.themes.Color(c50="#eef4f6", c100="#dbe8ee", c200="#b9d1db", c300="#9cc4d4", c400="#5f8fa1", c500="#3a6f83",
322
+ c600="#27586b", c700="#1b4756", c800="#133844", c900="#0d2a33", c950="#081c22")
323
+ THEME = gr.themes.Base(
324
+ primary_hue=TEAL, neutral_hue="slate", radius_size="sm",
325
+ font=[gr.themes.GoogleFont("Open Sans"), "Helvetica Neue", "Arial", "sans-serif"],
326
+ font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"],
327
+ ).set(
328
+ body_background_fill="white", block_shadow="none", block_shadow_dark="none",
329
+ block_label_background_fill="transparent", block_label_border_width="0px", block_label_text_weight="600",
330
+ block_title_text_weight="600",
331
+ button_primary_background_fill="*primary_800", button_primary_background_fill_hover="*primary_700",
332
+ button_primary_text_color="white", button_primary_shadow="none",
333
+ button_primary_background_fill_dark="*primary_500", button_primary_background_fill_hover_dark="*primary_400",
334
+ checkbox_label_background_fill_selected="*primary_100", checkbox_label_background_fill_selected_dark="*primary_700",
335
+ button_large_text_weight="600",
336
+ )
337
+
338
+ CSS = """
339
+ :root { --st-accent: #133844; }
340
+ .dark { --st-accent: #9cc4d4; }
341
+ .gradio-container { max-width: 1120px !important; margin: 0 auto !important; }
342
+ #head { padding: 20px 0 14px; border-bottom: 3px solid var(--st-accent); margin-bottom: 6px; }
343
+ #head h1 { font-size: 2rem; font-weight: 700; line-height: 1.2; color: var(--st-accent); margin: 0 0 8px; }
344
+ #head p { max-width: 74ch; margin: 0; }
345
+ #head .lede { font-size: 1.05rem; }
346
+ #head .about { color: var(--body-text-color-subdued); font-size: 0.9rem; margin-top: 6px; }
347
+ #head .models { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
348
+ #head .models span { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
349
+ color: var(--body-text-color-subdued); }
350
+ #head .models a { font-size: 0.8rem; font-weight: 600; color: var(--st-accent); text-decoration: none;
351
+ border: 1.5px solid currentColor; border-radius: 999px; padding: 1px 12px; }
352
+ #head .models a:hover { background: var(--st-accent); color: var(--body-background-fill); }
353
+ .flush, .flush .html-container { padding: 0 !important; }
354
+ #status { min-height: 0; }
355
+ #status:not(:has(p)) { display: none; }
356
+ #status p { font-size: 0.85rem; color: var(--body-text-color-subdued); }
357
+ #answer { border-top: 3px solid var(--st-accent); padding: 14px 2px 8px; min-height: 124px; }
358
+ #answer h2 { font-size: 1.9rem; font-weight: 700; line-height: 1.25; color: var(--st-accent); margin: 0 0 8px; }
359
+ #answer p { font-size: 0.85rem; color: var(--body-text-color-subdued); margin: 0; }
360
+ #answer p.empty { font-size: 0.95rem; padding-top: 6px; }
361
+ #answer table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-variant-numeric: tabular-nums; }
362
+ #answer table, #answer tr, #answer th, #answer td { border: 0 !important; background: transparent !important; }
363
+ #answer th, #answer td { padding: 7px 12px 7px 0; text-align: left; }
364
+ #answer thead th { border-top: 1.5px solid var(--body-text-color) !important;
365
+ border-bottom: 1px solid var(--body-text-color) !important;
366
+ font-weight: 600; font-size: 0.85rem; }
367
+ #answer tbody tr:last-child td { border-bottom: 1.5px solid var(--body-text-color) !important; }
368
+ #answer td strong { color: var(--st-accent); font-size: 1.05rem; }
369
+ #answer td:last-child { color: var(--body-text-color-subdued); font-size: 0.85rem; }
370
+ #notes { font-size: 0.8rem; color: var(--body-text-color-subdued); border-top: 1px solid var(--border-color-primary);
371
+ padding-top: 12px; margin-top: 8px; max-width: 96ch; }
372
+ #notes a { color: var(--st-accent); padding: 0; }
373
  """
374
 
 
 
 
 
 
375
  with gr.Blocks(title="SpaceTimeVLM") as demo:
376
+ gr.HTML(HEADER, elem_classes="flush")
377
  clip = gr.State(None)
378
+ with gr.Row(equal_height=False):
379
+ with gr.Column(scale=5):
380
+ video = gr.Video(label="Video", sources=["upload"], height=300)
381
+ status = gr.Markdown(elem_id="status")
382
  question = gr.Textbox(label="Question", placeholder="How many chairs are in this room?", lines=2)
383
+ with gr.Row():
384
+ model_choice = gr.Radio(list(SIZES) + ([ALL] if len(SIZES) > 1 else []), value=SIZES[0], label="Model")
385
+ num_frames = gr.Radio(FRAME_CHOICES, value=32, label="Frames")
386
  short_answer = gr.Checkbox(label="Short answer (VSI-Bench prompt)", value=False)
387
+ ask = gr.Button("Ask", variant="primary", size="lg")
388
+ gr.Examples(
389
+ examples=[[example_video(), "How many chairs are in this room?"],
390
+ [example_video(), "What is the size of this room in square meters?"]],
391
+ example_labels=["How many chairs are in this room?", "What is the size of this room in square meters?"],
392
+ inputs=[video, question], cache_examples=False, label="Or try the example video with a question")
393
+ with gr.Column(scale=6):
394
+ result = gr.Markdown(NO_ANSWER_YET, label="Answer", elem_id="answer")
395
+ seen = gr.Gallery(label="Frames the model saw", columns=4, height="auto", object_fit="cover")
396
+ with gr.Accordion("How it works", open=False):
397
+ gr.Markdown(HOW_IT_WORKS)
398
+ gr.HTML(NOTES, elem_classes="flush")
399
 
400
  # The GPU steps share one queue, so a question sent while its video is still being prepared waits for it.
401
  gpu = dict(concurrency_id="gpu", concurrency_limit=1)
 
416
  question.submit(answer, inputs, [result, seen], api_visibility="private", **gpu)
417
 
418
  if __name__ == "__main__":
419
+ demo.launch(mcp_server=True, theme=THEME, css=CSS) # in Gradio 6 the theme and the CSS are given to launch()