Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -168,8 +168,10 @@ print("[Echo-Infinity] Pipeline ready.")
|
|
| 168 |
# Inference function
|
| 169 |
# ----------------------------------------------------------------------------
|
| 170 |
from einops import rearrange
|
| 171 |
-
|
|
|
|
| 172 |
import random
|
|
|
|
| 173 |
|
| 174 |
|
| 175 |
def _estimate_duration(prompt: str, num_frames: int = 21, *args, **kwargs):
|
|
@@ -198,8 +200,6 @@ def generate(
|
|
| 198 |
seed: Random seed for reproducibility.
|
| 199 |
num_frames: Number of frames to generate (must be divisible by 3).
|
| 200 |
"""
|
| 201 |
-
import gradio as gr
|
| 202 |
-
|
| 203 |
if not prompt or not prompt.strip():
|
| 204 |
return None, "Please enter a text prompt."
|
| 205 |
|
|
@@ -234,10 +234,14 @@ def generate(
|
|
| 234 |
video = 255.0 * current_video
|
| 235 |
pipeline.vae.model.clear_cache()
|
| 236 |
|
| 237 |
-
# Save to temp file
|
|
|
|
| 238 |
tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
| 239 |
tmp.close()
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
return tmp.name, f"Generated {num_frames} frames from seed {seed}."
|
| 243 |
|
|
@@ -245,8 +249,6 @@ def generate(
|
|
| 245 |
# ----------------------------------------------------------------------------
|
| 246 |
# Gradio UI
|
| 247 |
# ----------------------------------------------------------------------------
|
| 248 |
-
import gradio as gr
|
| 249 |
-
|
| 250 |
CSS = """
|
| 251 |
#col-container { max-width: 1100px; margin: 0 auto; }
|
| 252 |
.dark .gradio-container { color: var(--body-text-color); }
|
|
|
|
| 168 |
# Inference function
|
| 169 |
# ----------------------------------------------------------------------------
|
| 170 |
from einops import rearrange
|
| 171 |
+
import imageio
|
| 172 |
+
import numpy as np
|
| 173 |
import random
|
| 174 |
+
import gradio as gr
|
| 175 |
|
| 176 |
|
| 177 |
def _estimate_duration(prompt: str, num_frames: int = 21, *args, **kwargs):
|
|
|
|
| 200 |
seed: Random seed for reproducibility.
|
| 201 |
num_frames: Number of frames to generate (must be divisible by 3).
|
| 202 |
"""
|
|
|
|
|
|
|
| 203 |
if not prompt or not prompt.strip():
|
| 204 |
return None, "Please enter a text prompt."
|
| 205 |
|
|
|
|
| 234 |
video = 255.0 * current_video
|
| 235 |
pipeline.vae.model.clear_cache()
|
| 236 |
|
| 237 |
+
# Save to temp file using imageio (torchvision.io.write_video not available)
|
| 238 |
+
frames = video[0].numpy().astype(np.uint8) # [T, H, W, C]
|
| 239 |
tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
| 240 |
tmp.close()
|
| 241 |
+
writer = imageio.get_writer(tmp.name, fps=16, codec="libx264")
|
| 242 |
+
for frame in frames:
|
| 243 |
+
writer.append_data(frame)
|
| 244 |
+
writer.close()
|
| 245 |
|
| 246 |
return tmp.name, f"Generated {num_frames} frames from seed {seed}."
|
| 247 |
|
|
|
|
| 249 |
# ----------------------------------------------------------------------------
|
| 250 |
# Gradio UI
|
| 251 |
# ----------------------------------------------------------------------------
|
|
|
|
|
|
|
| 252 |
CSS = """
|
| 253 |
#col-container { max-width: 1100px; margin: 0 auto; }
|
| 254 |
.dark .gradio-container { color: var(--body-text-color); }
|