Spaces:
Running
on
Zero
Running
on
Zero
Fix type annotation
Browse files
app.py
CHANGED
|
@@ -129,7 +129,7 @@ class AppState:
|
|
| 129 |
|
| 130 |
|
| 131 |
def init_video_session(
|
| 132 |
-
GLOBAL_STATE:
|
| 133 |
) -> tuple[AppState, int, int, Image.Image, str]:
|
| 134 |
GLOBAL_STATE.video_frames = []
|
| 135 |
GLOBAL_STATE.masks_by_frame = {}
|
|
@@ -596,7 +596,7 @@ def _get_active_prompts_display(state: AppState) -> str:
|
|
| 596 |
return "**Active prompts:** None"
|
| 597 |
|
| 598 |
|
| 599 |
-
def propagate_masks(GLOBAL_STATE:
|
| 600 |
if GLOBAL_STATE is None:
|
| 601 |
return GLOBAL_STATE, "Load a video first.", gr.update()
|
| 602 |
|
|
@@ -743,7 +743,7 @@ def propagate_masks(GLOBAL_STATE: gr.State) -> Iterator[tuple[AppState, str, dic
|
|
| 743 |
yield GLOBAL_STATE, text, gr.update(value=last_frame_idx)
|
| 744 |
|
| 745 |
|
| 746 |
-
def reset_prompts(GLOBAL_STATE:
|
| 747 |
"""Reset prompts and all outputs, but keep processed frames and cached vision features."""
|
| 748 |
if GLOBAL_STATE is None or GLOBAL_STATE.inference_session is None:
|
| 749 |
active_prompts = _get_active_prompts_display(GLOBAL_STATE)
|
|
@@ -810,7 +810,7 @@ def reset_prompts(GLOBAL_STATE: gr.State) -> tuple[AppState, Image.Image, str, s
|
|
| 810 |
return GLOBAL_STATE, preview_img, status, active_prompts
|
| 811 |
|
| 812 |
|
| 813 |
-
def reset_session(GLOBAL_STATE:
|
| 814 |
if not GLOBAL_STATE.video_frames:
|
| 815 |
return GLOBAL_STATE, None, 0, 0, "Session reset. Load a new video.", "**Active prompts:** None"
|
| 816 |
|
|
@@ -862,7 +862,7 @@ def reset_session(GLOBAL_STATE: gr.State) -> tuple[AppState, Image.Image, int, i
|
|
| 862 |
return GLOBAL_STATE, preview_img, slider_minmax, slider_value, status, active_prompts
|
| 863 |
|
| 864 |
|
| 865 |
-
def _on_video_change_pointbox(GLOBAL_STATE:
|
| 866 |
GLOBAL_STATE, min_idx, max_idx, first_frame, status = init_video_session(GLOBAL_STATE, video, "point_box")
|
| 867 |
return (
|
| 868 |
GLOBAL_STATE,
|
|
@@ -872,7 +872,7 @@ def _on_video_change_pointbox(GLOBAL_STATE: gr.State, video: str | dict) -> tupl
|
|
| 872 |
)
|
| 873 |
|
| 874 |
|
| 875 |
-
def _on_video_change_text(GLOBAL_STATE:
|
| 876 |
GLOBAL_STATE, min_idx, max_idx, first_frame, status = init_video_session(GLOBAL_STATE, video, "text")
|
| 877 |
active_prompts = _get_active_prompts_display(GLOBAL_STATE)
|
| 878 |
return (
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
def init_video_session(
|
| 132 |
+
GLOBAL_STATE: AppState, video: str | dict, active_tab: str = "point_box"
|
| 133 |
) -> tuple[AppState, int, int, Image.Image, str]:
|
| 134 |
GLOBAL_STATE.video_frames = []
|
| 135 |
GLOBAL_STATE.masks_by_frame = {}
|
|
|
|
| 596 |
return "**Active prompts:** None"
|
| 597 |
|
| 598 |
|
| 599 |
+
def propagate_masks(GLOBAL_STATE: AppState) -> Iterator[tuple[AppState, str, dict]]:
|
| 600 |
if GLOBAL_STATE is None:
|
| 601 |
return GLOBAL_STATE, "Load a video first.", gr.update()
|
| 602 |
|
|
|
|
| 743 |
yield GLOBAL_STATE, text, gr.update(value=last_frame_idx)
|
| 744 |
|
| 745 |
|
| 746 |
+
def reset_prompts(GLOBAL_STATE: AppState) -> tuple[AppState, Image.Image, str, str]:
|
| 747 |
"""Reset prompts and all outputs, but keep processed frames and cached vision features."""
|
| 748 |
if GLOBAL_STATE is None or GLOBAL_STATE.inference_session is None:
|
| 749 |
active_prompts = _get_active_prompts_display(GLOBAL_STATE)
|
|
|
|
| 810 |
return GLOBAL_STATE, preview_img, status, active_prompts
|
| 811 |
|
| 812 |
|
| 813 |
+
def reset_session(GLOBAL_STATE: AppState) -> tuple[AppState, Image.Image, int, int, str, str]:
|
| 814 |
if not GLOBAL_STATE.video_frames:
|
| 815 |
return GLOBAL_STATE, None, 0, 0, "Session reset. Load a new video.", "**Active prompts:** None"
|
| 816 |
|
|
|
|
| 862 |
return GLOBAL_STATE, preview_img, slider_minmax, slider_value, status, active_prompts
|
| 863 |
|
| 864 |
|
| 865 |
+
def _on_video_change_pointbox(GLOBAL_STATE: AppState, video: str | dict) -> tuple[AppState, dict, Image.Image, str]:
|
| 866 |
GLOBAL_STATE, min_idx, max_idx, first_frame, status = init_video_session(GLOBAL_STATE, video, "point_box")
|
| 867 |
return (
|
| 868 |
GLOBAL_STATE,
|
|
|
|
| 872 |
)
|
| 873 |
|
| 874 |
|
| 875 |
+
def _on_video_change_text(GLOBAL_STATE: AppState, video: str | dict) -> tuple[AppState, dict, Image.Image, str, str]:
|
| 876 |
GLOBAL_STATE, min_idx, max_idx, first_frame, status = init_video_session(GLOBAL_STATE, video, "text")
|
| 877 |
active_prompts = _get_active_prompts_display(GLOBAL_STATE)
|
| 878 |
return (
|