Spaces:
Running on Zero
Running on Zero
Commit Β·
8e42e86
1
Parent(s): c514efb
separate tab for video pointing
Browse files- app.py +52 -18
- example-videos/sports.mp4 +3 -0
- example-videos/travel.mp4 +3 -0
app.py
CHANGED
|
@@ -454,8 +454,10 @@ with gr.Blocks() as demo:
|
|
| 454 |
# ββ LEFT COLUMN: Inputs ββ
|
| 455 |
with gr.Column():
|
| 456 |
with gr.Tabs() as input_tabs:
|
| 457 |
-
with gr.TabItem("Video
|
| 458 |
-
|
|
|
|
|
|
|
| 459 |
with gr.TabItem("Image(s) Pointing", id="image_tab") as image_tab:
|
| 460 |
images_input = gr.Gallery(
|
| 461 |
label="Input Images", elem_id="input_image", type="filepath", height=MAX_IMAGE_SIZE,
|
|
@@ -472,7 +474,7 @@ with gr.Blocks() as demo:
|
|
| 472 |
with gr.Row():
|
| 473 |
submit_button = gr.Button("Submit", variant="primary", scale=3)
|
| 474 |
clear_all_button = gr.ClearButton(
|
| 475 |
-
components=[
|
| 476 |
)
|
| 477 |
|
| 478 |
# ββ RIGHT COLUMN: Outputs ββ
|
|
@@ -499,16 +501,26 @@ with gr.Blocks() as demo:
|
|
| 499 |
output_annotations_img = gr.Gallery(label="Annotated Images", height=MAX_IMAGE_SIZE)
|
| 500 |
|
| 501 |
# ββ Examples ββ
|
| 502 |
-
with gr.Group(visible=True) as
|
| 503 |
-
gr.Markdown("### Video Examples")
|
| 504 |
gr.Examples(
|
| 505 |
examples=[
|
| 506 |
["example-videos/penguins.mp4", "Track all the penguins."],
|
| 507 |
-
# ["example-videos/backflips.mp4", "Count the number of backflips performed in this clip."],
|
| 508 |
["example-videos/arena_basketball.mp4", "Track the players in yellow uniform in 1 fps."],
|
| 509 |
],
|
| 510 |
-
inputs=[
|
| 511 |
-
label="Video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
)
|
| 513 |
|
| 514 |
with gr.Group(visible=False) as image_examples_group:
|
|
@@ -523,12 +535,26 @@ with gr.Blocks() as demo:
|
|
| 523 |
)
|
| 524 |
|
| 525 |
# ββ Tab switching: toggle visibility + track active tab ββ
|
| 526 |
-
active_tab = gr.State("
|
| 527 |
|
| 528 |
-
def
|
| 529 |
return (
|
| 530 |
-
"
|
| 531 |
-
gr.update(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
gr.update(visible=False), # image_examples_group
|
| 533 |
gr.update(visible=True), # video_params_row
|
| 534 |
gr.update(visible=True), # video_output_tabs
|
|
@@ -538,15 +564,22 @@ with gr.Blocks() as demo:
|
|
| 538 |
def _select_image_tab():
|
| 539 |
return (
|
| 540 |
"image",
|
| 541 |
-
gr.update(
|
|
|
|
|
|
|
| 542 |
gr.update(visible=True), # image_examples_group
|
| 543 |
gr.update(visible=False), # video_params_row
|
| 544 |
gr.update(visible=False), # video_output_tabs
|
| 545 |
gr.update(visible=True), # image_output_group
|
| 546 |
)
|
| 547 |
|
| 548 |
-
tab_outputs = [
|
| 549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
image_tab.select(fn=_select_image_tab, outputs=tab_outputs)
|
| 551 |
|
| 552 |
_WARNING_STYLE = (
|
|
@@ -566,12 +599,13 @@ with gr.Blocks() as demo:
|
|
| 566 |
return gr.update(value=html, visible=True)
|
| 567 |
return gr.update(value="", visible=False)
|
| 568 |
|
| 569 |
-
def dispatch_submit(tab, user_text,
|
| 570 |
-
fsm, mf, mfps, max_tok):
|
| 571 |
if tab == "image":
|
| 572 |
text_out, img_gallery, pts = process_images(user_text, input_images, max_tok)
|
| 573 |
return text_out, pts, gr.update(value="", visible=False), None, [], img_gallery
|
| 574 |
else:
|
|
|
|
| 575 |
text_out, ann_video, ann_frames, pts = process_video(
|
| 576 |
user_text, video_path, fsm, mf, mfps, max_tok,
|
| 577 |
)
|
|
@@ -580,7 +614,7 @@ with gr.Blocks() as demo:
|
|
| 580 |
|
| 581 |
submit_button.click(
|
| 582 |
fn=dispatch_submit,
|
| 583 |
-
inputs=[active_tab, input_text,
|
| 584 |
frame_sample_mode, max_frames, max_fps, max_tok_slider],
|
| 585 |
outputs=[output_text, output_points, output_warning, output_video, output_annotations, output_annotations_img],
|
| 586 |
)
|
|
|
|
| 454 |
# ββ LEFT COLUMN: Inputs ββ
|
| 455 |
with gr.Column():
|
| 456 |
with gr.Tabs() as input_tabs:
|
| 457 |
+
with gr.TabItem("Video Tracking", id="video_tracking_tab") as video_tracking_tab:
|
| 458 |
+
video_tracking = gr.Video(label="Input Video", elem_id="input_video", height=MAX_VIDEO_HEIGHT)
|
| 459 |
+
with gr.TabItem("Video Pointing", id="video_pointing_tab") as video_pointing_tab:
|
| 460 |
+
video_pointing = gr.Video(label="Input Video", elem_id="input_video_pointing", height=MAX_VIDEO_HEIGHT)
|
| 461 |
with gr.TabItem("Image(s) Pointing", id="image_tab") as image_tab:
|
| 462 |
images_input = gr.Gallery(
|
| 463 |
label="Input Images", elem_id="input_image", type="filepath", height=MAX_IMAGE_SIZE,
|
|
|
|
| 474 |
with gr.Row():
|
| 475 |
submit_button = gr.Button("Submit", variant="primary", scale=3)
|
| 476 |
clear_all_button = gr.ClearButton(
|
| 477 |
+
components=[video_tracking, video_pointing, images_input, input_text], value="Clear All", scale=1,
|
| 478 |
)
|
| 479 |
|
| 480 |
# ββ RIGHT COLUMN: Outputs ββ
|
|
|
|
| 501 |
output_annotations_img = gr.Gallery(label="Annotated Images", height=MAX_IMAGE_SIZE)
|
| 502 |
|
| 503 |
# ββ Examples ββ
|
| 504 |
+
with gr.Group(visible=True) as video_tracking_examples_group:
|
| 505 |
+
gr.Markdown("### Video Tracking Examples")
|
| 506 |
gr.Examples(
|
| 507 |
examples=[
|
| 508 |
["example-videos/penguins.mp4", "Track all the penguins."],
|
|
|
|
| 509 |
["example-videos/arena_basketball.mp4", "Track the players in yellow uniform in 1 fps."],
|
| 510 |
],
|
| 511 |
+
inputs=[video_tracking, input_text],
|
| 512 |
+
label="Video Tracking Examples",
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
with gr.Group(visible=False) as video_pointing_examples_group:
|
| 516 |
+
gr.Markdown("### Video Pointing Examples")
|
| 517 |
+
gr.Examples(
|
| 518 |
+
examples=[
|
| 519 |
+
["example-videos/sports.mp4", "Point to players in white/blue jersey"],
|
| 520 |
+
["example-videos/travel.mp4", "Point to standalone spiky towers"],
|
| 521 |
+
],
|
| 522 |
+
inputs=[video_pointing, input_text],
|
| 523 |
+
label="Video Pointing Examples",
|
| 524 |
)
|
| 525 |
|
| 526 |
with gr.Group(visible=False) as image_examples_group:
|
|
|
|
| 535 |
)
|
| 536 |
|
| 537 |
# ββ Tab switching: toggle visibility + track active tab ββ
|
| 538 |
+
active_tab = gr.State("video_tracking")
|
| 539 |
|
| 540 |
+
def _select_video_tracking_tab():
|
| 541 |
return (
|
| 542 |
+
"video_tracking",
|
| 543 |
+
gr.update(value=10), # max_fps
|
| 544 |
+
gr.update(visible=True), # video_tracking_examples_group
|
| 545 |
+
gr.update(visible=False), # video_pointing_examples_group
|
| 546 |
+
gr.update(visible=False), # image_examples_group
|
| 547 |
+
gr.update(visible=True), # video_params_row
|
| 548 |
+
gr.update(visible=True), # video_output_tabs
|
| 549 |
+
gr.update(visible=False), # image_output_group
|
| 550 |
+
)
|
| 551 |
+
|
| 552 |
+
def _select_video_pointing_tab():
|
| 553 |
+
return (
|
| 554 |
+
"video_pointing",
|
| 555 |
+
gr.update(value=2), # max_fps
|
| 556 |
+
gr.update(visible=False), # video_tracking_examples_group
|
| 557 |
+
gr.update(visible=True), # video_pointing_examples_group
|
| 558 |
gr.update(visible=False), # image_examples_group
|
| 559 |
gr.update(visible=True), # video_params_row
|
| 560 |
gr.update(visible=True), # video_output_tabs
|
|
|
|
| 564 |
def _select_image_tab():
|
| 565 |
return (
|
| 566 |
"image",
|
| 567 |
+
gr.update(), # max_fps unchanged
|
| 568 |
+
gr.update(visible=False), # video_tracking_examples_group
|
| 569 |
+
gr.update(visible=False), # video_pointing_examples_group
|
| 570 |
gr.update(visible=True), # image_examples_group
|
| 571 |
gr.update(visible=False), # video_params_row
|
| 572 |
gr.update(visible=False), # video_output_tabs
|
| 573 |
gr.update(visible=True), # image_output_group
|
| 574 |
)
|
| 575 |
|
| 576 |
+
tab_outputs = [
|
| 577 |
+
active_tab, max_fps,
|
| 578 |
+
video_tracking_examples_group, video_pointing_examples_group, image_examples_group,
|
| 579 |
+
video_params_row, video_output_tabs, image_output_group,
|
| 580 |
+
]
|
| 581 |
+
video_tracking_tab.select(fn=_select_video_tracking_tab, outputs=tab_outputs)
|
| 582 |
+
video_pointing_tab.select(fn=_select_video_pointing_tab, outputs=tab_outputs)
|
| 583 |
image_tab.select(fn=_select_image_tab, outputs=tab_outputs)
|
| 584 |
|
| 585 |
_WARNING_STYLE = (
|
|
|
|
| 599 |
return gr.update(value=html, visible=True)
|
| 600 |
return gr.update(value="", visible=False)
|
| 601 |
|
| 602 |
+
def dispatch_submit(tab, user_text, video_tracking_path, video_pointing_path,
|
| 603 |
+
input_images, fsm, mf, mfps, max_tok):
|
| 604 |
if tab == "image":
|
| 605 |
text_out, img_gallery, pts = process_images(user_text, input_images, max_tok)
|
| 606 |
return text_out, pts, gr.update(value="", visible=False), None, [], img_gallery
|
| 607 |
else:
|
| 608 |
+
video_path = video_tracking_path if tab == "video_tracking" else video_pointing_path
|
| 609 |
text_out, ann_video, ann_frames, pts = process_video(
|
| 610 |
user_text, video_path, fsm, mf, mfps, max_tok,
|
| 611 |
)
|
|
|
|
| 614 |
|
| 615 |
submit_button.click(
|
| 616 |
fn=dispatch_submit,
|
| 617 |
+
inputs=[active_tab, input_text, video_tracking, video_pointing, images_input,
|
| 618 |
frame_sample_mode, max_frames, max_fps, max_tok_slider],
|
| 619 |
outputs=[output_text, output_points, output_warning, output_video, output_annotations, output_annotations_img],
|
| 620 |
)
|
example-videos/sports.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:74dac8c7df7403f7e349c2b4037b117c4c7520edb9501e295665216d02e1ea6e
|
| 3 |
+
size 6238226
|
example-videos/travel.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:53e9cf8094d252dba4abdcf922dca79f1b0c454cc8fa18c0005e62068ddfa8bc
|
| 3 |
+
size 9435014
|