Views
No views yet
sudo apt-get update && sudo apt-get install ffmpeg git-lfs cbm1pip install -U diffusers transformers torch sentencepiece peft moviepy protobuf
2pip install git+https://github.com/Lightricks/LTX-Video.git
3pip install git+https://github.com/huggingface/diffusers.git1import torch
2from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
3from diffusers.utils import export_to_video
4
5# Load base model and LoRA weights
6pipe = LTXConditionPipeline.from_pretrained(
7 "Lightricks/LTX-Video-0.9.7-dev",
8 torch_dtype=torch.bfloat16
9)
10pipe.load_lora_weights("LTXV_13B_097_DEV_escoffier_im_lora/lora_weights_step_19000.safetensors")
11
12# Load latent upscaler
13pipe_upsample = LTXLatentUpsamplePipeline.from_pretrained(
14 "Lightricks/ltxv-spatial-upscaler-0.9.7",
15 vae=pipe.vae,
16 torch_dtype=torch.bfloat16
17)
18
19# Memory optimization
20pipe.enable_sequential_cpu_offload()
21pipe_upsample.enable_sequential_cpu_offload()1def generate_escoffier_video(prompt, output_name):
2 """Complete generation pipeline for 832x480 videos"""
3
4 # Fixed resolution parameters
5 expected_width, expected_height = 832, 480
6 downscale_factor = 2/3
7 num_frames = 121 # ~5 seconds at 24fps
8 negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
9
10 # Resolution rounding helper
11 def round_resolution(h, w):
12 ratio = pipe.vae_spatial_compression_ratio
13 return h - (h % ratio), w - (w % ratio)
14
15 low_res_h, low_res_w = round_resolution(
16 int(expected_height * downscale_factor),
17 int(expected_width * downscale_factor)
18 )
19
20 # 1. Initial generation at low resolution
21 latents = pipe(
22 conditions=None,
23 prompt=prompt,
24 negative_prompt=negative_prompt,
25 width=low_res_w,
26 height=low_res_h,
27 num_frames=num_frames,
28 num_inference_steps=30,
29 generator=torch.Generator().manual_seed(0),
30 output_type="latent",
31 ).frames
32
33 # 2. Latent upscaling (2x)
34 upscaled_latents = pipe_upsample(
35 latents=latents,
36 output_type="latent"
37 ).frames
38
39 # 3. Quality refinement pass
40 video = pipe(
41 prompt=prompt,
42 negative_prompt=negative_prompt,
43 width=low_res_w*2, # 2x upscaled
44 height=low_res_h*2,
45 num_frames=num_frames,
46 denoise_strength=0.4, # 4/10 steps
47 num_inference_steps=10,
48 latents=upscaled_latents,
49 decode_timestep=0.05,
50 image_cond_noise_scale=0.025,
51 generator=torch.Generator().manual_seed(0),
52 output_type="pil",
53 ).frames[0]
54
55 # 4. Final resize to target resolution
56 video = [frame.resize((expected_width, expected_height)) for frame in video]
57 export_to_video(video, f"{output_name}.mp4", fps=24)1generate_escoffier_video(
2 prompt="In the style of Escoffier, This is a digital anime-style illustration of a blonde, blue-eyed female character with long, flowing hair and a large, curled strand on top. She wears a white and purple dress with gold accents, a large magenta bow on the waist, and white thigh-high stockings with intricate designs. The background features glowing, crystal-like structures and a dark blue, starry sky. Her expression is gentle, and she holds up the hem of her skirt with her right hand. The overall style is vibrant and dynamic, with a focus on her detailed, fantasy-inspired outfit and the magical, ethereal setting.",
3 output_name="escoffier_cosmic_scene"
4)1generate_escoffier_video(
2 prompt="In the style of Escoffier, This is a digital anime-style illustration of a blonde, blue-eyed female character with long, flowing hair and a large, curled strand on top. She wears a white and purple dress with gold accents, a large magenta bow on the waist, and white thigh-high stockings with intricate floral designs. She stands gracefully in a mystical garden filled with floating crystal butterflies and glowing lilies, reaching out to touch a shimmering orb.",
3 output_name="escoffier_garden_scene"
4)