Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -8,9 +8,10 @@ import torch
|
|
| 8 |
import gradio as gr
|
| 9 |
import tempfile
|
| 10 |
import time
|
|
|
|
|
|
|
| 11 |
from omegaconf import OmegaConf
|
| 12 |
from einops import rearrange
|
| 13 |
-
from torchvision.io import write_video
|
| 14 |
|
| 15 |
from pipeline import CausalInferencePipeline
|
| 16 |
from utils.wan_wrapper import WanDiffusionWrapper, WanTextEncoder, WanVAEWrapper
|
|
@@ -219,10 +220,10 @@ def generate(
|
|
| 219 |
video = rearrange(video, 'b t c h w -> b t h w c').cpu()
|
| 220 |
|
| 221 |
# Save as MP4
|
|
|
|
| 222 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
|
| 223 |
output_path = f.name
|
| 224 |
-
|
| 225 |
-
write_video(output_path, video[0], fps=16)
|
| 226 |
|
| 227 |
elapsed = time.time() - start_time
|
| 228 |
print(f"Generation completed in {elapsed:.2f}s")
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
import tempfile
|
| 10 |
import time
|
| 11 |
+
import numpy as np
|
| 12 |
+
import imageio
|
| 13 |
from omegaconf import OmegaConf
|
| 14 |
from einops import rearrange
|
|
|
|
| 15 |
|
| 16 |
from pipeline import CausalInferencePipeline
|
| 17 |
from utils.wan_wrapper import WanDiffusionWrapper, WanTextEncoder, WanVAEWrapper
|
|
|
|
| 220 |
video = rearrange(video, 'b t c h w -> b t h w c').cpu()
|
| 221 |
|
| 222 |
# Save as MP4
|
| 223 |
+
video_np = (video[0].numpy() * 255).clip(0, 255).astype(np.uint8)
|
| 224 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
|
| 225 |
output_path = f.name
|
| 226 |
+
imageio.mimsave(output_path, video_np, fps=16, quality=8)
|
|
|
|
| 227 |
|
| 228 |
elapsed = time.time() - start_time
|
| 229 |
print(f"Generation completed in {elapsed:.2f}s")
|