fffiloni commited on
Commit
d3fed5a
·
verified ·
1 Parent(s): fe98ed4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -52,7 +52,7 @@ def preprocess_video_in(video_path):
52
  cap.release()
53
 
54
  # 'image' is the first frame extracted from video_in
55
- return first_frame, gr.State([]), gr.State([]), first_frame, first_frame
56
 
57
  def get_point(point_type, tracking_points, trackings_input_label, first_frame_path, evt: gr.SelectData):
58
  print(f"You selected {evt.value} at {evt.index} from {evt.target}")
@@ -167,7 +167,7 @@ def show_masks(image, masks, scores, point_coords=None, box_coords=None, input_l
167
  return combined_images, mask_images
168
 
169
 
170
- def sam_process(input_first_frame_image, checkpoint, tracking_points, trackings_input_label):
171
  # 1. We need to preprocess the video and store frames in the right directory
172
  # — Penser à utiliser un ID unique pour le dossier
173
 
@@ -190,7 +190,8 @@ def sam_process(input_first_frame_image, checkpoint, tracking_points, trackings_
190
 
191
 
192
  # `video_dir` a directory of JPEG frames with filenames like `<frame_index>.jpg`
193
- video_dir = "./videos/bedroom"
 
194
 
195
  # scan all the JPEG frame names in this directory
196
  frame_names = [
@@ -279,6 +280,7 @@ with gr.Blocks() as demo:
279
  first_frame_path = gr.State()
280
  tracking_points = gr.State([])
281
  trackings_input_label = gr.State([])
 
282
  with gr.Column():
283
  gr.Markdown("# SAM2 Video Predictor")
284
  gr.Markdown("This is a simple demo for video segmentation with SAM2.")
@@ -317,7 +319,7 @@ with gr.Blocks() as demo:
317
  video_in.upload(
318
  fn = preprocess_video_in,
319
  inputs = [video_in],
320
- outputs = [first_frame_path, tracking_points, trackings_input_label, input_first_frame_image, points_map],
321
  queue = False
322
  )
323
 
@@ -330,7 +332,7 @@ with gr.Blocks() as demo:
330
 
331
  submit_btn.click(
332
  fn = sam_process,
333
- inputs = [input_first_frame_image, checkpoint, tracking_points, trackings_input_label],
334
  outputs = [output_result]
335
  )
336
 
 
52
  cap.release()
53
 
54
  # 'image' is the first frame extracted from video_in
55
+ return first_frame, gr.State([]), gr.State([]), first_frame, first_frame, output_dir
56
 
57
  def get_point(point_type, tracking_points, trackings_input_label, first_frame_path, evt: gr.SelectData):
58
  print(f"You selected {evt.value} at {evt.index} from {evt.target}")
 
167
  return combined_images, mask_images
168
 
169
 
170
+ def sam_process(input_first_frame_image, checkpoint, tracking_points, trackings_input_label, frames_output_dir):
171
  # 1. We need to preprocess the video and store frames in the right directory
172
  # — Penser à utiliser un ID unique pour le dossier
173
 
 
190
 
191
 
192
  # `video_dir` a directory of JPEG frames with filenames like `<frame_index>.jpg`
193
+ print(f"STATE FRAME OUTPUT DIRECTORY: {frames_output_dir.value}")
194
+ video_dir = frames_output_dir.value
195
 
196
  # scan all the JPEG frame names in this directory
197
  frame_names = [
 
280
  first_frame_path = gr.State()
281
  tracking_points = gr.State([])
282
  trackings_input_label = gr.State([])
283
+ frames_output_dir = gr.State()
284
  with gr.Column():
285
  gr.Markdown("# SAM2 Video Predictor")
286
  gr.Markdown("This is a simple demo for video segmentation with SAM2.")
 
319
  video_in.upload(
320
  fn = preprocess_video_in,
321
  inputs = [video_in],
322
+ outputs = [first_frame_path, tracking_points, trackings_input_label, input_first_frame_image, points_map, frames_output_dir],
323
  queue = False
324
  )
325
 
 
332
 
333
  submit_btn.click(
334
  fn = sam_process,
335
+ inputs = [input_first_frame_image, checkpoint, tracking_points, trackings_input_label, frames_output_dir],
336
  outputs = [output_result]
337
  )
338