Spaces:
Running
on
Zero
Running
on
Zero
Change video downsampling logic to avoid CUDA OOM
Browse files
app.py
CHANGED
@@ -62,7 +62,6 @@ def validate_media_constraints(message: dict, history: list[dict]) -> bool:
|
|
62 |
if "<image>" in message["text"]:
|
63 |
gr.Warning("Using <image> tags with video files is not supported.")
|
64 |
return False
|
65 |
-
# TODO: Add frame count validation for videos similar to image count limits # noqa: FIX002, TD002, TD003
|
66 |
if video_count == 0 and image_count > MAX_NUM_IMAGES:
|
67 |
gr.Warning(f"You can upload up to {MAX_NUM_IMAGES} images.")
|
68 |
return False
|
@@ -77,10 +76,13 @@ def downsample_video(video_path: str) -> list[tuple[Image.Image, float]]:
|
|
77 |
fps = vidcap.get(cv2.CAP_PROP_FPS)
|
78 |
total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
|
79 |
|
80 |
-
frame_interval =
|
81 |
-
frames = []
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
for i in range(0, total_frames, frame_interval):
|
84 |
vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
85 |
success, image = vidcap.read()
|
86 |
if success:
|
|
|
62 |
if "<image>" in message["text"]:
|
63 |
gr.Warning("Using <image> tags with video files is not supported.")
|
64 |
return False
|
|
|
65 |
if video_count == 0 and image_count > MAX_NUM_IMAGES:
|
66 |
gr.Warning(f"You can upload up to {MAX_NUM_IMAGES} images.")
|
67 |
return False
|
|
|
76 |
fps = vidcap.get(cv2.CAP_PROP_FPS)
|
77 |
total_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
|
78 |
|
79 |
+
frame_interval = max(total_frames // MAX_NUM_IMAGES, 1)
|
80 |
+
frames: list[tuple[Image.Image, float]] = []
|
81 |
+
|
82 |
+
for i in range(0, min(total_frames, MAX_NUM_IMAGES * frame_interval), frame_interval):
|
83 |
+
if len(frames) >= MAX_NUM_IMAGES:
|
84 |
+
break
|
85 |
|
|
|
86 |
vidcap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
87 |
success, image = vidcap.read()
|
88 |
if success:
|