DarwinModel1 / IV2Img2Vid.py
J Z
Update IV2Img2Vid.py
2b31379 verified
Raw
History Blame Contribute Delete
848 Bytes
#animate img
import torch
from diffusers import I2VGenXLPipeline
from diffusers.utils import export_to_gif, load_image
from PIL import Image
pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
pipeline.enable_model_cpu_offload()
# Load a local image
image_path = "darwin1.png"
image = Image.open(image_path).convert("RGB")
prompt = "Charles Darwin stands up from chair, realistic"
negative_prompt = "Distorted, discontinuous, Ugly, blurry, low resolution, motionless, static, disfigured, disconnected limbs, Ugly faces, incomplete arms"
generator = torch.manual_seed(8888)
frames = pipeline(
prompt=prompt,
image=image,
num_inference_steps=50,
negative_prompt=negative_prompt,
guidance_scale=9.0,
generator=generator
).frames[0]
export_to_gif(frames, "i2v5.gif")