Views
No views yet
pip install git+https://github.com/huggingface/diffusers.git1import torch
2from diffusers.utils import export_to_video, load_image
3from diffusers import AutoencoderKLWan, WanImageToVideoPipeline
4from transformers import CLIPVisionModel
5import numpy as np
6
7model_id = "Wan-AI/Wan2.1-I2V-14B-720P-Diffusers"
8image_encoder = CLIPVisionModel.from_pretrained(model_id, subfolder="image_encoder", torch_dtype=torch.float32)
9vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
10pipe = WanImageToVideoPipeline.from_pretrained(model_id, vae=vae, image_encoder=image_encoder, torch_dtype=torch.bfloat16)
11pipe.to("cuda")
12
13pipe.load_lora_weights("starsfriday/Wan2.1-Fight-LoRA")
14
15pipe.enable_model_cpu_offload() #for low-vram environments
16
17prompt = "faxiang,背景保持不变,这个女人双手合十,身后出现巨大半透明粉色虚影法相,与女人动作同步."
18
19image = load_image("https://huggingface.co/starsfriday/Wan2.1-Fight-LoRA/blob/main/result/test.jpg")
20
21max_area = 512 * 768
22aspect_ratio = image.height / image.width
23mod_value = pipe.vae_scale_factor_spatial * pipe.transformer.config.patch_size[1]
24height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
25width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
26image = image.resize((width, height))
27
28output = pipe(
29 image=image,
30 prompt=prompt,
31 height=height,
32 width=width,
33 num_frames=81,
34 guidance_scale=5.0,
35 num_inference_steps=25
36).frames[0]
37export_to_video(output, "output.mp4", fps=16)faxiang[gender] with whatever you want to let this person manifest their supernatural powers!