John Ho commited on
Commit
cfd2182
·
1 Parent(s): ff0753c

added timeout option

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -1,7 +1,7 @@
1
  # Import helpers for mask encoding and bbox extraction
 
2
  import sys
3
  import tempfile
4
- from ast import Return
5
 
6
  import cv2
7
  import gradio as gr
@@ -130,9 +130,21 @@ def frames_to_vid(pil_frames, output_path: str, vid_fps: int, vid_w: int, vid_h:
130
  return output_path
131
 
132
 
 
 
 
 
 
 
 
133
  # Our Inference Function
134
- @spaces.GPU(duration=120)
135
- def video_inference(input_video, prompt: str, annotation_mode: bool = False):
 
 
 
 
 
136
  """
137
  Segments objects in a video using a text prompt.
138
  Returns a list of detection dicts (one per object per frame) and output video path/status.
@@ -230,8 +242,10 @@ def video_inference(input_video, prompt: str, annotation_mode: bool = False):
230
  )
231
 
232
 
233
- def video_annotation(input_video, prompt: str):
234
- return video_inference(input_video, prompt, annotation_mode=True)
 
 
235
 
236
 
237
  # the Gradio App
@@ -247,6 +261,7 @@ with gr.Blocks() as app:
247
  info="Describe the Object(s) you would like to track/ segmentate",
248
  value="",
249
  ),
 
250
  ],
251
  outputs=gr.JSON(label="Output JSON"),
252
  title="SAM3 Video Segmentation",
@@ -264,6 +279,7 @@ with gr.Blocks() as app:
264
  info="Describe the Object(s) you would like to track/ segmentate",
265
  value="",
266
  ),
 
267
  ],
268
  outputs=gr.Video(label="Processed Video"),
269
  title="SAM3 Video Segmentation",
 
1
  # Import helpers for mask encoding and bbox extraction
2
+ import inspect
3
  import sys
4
  import tempfile
 
5
 
6
  import cv2
7
  import gradio as gr
 
130
  return output_path
131
 
132
 
133
+ def calc_timeout_duration(vid_file, *args):
134
+ sig = inspect.signature(video_inference)
135
+ bound = sig.bind(vid_file, *args)
136
+ bound.apply_defaults()
137
+ return bound.arguments.get("timeout_duration", 60)
138
+
139
+
140
  # Our Inference Function
141
+ @spaces.GPU(duration=calc_timeout_duration)
142
+ def video_inference(
143
+ input_video,
144
+ prompt: str,
145
+ timeout_duration: int = 60,
146
+ annotation_mode: bool = False,
147
+ ):
148
  """
149
  Segments objects in a video using a text prompt.
150
  Returns a list of detection dicts (one per object per frame) and output video path/status.
 
242
  )
243
 
244
 
245
+ def video_annotation(input_video, prompt: str, timeout_duration: int = 60):
246
+ return video_inference(
247
+ input_video, prompt, timeout_duration=timeout_duration, annotation_mode=True
248
+ )
249
 
250
 
251
  # the Gradio App
 
261
  info="Describe the Object(s) you would like to track/ segmentate",
262
  value="",
263
  ),
264
+ gr.Radio([60, 120, 180, 240], value=60, label="Timeout (seconds)"),
265
  ],
266
  outputs=gr.JSON(label="Output JSON"),
267
  title="SAM3 Video Segmentation",
 
279
  info="Describe the Object(s) you would like to track/ segmentate",
280
  value="",
281
  ),
282
+ gr.Radio([60, 120, 180, 240], value=60, label="Timeout (seconds)"),
283
  ],
284
  outputs=gr.Video(label="Processed Video"),
285
  title="SAM3 Video Segmentation",