Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@ from pathlib import Path
|
|
| 5 |
current_dir = Path(__file__).parent
|
| 6 |
sys.path.insert(0, str(current_dir / "packages" / "ltx-pipelines" / "src"))
|
| 7 |
sys.path.insert(0, str(current_dir / "packages" / "ltx-core" / "src"))
|
| 8 |
-
|
|
|
|
| 9 |
import spaces
|
| 10 |
import gradio as gr
|
| 11 |
from typing import Optional
|
|
@@ -23,6 +24,7 @@ from ltx_pipelines.constants import (
|
|
| 23 |
DEFAULT_LORA_STRENGTH,
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
# Custom negative prompt
|
| 27 |
DEFAULT_NEGATIVE_PROMPT = "shaky, glitchy, low quality, worst quality, deformed, distorted, disfigured, motion smear, motion artifacts, fused fingers, bad anatomy, weird hand, ugly, transition, static"
|
| 28 |
|
|
@@ -129,9 +131,7 @@ def generate_video(
|
|
| 129 |
"""Generate a video based on the given parameters."""
|
| 130 |
try:
|
| 131 |
# Randomize seed if checkbox is enabled
|
| 132 |
-
if randomize_seed
|
| 133 |
-
import random
|
| 134 |
-
seed = random.randint(0, 1000000)
|
| 135 |
|
| 136 |
# Calculate num_frames from duration (using fixed 24 fps)
|
| 137 |
frame_rate = 24.0
|
|
@@ -160,7 +160,7 @@ def generate_video(
|
|
| 160 |
prompt=prompt,
|
| 161 |
negative_prompt=negative_prompt,
|
| 162 |
output_path=str(output_path),
|
| 163 |
-
seed=
|
| 164 |
height=height,
|
| 165 |
width=width,
|
| 166 |
num_frames=num_frames,
|
|
@@ -171,7 +171,7 @@ def generate_video(
|
|
| 171 |
tiling_config=TilingConfig.default(),
|
| 172 |
)
|
| 173 |
|
| 174 |
-
return str(output_path)
|
| 175 |
|
| 176 |
except Exception as e:
|
| 177 |
import traceback
|
|
@@ -274,7 +274,7 @@ with gr.Blocks(title="LTX-2 Video 🎥🔈") as demo:
|
|
| 274 |
height,
|
| 275 |
width,
|
| 276 |
],
|
| 277 |
-
outputs=output_video
|
| 278 |
)
|
| 279 |
|
| 280 |
# Add example
|
|
@@ -288,7 +288,7 @@ with gr.Blocks(title="LTX-2 Video 🎥🔈") as demo:
|
|
| 288 |
],
|
| 289 |
fn=generate_video,
|
| 290 |
inputs=[input_image, prompt, duration],
|
| 291 |
-
outputs = [output_video],
|
| 292 |
label="Example",
|
| 293 |
cache_examples=True,
|
| 294 |
cache_mode="lazy",
|
|
|
|
| 5 |
current_dir = Path(__file__).parent
|
| 6 |
sys.path.insert(0, str(current_dir / "packages" / "ltx-pipelines" / "src"))
|
| 7 |
sys.path.insert(0, str(current_dir / "packages" / "ltx-core" / "src"))
|
| 8 |
+
import numpy as np
|
| 9 |
+
import random
|
| 10 |
import spaces
|
| 11 |
import gradio as gr
|
| 12 |
from typing import Optional
|
|
|
|
| 24 |
DEFAULT_LORA_STRENGTH,
|
| 25 |
)
|
| 26 |
|
| 27 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 28 |
# Custom negative prompt
|
| 29 |
DEFAULT_NEGATIVE_PROMPT = "shaky, glitchy, low quality, worst quality, deformed, distorted, disfigured, motion smear, motion artifacts, fused fingers, bad anatomy, weird hand, ugly, transition, static"
|
| 30 |
|
|
|
|
| 131 |
"""Generate a video based on the given parameters."""
|
| 132 |
try:
|
| 133 |
# Randomize seed if checkbox is enabled
|
| 134 |
+
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
|
|
|
|
|
|
| 135 |
|
| 136 |
# Calculate num_frames from duration (using fixed 24 fps)
|
| 137 |
frame_rate = 24.0
|
|
|
|
| 160 |
prompt=prompt,
|
| 161 |
negative_prompt=negative_prompt,
|
| 162 |
output_path=str(output_path),
|
| 163 |
+
seed=current_seed,
|
| 164 |
height=height,
|
| 165 |
width=width,
|
| 166 |
num_frames=num_frames,
|
|
|
|
| 171 |
tiling_config=TilingConfig.default(),
|
| 172 |
)
|
| 173 |
|
| 174 |
+
return str(output_path), current_seed
|
| 175 |
|
| 176 |
except Exception as e:
|
| 177 |
import traceback
|
|
|
|
| 274 |
height,
|
| 275 |
width,
|
| 276 |
],
|
| 277 |
+
outputs=[output_video,seed]
|
| 278 |
)
|
| 279 |
|
| 280 |
# Add example
|
|
|
|
| 288 |
],
|
| 289 |
fn=generate_video,
|
| 290 |
inputs=[input_image, prompt, duration],
|
| 291 |
+
outputs = [output_video,seed],
|
| 292 |
label="Example",
|
| 293 |
cache_examples=True,
|
| 294 |
cache_mode="lazy",
|