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
Files changed (1) hide show
  1. app.py +15 -15
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 WanPipeline
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 Wan2.1-T2V-1.3B inside a ZeroGPU context."""
37
  global _pipe
38
  if _pipe is None:
39
  with _pipe_lock:
40
  if _pipe is None:
41
- print("Loading Wan2.1-T2V-1.3B pipeline...")
42
- _pipe = WanPipeline.from_pretrained(
43
- "Wan-AI/Wan2.1-T2V-1.3B",
44
  torch_dtype=torch.bfloat16,
45
  )
46
  _pipe.enable_model_cpu_offload()
47
  _pipe.vae.enable_tiling()
48
- print("Wan2.1-T2V pipeline ready.")
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 (Wan2.1-T2V-1.3B inside ZeroGPU context) ---
191
- @spaces.GPU(duration=180)
192
  def run_video_generation(video_prompt):
193
  pipe = get_pipe()
 
194
  output = pipe(
195
  prompt=video_prompt,
196
- negative_prompt="blurry, ugly, bad quality, distorted, low resolution",
197
- width=512,
198
- height=288,
199
- num_frames=33,
200
- num_inference_steps=24,
201
- guidance_scale=5.0,
202
  )
203
  mp4_path = "output_video.mp4"
204
- export_to_video(output.frames[0], mp4_path, fps=16)
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 ---