Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,8 +28,6 @@ from PIL import Image, ImageFilter
|
|
28 |
from sam2.build_sam import build_sam2_video_predictor
|
29 |
|
30 |
from moviepy.editor import ImageSequenceClip
|
31 |
-
from tqdm import tqdm
|
32 |
-
import re
|
33 |
|
34 |
def get_video_fps(video_path):
|
35 |
# Open the video file
|
@@ -317,13 +315,13 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
317 |
# Define the output filename and save the figure as a JPEG file
|
318 |
output_filename = os.path.join(frames_output_dir, f"frame_{out_frame_idx}.jpg")
|
319 |
plt.savefig(output_filename, format='jpg')
|
320 |
-
|
321 |
-
# Append the file path to the list
|
322 |
-
jpeg_images.append(output_filename)
|
323 |
|
324 |
# Close the plot
|
325 |
plt.close()
|
326 |
|
|
|
|
|
|
|
327 |
|
328 |
|
329 |
if vis_frame_type == "check":
|
@@ -337,30 +335,12 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
337 |
# Write the result to a file
|
338 |
final_vid_output_path = "output_video.mp4"
|
339 |
|
340 |
-
# Initialize the tqdm progress bar with the total number of frames
|
341 |
-
pbar = tqdm(total=total_frames, desc="Rendering video")
|
342 |
-
|
343 |
-
# Define a function to update the progress bar
|
344 |
-
def update_progress(txt):
|
345 |
-
# Extract progress from the log message
|
346 |
-
progress_match = re.search(r"frame\s+(\d+)", txt)
|
347 |
-
if progress_match:
|
348 |
-
current_frame = int(progress_match.group(1))
|
349 |
-
pbar.n = current_frame
|
350 |
-
pbar.refresh()
|
351 |
-
|
352 |
# Write the result to a file
|
353 |
clip.write_videofile(
|
354 |
final_vid_output_path,
|
355 |
-
codec='libx264'
|
356 |
-
logger=lambda txt: update_progress(txt)
|
357 |
)
|
358 |
|
359 |
-
# Close the progress bar after the process is finished
|
360 |
-
pbar.close()
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
365 |
|
366 |
def update_ui(vis_frame_type):
|
|
|
28 |
from sam2.build_sam import build_sam2_video_predictor
|
29 |
|
30 |
from moviepy.editor import ImageSequenceClip
|
|
|
|
|
31 |
|
32 |
def get_video_fps(video_path):
|
33 |
# Open the video file
|
|
|
315 |
# Define the output filename and save the figure as a JPEG file
|
316 |
output_filename = os.path.join(frames_output_dir, f"frame_{out_frame_idx}.jpg")
|
317 |
plt.savefig(output_filename, format='jpg')
|
|
|
|
|
|
|
318 |
|
319 |
# Close the plot
|
320 |
plt.close()
|
321 |
|
322 |
+
# Append the file path to the list
|
323 |
+
jpeg_images.append(output_filename)
|
324 |
+
|
325 |
|
326 |
|
327 |
if vis_frame_type == "check":
|
|
|
335 |
# Write the result to a file
|
336 |
final_vid_output_path = "output_video.mp4"
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
# Write the result to a file
|
339 |
clip.write_videofile(
|
340 |
final_vid_output_path,
|
341 |
+
codec='libx264'
|
|
|
342 |
)
|
343 |
|
|
|
|
|
|
|
|
|
|
|
344 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
345 |
|
346 |
def update_ui(vis_frame_type):
|