Spaces:
Paused
Paused
Normalize Wan frames and fix video export
Browse files- app.py +19 -0
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -125,6 +125,24 @@ def _cover_resize(image: Image.Image, size: tuple[int, int]) -> Image.Image:
|
|
| 125 |
return resized.crop((left, top, left + target_width, top + target_height))
|
| 126 |
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
def _frame_count(duration_seconds: float) -> int:
|
| 129 |
desired = int(round(float(duration_seconds) * FPS))
|
| 130 |
return int(np.clip(round((desired - 1) / 4) * 4 + 1, 17, 81))
|
|
@@ -230,6 +248,7 @@ def generate_extended_video(
|
|
| 230 |
(current_seed + index) % MAX_SEED
|
| 231 |
),
|
| 232 |
).frames[0]
|
|
|
|
| 233 |
|
| 234 |
clip = tempfile.NamedTemporaryFile(suffix=f"-clip-{index + 1}.mp4", delete=False)
|
| 235 |
clip.close()
|
|
|
|
| 125 |
return resized.crop((left, top, left + target_width, top + target_height))
|
| 126 |
|
| 127 |
|
| 128 |
+
def _to_pil_frame(frame) -> Image.Image:
|
| 129 |
+
"""Normalize Diffusers frame outputs to an RGB PIL image."""
|
| 130 |
+
if isinstance(frame, Image.Image):
|
| 131 |
+
return frame.convert("RGB")
|
| 132 |
+
if isinstance(frame, torch.Tensor):
|
| 133 |
+
frame = frame.detach().cpu().numpy()
|
| 134 |
+
|
| 135 |
+
array = np.asarray(frame)
|
| 136 |
+
if array.ndim == 3 and array.shape[0] in (1, 3, 4) and array.shape[-1] not in (1, 3, 4):
|
| 137 |
+
array = np.moveaxis(array, 0, -1)
|
| 138 |
+
if np.issubdtype(array.dtype, np.floating):
|
| 139 |
+
if array.size and float(array.min()) < 0:
|
| 140 |
+
array = (array + 1.0) / 2.0
|
| 141 |
+
array = np.clip(array, 0.0, 1.0) * 255.0
|
| 142 |
+
array = np.clip(array, 0, 255).astype(np.uint8)
|
| 143 |
+
return Image.fromarray(array).convert("RGB")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
def _frame_count(duration_seconds: float) -> int:
|
| 147 |
desired = int(round(float(duration_seconds) * FPS))
|
| 148 |
return int(np.clip(round((desired - 1) / 4) * 4 + 1, 17, 81))
|
|
|
|
| 248 |
(current_seed + index) % MAX_SEED
|
| 249 |
),
|
| 250 |
).frames[0]
|
| 251 |
+
frames = [_to_pil_frame(frame) for frame in frames]
|
| 252 |
|
| 253 |
clip = tempfile.NamedTemporaryFile(suffix=f"-clip-{index + 1}.mp4", delete=False)
|
| 254 |
clip.close()
|
requirements.txt
CHANGED
|
@@ -5,7 +5,7 @@ safetensors
|
|
| 5 |
sentencepiece
|
| 6 |
peft
|
| 7 |
ftfy
|
|
|
|
| 8 |
imageio-ffmpeg
|
| 9 |
opencv-python-headless
|
| 10 |
torchao==0.11.0
|
| 11 |
-
|
|
|
|
| 5 |
sentencepiece
|
| 6 |
peft
|
| 7 |
ftfy
|
| 8 |
+
imageio
|
| 9 |
imageio-ffmpeg
|
| 10 |
opencv-python-headless
|
| 11 |
torchao==0.11.0
|
|
|