Views
No views yet
1# image + video
2import torch
3from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXConditionPipeline, LTXVideoCondition
4from diffusers.utils import export_to_video, load_video, load_image
5
6
7device = "cuda:2"
8dtype = torch.bfloat16
9
10
11
12repo = "YiYiXu/ltx-95"
13
14# Initialize the pipeline
15pipe = LTXConditionPipeline.from_pretrained(repo, torch_dtype=dtype)
16pipe.to(device)
17
18
19video = load_video(
20 "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4"
21)
22
23image = load_image(
24 "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input.jpg"
25)
26
27condition1 = LTXVideoCondition(
28 image=image,
29 frame_index=0,
30)
31
32condition2 = LTXVideoCondition(
33 video=video,
34 frame_index=80,
35)
36
37# Define prompts
38prompt = "The video depicts a long, straight highway stretching into the distance, flanked by metal guardrails. The road is divided into multiple lanes, with a few vehicles visible in the far distance. The surrounding landscape features dry, grassy fields on one side and rolling hills on the other. The sky is mostly clear with a few scattered clouds, suggesting a bright, sunny day. And then the camera switch to a inding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region."
39negative_prompt='worst quality, inconsistent motion, blurry, jittery, distorted'
40# Generate the video
41generator = torch.Generator(device=device).manual_seed(0)
42video = pipe(
43 conditions=[condition1, condition2],
44 prompt=prompt,
45 negative_prompt=negative_prompt,
46 width=768,
47 height=512,
48 num_frames=161,
49 num_inference_steps=40,
50 generator=generator,
51).frames[0]
52
53# Export the video
54export_to_video(video, "output.mp4", fps=24)
55