Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
bee8dcd
1
Parent(s):
41a8ca1
update
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import Optional
|
|
| 5 |
import gradio as gr
|
| 6 |
import numpy as np
|
| 7 |
import torch
|
|
|
|
| 8 |
from PIL import Image, ImageDraw
|
| 9 |
|
| 10 |
# Prefer local transformers in the workspace
|
|
@@ -562,9 +563,9 @@ def reset_session() -> tuple[AppState, Image.Image, int, int, str]:
|
|
| 562 |
return GLOBAL_STATE, preview_img, slider_minmax, slider_value, status
|
| 563 |
|
| 564 |
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
) as demo:
|
| 568 |
state = gr.State(GLOBAL_STATE)
|
| 569 |
|
| 570 |
gr.Markdown("""
|
|
@@ -582,7 +583,6 @@ with gr.Blocks(
|
|
| 582 |
ckpt_progress = gr.Markdown(visible=False)
|
| 583 |
load_status = gr.Markdown(visible=True)
|
| 584 |
reset_btn = gr.Button("Reset Session", variant="secondary")
|
| 585 |
-
examples_list = [["./tennis.mp4", "./football.mp4", "./basket.mp4", "./hurdles.mp4"]]
|
| 586 |
with gr.Column(scale=2):
|
| 587 |
preview = gr.Image(label="Preview", interactive=True)
|
| 588 |
frame_slider = gr.Slider(label="Frame", minimum=0, maximum=0, step=1, value=0, interactive=True)
|
|
@@ -596,12 +596,6 @@ with gr.Blocks(
|
|
| 596 |
propagate_btn = gr.Button("Propagate across video", variant="primary")
|
| 597 |
propagate_status = gr.Markdown(visible=True)
|
| 598 |
|
| 599 |
-
# Examples (place before the render MP4 button) — defined after handler below
|
| 600 |
-
|
| 601 |
-
with gr.Row():
|
| 602 |
-
render_btn = gr.Button("Render MP4 for smooth playback")
|
| 603 |
-
playback_video = gr.Video(label="Rendered Playback", interactive=False)
|
| 604 |
-
|
| 605 |
# Wire events
|
| 606 |
def _on_video_change(video):
|
| 607 |
s, min_idx, max_idx, first_frame, status = init_video_session(video)
|
|
@@ -620,6 +614,7 @@ with gr.Blocks(
|
|
| 620 |
)
|
| 621 |
|
| 622 |
# (moved) Examples are defined above the render button
|
|
|
|
| 623 |
gr.Examples(
|
| 624 |
examples=examples_list,
|
| 625 |
inputs=[video_in],
|
|
@@ -629,6 +624,11 @@ with gr.Blocks(
|
|
| 629 |
cache_examples=False,
|
| 630 |
examples_per_page=5,
|
| 631 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
|
| 633 |
def _on_ckpt_change(s: AppState, key: str):
|
| 634 |
if s is not None and key:
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import numpy as np
|
| 7 |
import torch
|
| 8 |
+
from gradio.themes import Soft
|
| 9 |
from PIL import Image, ImageDraw
|
| 10 |
|
| 11 |
# Prefer local transformers in the workspace
|
|
|
|
| 563 |
return GLOBAL_STATE, preview_img, slider_minmax, slider_value, status
|
| 564 |
|
| 565 |
|
| 566 |
+
theme = Soft(primary_hue="blue", secondary_hue="rose", neutral_hue="slate")
|
| 567 |
+
|
| 568 |
+
with gr.Blocks(title="SAM2 Video (Transformers) - Interactive Segmentation", theme=theme) as demo:
|
| 569 |
state = gr.State(GLOBAL_STATE)
|
| 570 |
|
| 571 |
gr.Markdown("""
|
|
|
|
| 583 |
ckpt_progress = gr.Markdown(visible=False)
|
| 584 |
load_status = gr.Markdown(visible=True)
|
| 585 |
reset_btn = gr.Button("Reset Session", variant="secondary")
|
|
|
|
| 586 |
with gr.Column(scale=2):
|
| 587 |
preview = gr.Image(label="Preview", interactive=True)
|
| 588 |
frame_slider = gr.Slider(label="Frame", minimum=0, maximum=0, step=1, value=0, interactive=True)
|
|
|
|
| 596 |
propagate_btn = gr.Button("Propagate across video", variant="primary")
|
| 597 |
propagate_status = gr.Markdown(visible=True)
|
| 598 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
# Wire events
|
| 600 |
def _on_video_change(video):
|
| 601 |
s, min_idx, max_idx, first_frame, status = init_video_session(video)
|
|
|
|
| 614 |
)
|
| 615 |
|
| 616 |
# (moved) Examples are defined above the render button
|
| 617 |
+
examples_list = [["./tennis.mp4"], ["./football.mp4"], ["./basket.mp4"], ["./hurdles.mp4"]]
|
| 618 |
gr.Examples(
|
| 619 |
examples=examples_list,
|
| 620 |
inputs=[video_in],
|
|
|
|
| 624 |
cache_examples=False,
|
| 625 |
examples_per_page=5,
|
| 626 |
)
|
| 627 |
+
# Examples (place before the render MP4 button) — defined after handler below
|
| 628 |
+
|
| 629 |
+
with gr.Row():
|
| 630 |
+
render_btn = gr.Button("Render MP4 for smooth playback", variant="primary")
|
| 631 |
+
playback_video = gr.Video(label="Rendered Playback", interactive=False)
|
| 632 |
|
| 633 |
def _on_ckpt_change(s: AppState, key: str):
|
| 634 |
if s is not None and key:
|