fffiloni commited on
Commit
fbb77f2
1 Parent(s): 28dd534

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -27,6 +27,8 @@ import matplotlib.pyplot as plt
27
  from PIL import Image, ImageFilter
28
  from sam2.build_sam import build_sam2_video_predictor
29
 
 
 
30
  def preprocess_image(image):
31
  return image, gr.State([]), gr.State([]), image, gr.State()
32
 
@@ -303,10 +305,18 @@ def propagate_to_all(checkpoint, stored_inference_state, stored_frame_names, vid
303
  # Close the plot
304
  plt.close()
305
 
 
 
306
  if vis_frame_type == "check":
307
  return gr.update(value=jpeg_images, visible=True), gr.update(visible=False, value=None)
308
  elif vis_frame_type == "render":
309
- return gr.update(visible=False, value=None), gr.update(value=final_vid, visible=True)
 
 
 
 
 
 
310
 
311
 
312
  with gr.Blocks() as demo:
 
27
  from PIL import Image, ImageFilter
28
  from sam2.build_sam import build_sam2_video_predictor
29
 
30
+ from moviepy.editor import ImageSequenceClip
31
+
32
  def preprocess_image(image):
33
  return image, gr.State([]), gr.State([]), image, gr.State()
34
 
 
305
  # Close the plot
306
  plt.close()
307
 
308
+
309
+
310
  if vis_frame_type == "check":
311
  return gr.update(value=jpeg_images, visible=True), gr.update(visible=False, value=None)
312
  elif vis_frame_type == "render":
313
+ # Create a video clip from the image sequence
314
+ fps = 24 # Frames per second
315
+ clip = ImageSequenceClip(jpeg_images, fps=fps)
316
+ # Write the result to a file
317
+ final_vid_output_path = "output_video.mp4"
318
+ video.write_videofile(output_path, codec='libx264')
319
+ return gr.update(visible=False, value=None), gr.update(value=final_vid_output_path, visible=True)
320
 
321
 
322
  with gr.Blocks() as demo: