Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -288,8 +288,56 @@ def generate_video(
|
|
| 288 |
width: int = DEFAULT_1_STAGE_WIDTH ,
|
| 289 |
progress=gr.Progress(track_tqdm=True)
|
| 290 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
try:
|
| 294 |
# Randomize seed if checkbox is enabled
|
| 295 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
|
@@ -578,4 +626,4 @@ with gr.Blocks(css=css, title="LTX-2 Video Distilled 🎥🔈") as demo:
|
|
| 578 |
|
| 579 |
|
| 580 |
if __name__ == "__main__":
|
| 581 |
-
demo.launch()
|
|
|
|
| 288 |
width: int = DEFAULT_1_STAGE_WIDTH ,
|
| 289 |
progress=gr.Progress(track_tqdm=True)
|
| 290 |
):
|
| 291 |
+
"""
|
| 292 |
+
Generate a short cinematic video from a text prompt and optional input image using the LTX-2 distilled pipeline.
|
| 293 |
+
|
| 294 |
+
This function performs text-to-video or image-to-video generation by:
|
| 295 |
+
1. Optionally enhancing the input prompt using a Gemma-based text encoder.
|
| 296 |
+
2. Encoding the prompt into video and audio conditioning embeddings.
|
| 297 |
+
3. Running the LTX-2 distilled DiT-based video generation pipeline with optional image conditioning.
|
| 298 |
+
4. Producing an MP4 video file at the requested resolution, duration, and random seed.
|
| 299 |
+
|
| 300 |
+
Args:
|
| 301 |
+
input_image (PIL.Image.Image | None):
|
| 302 |
+
Optional input image used for image-to-video generation. If provided,
|
| 303 |
+
the image is injected at the first frame with full strength to guide motion.
|
| 304 |
+
prompt (str):
|
| 305 |
+
Text description of the scene, motion, and cinematic style to generate.
|
| 306 |
+
duration (float):
|
| 307 |
+
Desired video length in seconds. Internally converted to number of frames
|
| 308 |
+
using a fixed frame rate (24 FPS).
|
| 309 |
+
enhance_prompt (bool, optional):
|
| 310 |
+
Whether to enhance the prompt using an AI prompt enhancer before encoding.
|
| 311 |
+
Defaults to True.
|
| 312 |
+
seed (int, optional):
|
| 313 |
+
Base random seed for reproducibility. Ignored if `randomize_seed` is True.
|
| 314 |
+
Defaults to 42.
|
| 315 |
+
randomize_seed (bool, optional):
|
| 316 |
+
If True, a random seed is generated for each run. Defaults to True.
|
| 317 |
+
height (int, optional):
|
| 318 |
+
Output video height in pixels. Defaults to the model’s 1-stage height.
|
| 319 |
+
width (int, optional):
|
| 320 |
+
Output video width in pixels. Defaults to the model’s 1-stage width.
|
| 321 |
+
progress (gr.Progress, optional):
|
| 322 |
+
Gradio progress tracker for visualizing generation progress.
|
| 323 |
|
| 324 |
+
Returns:
|
| 325 |
+
tuple:
|
| 326 |
+
- str: Path to the generated MP4 video file.
|
| 327 |
+
- int: The seed used for the generation.
|
| 328 |
+
|
| 329 |
+
Notes:
|
| 330 |
+
- The function uses a fixed frame rate of 24 FPS.
|
| 331 |
+
- Prompt embeddings are generated externally and passed directly to the pipeline
|
| 332 |
+
to avoid reloading the text encoder.
|
| 333 |
+
- GPU memory is explicitly cleared after generation to reduce VRAM pressure.
|
| 334 |
+
- If an input image is provided, it is temporarily saved to disk for processing.
|
| 335 |
+
|
| 336 |
+
Raises:
|
| 337 |
+
Exception:
|
| 338 |
+
Any errors during prompt encoding, embedding loading, or video generation
|
| 339 |
+
are caught and printed with a full traceback for debugging.
|
| 340 |
+
"""
|
| 341 |
try:
|
| 342 |
# Randomize seed if checkbox is enabled
|
| 343 |
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
|
|
|
| 626 |
|
| 627 |
|
| 628 |
if __name__ == "__main__":
|
| 629 |
+
demo.launch(ssr_mode=False, mcp_server=True)
|