6.8 KiB
6.8 KiB
In [ ]:
!nvidia-smiIn [ ]:
# --- EDIT THIS ---
# Set to the folder path of your attached Kaggle dataset if you pre-downloaded the model,
# e.g. "/kaggle/input/wan22-ti2v-5b/Wan2.2-TI2V-5B-Diffusers"
# Leave as None to auto-download from Hugging Face instead.
LOCAL_MODEL_PATH = None
# Where to save generated test videos
OUTPUT_DIR = "/kaggle/working/outputs"
import os
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Quick sanity check of what's available under /kaggle/input
for root, dirs, files in os.walk("/kaggle/input"):
print(root)
In [ ]:
import torch
from diffusers import WanPipeline
from diffusers.utils import export_to_video, load_image
from IPython.display import Video, display
print("Torch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("GPU:", torch.cuda.get_device_name(0))
In [ ]:
model_source = LOCAL_MODEL_PATH if LOCAL_MODEL_PATH else "Wan-AI/Wan2.2-TI2V-5B-Diffusers"
print("Loading model from:", model_source)
pipe = WanPipeline.from_pretrained(
model_source,
torch_dtype=torch.bfloat16
)
pipe.to("cuda")
# Keeps VRAM usage safe on Kaggle's T4/P100 GPUs
pipe.enable_model_cpu_offload()
print("Model loaded successfully.")
In [ ]:
prompt = "A golden retriever running on a beach at sunset, cinematic lighting"
t2v_output = pipe(
prompt=prompt,
num_frames=49,
guidance_scale=5.0
).frames[0]
t2v_path = os.path.join(OUTPUT_DIR, "test_t2v_output.mp4")
export_to_video(t2v_output, t2v_path, fps=24)
print("Saved:", t2v_path)
In [ ]:
display(Video(t2v_path, embed=True))In [ ]:
# --- EDIT THIS ---
# Local path to an image from your dataset, e.g. "/kaggle/input/my-images/sample.jpg"
# Or leave as a URL to test with a sample image instead.
input_image_path = "https://images.unsplash.com/photo-1519681393784-d120267933ba"
input_image = load_image(input_image_path)
i2v_prompt = "the scene comes to life with gentle, natural motion"
i2v_output = pipe(
image=input_image,
prompt=i2v_prompt,
num_frames=49,
guidance_scale=5.0
).frames[0]
i2v_path = os.path.join(OUTPUT_DIR, "test_i2v_output.mp4")
export_to_video(i2v_output, i2v_path, fps=24)
print("Saved:", i2v_path)
In [ ]:
display(Video(i2v_path, embed=True))