Spaces:
Sleeping
Sleeping
Junchen Fu commited on
Commit ·
b6e2fb3
1
Parent(s): 0432e61
Swap Wan2.1 -> HunyuanVideo-1.5, 544x960 portrait 9:16, 49 frames @ 24fps
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ import threading
|
|
| 10 |
import numpy as np
|
| 11 |
import pandas as pd
|
| 12 |
import faiss
|
| 13 |
-
from diffusers import
|
| 14 |
from diffusers.utils import export_to_video
|
| 15 |
from transformers import pipeline as hf_pipeline
|
| 16 |
from sentence_transformers import SentenceTransformer
|
|
@@ -33,19 +33,19 @@ _pipe_lock = threading.Lock()
|
|
| 33 |
_rag_lock = threading.Lock()
|
| 34 |
|
| 35 |
def get_pipe():
|
| 36 |
-
"""Lazy-load
|
| 37 |
global _pipe
|
| 38 |
if _pipe is None:
|
| 39 |
with _pipe_lock:
|
| 40 |
if _pipe is None:
|
| 41 |
-
print("Loading
|
| 42 |
-
_pipe =
|
| 43 |
-
"
|
| 44 |
torch_dtype=torch.bfloat16,
|
| 45 |
)
|
| 46 |
_pipe.enable_model_cpu_offload()
|
| 47 |
_pipe.vae.enable_tiling()
|
| 48 |
-
print("
|
| 49 |
return _pipe
|
| 50 |
|
| 51 |
def get_rag():
|
|
@@ -187,21 +187,21 @@ Return JSON ONLY with keys: title (max 50 chars), cover_prompt, video_prompt (3s
|
|
| 187 |
result["_matched_tag"] = matched_tag
|
| 188 |
return result
|
| 189 |
|
| 190 |
-
# --- 5. Video generation (
|
| 191 |
-
@spaces.GPU(duration=
|
| 192 |
def run_video_generation(video_prompt):
|
| 193 |
pipe = get_pipe()
|
|
|
|
| 194 |
output = pipe(
|
| 195 |
prompt=video_prompt,
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
guidance_scale=5.0,
|
| 202 |
)
|
| 203 |
mp4_path = "output_video.mp4"
|
| 204 |
-
export_to_video(output.frames[0], mp4_path, fps=
|
| 205 |
return mp4_path
|
| 206 |
|
| 207 |
# --- 6. Gradio entrypoints ---
|
|
|
|
| 10 |
import numpy as np
|
| 11 |
import pandas as pd
|
| 12 |
import faiss
|
| 13 |
+
from diffusers import HunyuanVideo15Pipeline
|
| 14 |
from diffusers.utils import export_to_video
|
| 15 |
from transformers import pipeline as hf_pipeline
|
| 16 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 33 |
_rag_lock = threading.Lock()
|
| 34 |
|
| 35 |
def get_pipe():
|
| 36 |
+
"""Lazy-load HunyuanVideo-1.5 inside a ZeroGPU context."""
|
| 37 |
global _pipe
|
| 38 |
if _pipe is None:
|
| 39 |
with _pipe_lock:
|
| 40 |
if _pipe is None:
|
| 41 |
+
print("Loading HunyuanVideo-1.5 pipeline...")
|
| 42 |
+
_pipe = HunyuanVideo15Pipeline.from_pretrained(
|
| 43 |
+
"hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-720p_t2v",
|
| 44 |
torch_dtype=torch.bfloat16,
|
| 45 |
)
|
| 46 |
_pipe.enable_model_cpu_offload()
|
| 47 |
_pipe.vae.enable_tiling()
|
| 48 |
+
print("HunyuanVideo-1.5 pipeline ready.")
|
| 49 |
return _pipe
|
| 50 |
|
| 51 |
def get_rag():
|
|
|
|
| 187 |
result["_matched_tag"] = matched_tag
|
| 188 |
return result
|
| 189 |
|
| 190 |
+
# --- 5. Video generation (HunyuanVideo-1.5 inside ZeroGPU context) ---
|
| 191 |
+
@spaces.GPU(duration=300)
|
| 192 |
def run_video_generation(video_prompt):
|
| 193 |
pipe = get_pipe()
|
| 194 |
+
generator = torch.Generator(device="cuda").manual_seed(42)
|
| 195 |
output = pipe(
|
| 196 |
prompt=video_prompt,
|
| 197 |
+
generator=generator,
|
| 198 |
+
num_frames=49, # ~2s at 24fps — fast enough for a demo
|
| 199 |
+
num_inference_steps=30,
|
| 200 |
+
width=544,
|
| 201 |
+
height=960, # 9:16 portrait — TikTok/short-video style
|
|
|
|
| 202 |
)
|
| 203 |
mp4_path = "output_video.mp4"
|
| 204 |
+
export_to_video(output.frames[0], mp4_path, fps=24)
|
| 205 |
return mp4_path
|
| 206 |
|
| 207 |
# --- 6. Gradio entrypoints ---
|