Spaces:
Running on Zero
Running on Zero
AndrianBalanescu commited on
Commit ·
b6e7009
1
Parent(s): 3222c30
fix(zerogpu-video): replace opencv export_to_video with PIL + ffmpeg
Browse filesdiffusers export_to_video fails with 'export_to_video requires the OpenCV
library but it was not found in your environment'. Replacing with PIL PNG
frame dump + standard system ffmpeg subprocess, avoiding missing opencv
dependency on ZeroGPU container.
app.py
CHANGED
|
@@ -1271,7 +1271,6 @@ def generate_zerogpu_video(
|
|
| 1271 |
try:
|
| 1272 |
import torch
|
| 1273 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 1274 |
-
from diffusers.utils import export_to_video
|
| 1275 |
|
| 1276 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 1277 |
dtype = torch.float16 if device == "cuda" else torch.float32
|
|
@@ -1303,7 +1302,27 @@ def generate_zerogpu_video(
|
|
| 1303 |
generator=generator
|
| 1304 |
).frames[0]
|
| 1305 |
|
| 1306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1307 |
return out_video_path
|
| 1308 |
except Exception as exc:
|
| 1309 |
print(f"[ZeroGPU Video] Direct pipeline exception: {exc}, running ffmpeg dynamic visualizer fallback...", flush=True)
|
|
|
|
| 1271 |
try:
|
| 1272 |
import torch
|
| 1273 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
|
|
|
| 1274 |
|
| 1275 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 1276 |
dtype = torch.float16 if device == "cuda" else torch.float32
|
|
|
|
| 1302 |
generator=generator
|
| 1303 |
).frames[0]
|
| 1304 |
|
| 1305 |
+
import numpy as np
|
| 1306 |
+
from PIL import Image
|
| 1307 |
+
|
| 1308 |
+
ffmpeg_bin = shutil.which("ffmpeg") or "/usr/bin/ffmpeg"
|
| 1309 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 1310 |
+
for idx, frame in enumerate(video_frames):
|
| 1311 |
+
if isinstance(frame, np.ndarray):
|
| 1312 |
+
img = Image.fromarray(frame)
|
| 1313 |
+
else:
|
| 1314 |
+
img = frame
|
| 1315 |
+
img.save(os.path.join(tmpdir, f"frame_{idx:05d}.png"))
|
| 1316 |
+
subprocess.run(
|
| 1317 |
+
[
|
| 1318 |
+
ffmpeg_bin, "-y", "-framerate", str(int(fps)),
|
| 1319 |
+
"-i", os.path.join(tmpdir, "frame_%05d.png"),
|
| 1320 |
+
"-c:v", "libx264", "-pix_fmt", "yuv420p",
|
| 1321 |
+
out_video_path
|
| 1322 |
+
],
|
| 1323 |
+
check=True,
|
| 1324 |
+
capture_output=True
|
| 1325 |
+
)
|
| 1326 |
return out_video_path
|
| 1327 |
except Exception as exc:
|
| 1328 |
print(f"[ZeroGPU Video] Direct pipeline exception: {exc}, running ffmpeg dynamic visualizer fallback...", flush=True)
|