sming256 commited on
Commit
ea89991
·
verified ·
1 Parent(s): 6983b5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -464,7 +464,7 @@ EXAMPLES = [
464
  demo = gr.Blocks(title="VideoAuto-R1 Demo")
465
 
466
  with demo:
467
- gr.Markdown("# VideoAuto-R1 (Qwen3-VL-8B) Demo")
468
 
469
  # Display system prompt
470
  with gr.Accordion("System Prompt", open=False):
@@ -586,11 +586,54 @@ with demo:
586
  outputs=[chatbot],
587
  )
588
 
589
- gr.Examples(
590
- examples=EXAMPLES,
591
- inputs=[media_input, textbox],
592
  label="Examples",
593
- cache_examples=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594
  )
595
 
596
 
 
464
  demo = gr.Blocks(title="VideoAuto-R1 Demo")
465
 
466
  with demo:
467
+ gr.Markdown("# [VideoAuto-R1: Video Auto Reasoning via Thinking Once, Answering Twice](https://github.com/IVUL-KAUST/VideoAuto-R1/)")
468
 
469
  # Display system prompt
470
  with gr.Accordion("System Prompt", open=False):
 
586
  outputs=[chatbot],
587
  )
588
 
589
+ examples_ds = gr.Dataset(
590
+ components=[media_input, textbox],
591
+ samples=EXAMPLES,
592
  label="Examples",
593
+ type="index", # important: pass selected row index to fn
594
+ )
595
+
596
+ def load_example(idx: int | None):
597
+ # idx can be None when deselecting
598
+ if idx is None:
599
+ # just clear everything
600
+ return clear_history()
601
+
602
+ media, text = EXAMPLES[idx][0], EXAMPLES[idx][1]
603
+
604
+ # 1) clear all states + re-enable inputs
605
+ ms, cs, last, file_u, img_u, vid_u, tb_u, send_u = clear_history()
606
+
607
+ # 2) set selected example values
608
+ file_u = gr.update(value=media)
609
+ tb_u = gr.update(value=text, interactive=True)
610
+ send_u = gr.update(interactive=True)
611
+
612
+ # 3) update preview explicitly (don't rely on File.change always firing)
613
+ img_u, vid_u = update_preview(media)
614
+
615
+ # 4) optionally set last_media_state to current media
616
+ last = media
617
+
618
+ return ms, cs, last, file_u, img_u, vid_u, tb_u, send_u
619
+
620
+ examples_ds.select(
621
+ fn=load_example,
622
+ inputs=[examples_ds],
623
+ outputs=[
624
+ messages_state,
625
+ chatbot_state,
626
+ last_media_state,
627
+ media_input,
628
+ image_preview,
629
+ video_preview,
630
+ textbox,
631
+ send_btn,
632
+ ],
633
+ ).then(
634
+ fn=lambda cs: cs,
635
+ inputs=[chatbot_state],
636
+ outputs=[chatbot],
637
  )
638
 
639