-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhunyuanvideo.py
38 lines (32 loc) · 1.8 KB
/
hunyuanvideo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import torch
from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
from diffusers.utils import export_to_video
from enhance_a_video import enable_enhance, inject_enhance_for_hunyuanvideo, set_enhance_weight
model_id = "tencent/HunyuanVideo"
transformer = HunyuanVideoTransformer3DModel.from_pretrained(
model_id, subfolder="transformer", torch_dtype=torch.bfloat16, revision="refs/pr/18"
)
pipe = HunyuanVideoPipeline.from_pretrained(
model_id, transformer=transformer, revision="refs/pr/18", torch_dtype=torch.bfloat16
)
pipe.to("cuda")
# pipe.enable_sequential_cpu_offload()
pipe.vae.enable_tiling()
# pipe.vae.enable_tiling()
# ============ Enhance-A-Video ============
# comment the following if you want to use the original model
inject_enhance_for_hunyuanvideo(pipe.transformer)
# enhance_weight can be adjusted for better visual quality
set_enhance_weight(4)
enable_enhance()
# ============ Enhance-A-Video ============
prompt = "A focused baseball player stands in the dugout, gripping his bat with determination, wearing a classic white jersey with blue pinstripes and a matching cap. The sunlight casts dramatic shadows across his face, highlighting his intense gaze as he prepares for the game. His hands, wrapped in black batting gloves, firmly hold the bat, showcasing his readiness and anticipation. The background reveals the bustling stadium, with blurred fans and vibrant green field, creating an atmosphere of excitement and competition. As he adjusts his stance, the player's concentration and passion for the sport are palpable, embodying the spirit of baseball."
output = pipe(
prompt=prompt,
height=544,
width=960,
num_frames=129,
num_inference_steps=50,
generator=torch.Generator().manual_seed(42),
).frames[0]
export_to_video(output, "output.mp4", fps=15)