Skip to content

Commit 46bd05b

Browse files
author
lzw478614@alibaba-inc.com
committed
add examples
1 parent 952933e commit 46bd05b

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import torch
2+
from diffsynth import save_video,VideoData
3+
from diffsynth.pipelines.wan_video_new import WanVideoPipeline, ModelConfig
4+
from PIL import Image
5+
from modelscope import dataset_snapshot_download
6+
7+
pipe = WanVideoPipeline.from_pretrained(
8+
torch_dtype=torch.bfloat16,
9+
device="cuda",
10+
model_configs=[
11+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control-Camera", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
12+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control-Camera", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
13+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control-Camera", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth", offload_device="cpu"),
14+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control-Camera", origin_file_pattern="Wan2.1_VAE.pth", offload_device="cpu"),
15+
],
16+
)
17+
pipe.enable_vram_management()
18+
19+
20+
dataset_snapshot_download(
21+
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
22+
local_dir="./",
23+
allow_file_pattern=f"data/examples/wan/input_image.jpg"
24+
)
25+
input_image = Image.open("data/examples/wan/input_image.jpg")
26+
27+
video = pipe(
28+
prompt="一艘小船正勇敢地乘风破浪前行。蔚蓝的大海波涛汹涌,白色的浪花拍打着船身,但小船毫不畏惧,坚定地驶向远方。阳光洒在水面上,闪烁着金色的光芒,为这壮丽的场景增添了一抹温暖。镜头拉近,可以看到船上的旗帜迎风飘扬,象征着不屈的精神与冒险的勇气。这段画面充满力量,激励人心,展现了面对挑战时的无畏与执着。",
29+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
30+
seed=0, tiled=True,
31+
input_image=input_image,
32+
camera_control_direction="Left", camera_control_speed=0.01,
33+
)
34+
save_video(video, "video_left.mp4", fps=15, quality=5)
35+
36+
video = pipe(
37+
prompt="一艘小船正勇敢地乘风破浪前行。蔚蓝的大海波涛汹涌,白色的浪花拍打着船身,但小船毫不畏惧,坚定地驶向远方。阳光洒在水面上,闪烁着金色的光芒,为这壮丽的场景增添了一抹温暖。镜头拉近,可以看到船上的旗帜迎风飘扬,象征着不屈的精神与冒险的勇气。这段画面充满力量,激励人心,展现了面对挑战时的无畏与执着。",
38+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
39+
seed=0, tiled=True,
40+
input_image=input_image,
41+
camera_control_direction="Up", camera_control_speed=0.01,
42+
)
43+
save_video(video, "video_up.mp4", fps=15, quality=5)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import torch
2+
from diffsynth import save_video,VideoData
3+
from diffsynth.pipelines.wan_video_new import WanVideoPipeline, ModelConfig
4+
from PIL import Image
5+
from modelscope import dataset_snapshot_download
6+
7+
pipe = WanVideoPipeline.from_pretrained(
8+
torch_dtype=torch.bfloat16,
9+
device="cuda",
10+
model_configs=[
11+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
12+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
13+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth", offload_device="cpu"),
14+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-Control", origin_file_pattern="Wan2.1_VAE.pth", offload_device="cpu"),
15+
],
16+
)
17+
pipe.enable_vram_management()
18+
19+
dataset_snapshot_download(
20+
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
21+
local_dir="./",
22+
allow_file_pattern=["data/examples/wan/control_video.mp4", "data/examples/wan/reference_image_girl.png"]
23+
)
24+
25+
# Control video
26+
control_video = VideoData("data/examples/wan/control_video.mp4", height=832, width=576)
27+
reference_image = Image.open("data/examples/wan/reference_image_girl.png").resize((576, 832))
28+
video = pipe(
29+
prompt="扁平风格动漫,一位长发少女优雅起舞。她五官精致,大眼睛明亮有神,黑色长发柔顺光泽。身穿淡蓝色T恤和深蓝色牛仔短裤。背景是粉色。",
30+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
31+
control_video=control_video, reference_image=reference_image,
32+
height=832, width=576, num_frames=49,
33+
seed=1, tiled=True
34+
)
35+
save_video(video, "video.mp4", fps=15, quality=5)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import torch
2+
from diffsynth import save_video
3+
from diffsynth.pipelines.wan_video_new import WanVideoPipeline, ModelConfig
4+
from PIL import Image
5+
from modelscope import dataset_snapshot_download
6+
7+
pipe = WanVideoPipeline.from_pretrained(
8+
torch_dtype=torch.bfloat16,
9+
device="cuda",
10+
model_configs=[
11+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="high_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
12+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="low_noise_model/diffusion_pytorch_model*.safetensors", offload_device="cpu"),
13+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="models_t5_umt5-xxl-enc-bf16.pth", offload_device="cpu"),
14+
ModelConfig(model_id="PAI/Wan2.2-Fun-A14B-InP", origin_file_pattern="Wan2.1_VAE.pth", offload_device="cpu"),
15+
],
16+
)
17+
pipe.enable_vram_management()
18+
19+
dataset_snapshot_download(
20+
dataset_id="DiffSynth-Studio/examples_in_diffsynth",
21+
local_dir="./",
22+
allow_file_pattern=f"data/examples/wan/input_image.jpg"
23+
)
24+
image = Image.open("data/examples/wan/input_image.jpg")
25+
26+
# First and last frame to video
27+
video = pipe(
28+
prompt="一艘小船正勇敢地乘风破浪前行。蔚蓝的大海波涛汹涌,白色的浪花拍打着船身,但小船毫不畏惧,坚定地驶向远方。阳光洒在水面上,闪烁着金色的光芒,为这壮丽的场景增添了一抹温暖。镜头拉近,可以看到船上的旗帜迎风飘扬,象征着不屈的精神与冒险的勇气。这段画面充满力量,激励人心,展现了面对挑战时的无畏与执着。",
29+
negative_prompt="色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走",
30+
input_image=image,
31+
seed=0, tiled=True,
32+
# You can input `end_image=xxx` to control the last frame of the video.
33+
# The model will automatically generate the dynamic content between `input_image` and `end_image`.
34+
)
35+
save_video(video, "video.mp4", fps=15, quality=5)

0 commit comments

Comments
 (0)