Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,22 +46,24 @@ def generate_video(prompt, image_url):
|
|
| 46 |
raw_image = Image.open(BytesIO(requests.get(image_url).content)).convert("RGB")
|
| 47 |
image = prepare_image_condition(raw_image)
|
| 48 |
|
| 49 |
-
# Set target resolutions - using
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
# Step 1: Generate latents at lower resolution with
|
| 54 |
latents = pipe(
|
| 55 |
prompt=prompt,
|
| 56 |
image=image,
|
| 57 |
width=down_width,
|
| 58 |
height=down_height,
|
| 59 |
num_frames=60,
|
| 60 |
-
num_inference_steps=
|
| 61 |
output_type="latent",
|
| 62 |
-
guidance_scale=
|
| 63 |
-
decode_timestep=0.
|
| 64 |
-
decode_noise_scale=0.
|
| 65 |
generator=generator
|
| 66 |
).frames
|
| 67 |
|
|
@@ -74,19 +76,20 @@ def generate_video(prompt, image_url):
|
|
| 74 |
torch.cuda.empty_cache()
|
| 75 |
gc.collect()
|
| 76 |
|
| 77 |
-
# Step 3: Decode upscaled latents to frames
|
| 78 |
frames = pipe(
|
| 79 |
-
prompt=prompt, # Use original prompt for
|
| 80 |
latents=upscaled_latents,
|
| 81 |
width=base_width,
|
| 82 |
height=base_height,
|
| 83 |
num_frames=60,
|
| 84 |
-
num_inference_steps=
|
| 85 |
output_type="pil",
|
| 86 |
-
guidance_scale=
|
| 87 |
-
decode_timestep=0.
|
| 88 |
-
decode_noise_scale=0.
|
| 89 |
-
|
|
|
|
| 90 |
generator=generator
|
| 91 |
).frames[0]
|
| 92 |
|
|
@@ -204,7 +207,7 @@ demo = gr.Interface(
|
|
| 204 |
],
|
| 205 |
outputs=gr.Video(label="Generated Video"),
|
| 206 |
title="🎬 LTX AI Video Generator",
|
| 207 |
-
description="AI-powered video with voiceover and subtitles.
|
| 208 |
)
|
| 209 |
|
| 210 |
demo.launch()
|
|
|
|
| 46 |
raw_image = Image.open(BytesIO(requests.get(image_url).content)).convert("RGB")
|
| 47 |
image = prepare_image_condition(raw_image)
|
| 48 |
|
| 49 |
+
# Set target resolutions - using dimensions that match expected latent shapes
|
| 50 |
+
# LTX uses 32x downsampling, so we need multiples of 32
|
| 51 |
+
# For latent shape (1, 128, 8, 16, 16), we need 16*32 = 512x512
|
| 52 |
+
base_width, base_height = 512, 512 # final upscaled size (16*32)
|
| 53 |
+
down_width, down_height = 256, 256 # for initial generation (8*32) - smaller ratio for upscaling
|
| 54 |
|
| 55 |
+
# Step 1: Generate latents at lower resolution with improved quality settings
|
| 56 |
latents = pipe(
|
| 57 |
prompt=prompt,
|
| 58 |
image=image,
|
| 59 |
width=down_width,
|
| 60 |
height=down_height,
|
| 61 |
num_frames=60,
|
| 62 |
+
num_inference_steps=10, # Increased from 7 for better quality
|
| 63 |
output_type="latent",
|
| 64 |
+
guidance_scale=1.5, # Slightly increased for better prompt adherence
|
| 65 |
+
decode_timestep=0.08, # Optimized value
|
| 66 |
+
decode_noise_scale=0.05, # Reduced noise
|
| 67 |
generator=generator
|
| 68 |
).frames
|
| 69 |
|
|
|
|
| 76 |
torch.cuda.empty_cache()
|
| 77 |
gc.collect()
|
| 78 |
|
| 79 |
+
# Step 3: Decode upscaled latents to frames with improved settings
|
| 80 |
frames = pipe(
|
| 81 |
+
prompt=prompt, # Use original prompt for consistency
|
| 82 |
latents=upscaled_latents,
|
| 83 |
width=base_width,
|
| 84 |
height=base_height,
|
| 85 |
num_frames=60,
|
| 86 |
+
num_inference_steps=12, # Increased for better decoding quality
|
| 87 |
output_type="pil",
|
| 88 |
+
guidance_scale=1.5, # Consistent with generation
|
| 89 |
+
decode_timestep=0.08, # Optimized
|
| 90 |
+
decode_noise_scale=0.05, # Reduced noise
|
| 91 |
+
image_cond_noise_scale=0.02, # Reduced for cleaner output
|
| 92 |
+
denoise_strength=0.25, # Balanced denoising
|
| 93 |
generator=generator
|
| 94 |
).frames[0]
|
| 95 |
|
|
|
|
| 207 |
],
|
| 208 |
outputs=gr.Video(label="Generated Video"),
|
| 209 |
title="🎬 LTX AI Video Generator",
|
| 210 |
+
description="AI-powered video with voiceover and subtitles. Generates at 256x256 and upscales to 512x512 with improved quality."
|
| 211 |
)
|
| 212 |
|
| 213 |
demo.launch()
|