Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import LTXPipeline
|
4 |
+
from diffusers.utils import export_to_video
|
5 |
+
import tempfile
|
6 |
+
import random
|
7 |
+
|
8 |
+
# Load the LTX Video model
|
9 |
+
pipe = LTXPipeline.from_pretrained("Lightricks/LTX-Video", torch_dtype=torch.bfloat16)
|
10 |
+
pipe.to("cuda")
|
11 |
+
|
12 |
+
def generate_video(prompt, negative_prompt, height, width, num_frames, num_inference_steps, seed):
|
13 |
+
if seed == -1:
|
14 |
+
seed = random.randint(0, 2**32 - 1)
|
15 |
+
|
16 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
17 |
+
|
18 |
+
video = pipe(
|
19 |
+
prompt=prompt,
|
20 |
+
negative_prompt=negative_prompt,
|
21 |
+
height=height,
|
22 |
+
width=width,
|
23 |
+
num_frames=num_frames,
|
24 |
+
num_inference_steps=num_inference_steps,
|
25 |
+
generator=generator
|
26 |
+
).frames[0]
|
27 |
+
|
28 |
+
# Export video to temporary file
|
29 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmpfile:
|
30 |
+
export_to_video(video, tmpfile.name, fps=24)
|
31 |
+
return tmpfile.name
|
32 |
+
|
33 |
+
# Gradio Interface
|
34 |
+
title = "LTX-Video Generator"
|
35 |
+
description = "Generate high-quality videos from text using the Lightricks LTX-Video model."
|
36 |
+
|
37 |
+
with gr.Blocks(title=title) as demo:
|
38 |
+
gr.Markdown(f"## {title}\n{description}")
|
39 |
+
|
40 |
+
with gr.Row():
|
41 |
+
prompt = gr.Textbox(label="Prompt", value="A woman with long brown hair and light skin smiles at another woman...", lines=5)
|
42 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", value="worst quality, inconsistent motion, blurry, jittery, distorted", lines=5)
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
height = gr.Slider(minimum=64, maximum=720, step=32, value=480, label="Height")
|
46 |
+
width = gr.Slider(minimum=64, maximum=1280, step=32, value=704, label="Width")
|
47 |
+
num_frames = gr.Slider(minimum=9, maximum=257, step=8, value=161, label="Number of Frames")
|
48 |
+
num_inference_steps = gr.Slider(minimum=10, maximum=100, step=1, value=50, label="Inference Steps")
|
49 |
+
seed = gr.Number(value=-1, label="Seed (set -1 for random)")
|
50 |
+
|
51 |
+
generate_btn = gr.Button("Generate Video")
|
52 |
+
output_video = gr.Video(label="Generated Video")
|
53 |
+
|
54 |
+
generate_btn.click(
|
55 |
+
fn=generate_video,
|
56 |
+
inputs=[prompt, negative_prompt, height, width, num_frames, num_inference_steps, seed],
|
57 |
+
outputs=output_video
|
58 |
+
)
|
59 |
+
|
60 |
+
demo.launch()
|