Enhance UI for video generation with step-by-step labels and improved layout
Browse files
app.py
CHANGED
@@ -167,13 +167,6 @@ pipeline = XoraVideoPipeline(
|
|
167 |
).to(device)
|
168 |
|
169 |
|
170 |
-
import gradio as gr
|
171 |
-
import torch
|
172 |
-
from huggingface_hub import snapshot_download
|
173 |
-
|
174 |
-
# [Previous imports remain the same...]
|
175 |
-
|
176 |
-
|
177 |
def generate_video_from_text(
|
178 |
prompt="",
|
179 |
negative_prompt="",
|
@@ -309,26 +302,38 @@ def generate_video_from_image(
|
|
309 |
|
310 |
|
311 |
def create_advanced_options():
|
312 |
-
with gr.Accordion("Advanced Options", open=False):
|
313 |
-
seed = gr.Slider(
|
|
|
|
|
314 |
inference_steps = gr.Slider(
|
315 |
-
label="Inference Steps", minimum=1, maximum=100, step=1, value=40
|
316 |
)
|
317 |
images_per_prompt = gr.Slider(
|
318 |
-
label="Images per Prompt", minimum=1, maximum=10, step=1, value=1
|
319 |
)
|
320 |
guidance_scale = gr.Slider(
|
321 |
-
label="Guidance Scale", minimum=1.0, maximum=20.0, step=0.1, value=3.0
|
322 |
)
|
323 |
|
324 |
height_slider = gr.Slider(
|
325 |
-
label="Height",
|
|
|
|
|
|
|
|
|
|
|
326 |
)
|
327 |
width_slider = gr.Slider(
|
328 |
-
label="Width",
|
|
|
|
|
|
|
|
|
|
|
329 |
)
|
330 |
num_frames_slider = gr.Slider(
|
331 |
-
label="Number of Frames",
|
332 |
minimum=1,
|
333 |
maximum=200,
|
334 |
step=1,
|
@@ -336,7 +341,12 @@ def create_advanced_options():
|
|
336 |
visible=False,
|
337 |
)
|
338 |
frame_rate = gr.Slider(
|
339 |
-
label="Frame Rate",
|
|
|
|
|
|
|
|
|
|
|
340 |
)
|
341 |
|
342 |
return [
|
@@ -352,65 +362,80 @@ def create_advanced_options():
|
|
352 |
|
353 |
|
354 |
# Define the Gradio interface with tabs
|
355 |
-
with gr.Blocks() as iface:
|
356 |
gr.Markdown("# Video Generation with LTX Video")
|
357 |
|
358 |
with gr.Tabs():
|
|
|
359 |
with gr.TabItem("Text to Video"):
|
360 |
with gr.Row():
|
361 |
with gr.Column():
|
362 |
txt2vid_prompt = gr.Textbox(
|
363 |
-
label="Prompt",
|
364 |
-
|
|
|
|
|
365 |
)
|
366 |
txt2vid_negative_prompt = gr.Textbox(
|
367 |
-
label="Negative Prompt",
|
|
|
368 |
value="worst quality, inconsistent motion...",
|
|
|
369 |
)
|
370 |
|
371 |
-
# Preset dropdown for resolution and frame settings
|
372 |
txt2vid_preset = gr.Dropdown(
|
373 |
choices=[p["label"] for p in preset_options],
|
374 |
value="1216x704, 41 frames",
|
375 |
-
label="Resolution Preset",
|
376 |
)
|
377 |
|
378 |
txt2vid_advanced = create_advanced_options()
|
379 |
-
txt2vid_generate = gr.Button(
|
|
|
|
|
380 |
|
381 |
with gr.Column():
|
382 |
-
txt2vid_output = gr.Video(label="Generated
|
383 |
|
|
|
384 |
with gr.TabItem("Image to Video"):
|
385 |
with gr.Row():
|
386 |
with gr.Column():
|
387 |
-
img2vid_image = gr.Image(
|
|
|
|
|
|
|
|
|
388 |
img2vid_prompt = gr.Textbox(
|
389 |
-
label="Prompt",
|
390 |
-
|
|
|
|
|
391 |
)
|
392 |
img2vid_negative_prompt = gr.Textbox(
|
393 |
-
label="Negative Prompt",
|
|
|
394 |
value="worst quality, inconsistent motion...",
|
|
|
395 |
)
|
396 |
|
397 |
img2vid_preset = gr.Dropdown(
|
398 |
choices=[p["label"] for p in preset_options],
|
399 |
value="1216x704, 41 frames",
|
400 |
-
label="Resolution Preset",
|
401 |
)
|
402 |
|
403 |
img2vid_advanced = create_advanced_options()
|
404 |
-
img2vid_generate = gr.Button(
|
|
|
|
|
405 |
|
406 |
with gr.Column():
|
407 |
-
img2vid_output = gr.Video(label="Generated
|
408 |
|
409 |
-
#
|
410 |
txt2vid_preset.change(
|
411 |
-
fn=preset_changed,
|
412 |
-
inputs=[txt2vid_preset],
|
413 |
-
outputs=txt2vid_advanced[4:], # height, width, num_frames, and their visibility
|
414 |
)
|
415 |
|
416 |
txt2vid_generate.click(
|
@@ -419,11 +444,8 @@ with gr.Blocks() as iface:
|
|
419 |
outputs=txt2vid_output,
|
420 |
)
|
421 |
|
422 |
-
# Event handlers for image-to-video tab
|
423 |
img2vid_preset.change(
|
424 |
-
fn=preset_changed,
|
425 |
-
inputs=[img2vid_preset],
|
426 |
-
outputs=img2vid_advanced[4:], # height, width, num_frames, and their visibility
|
427 |
)
|
428 |
|
429 |
img2vid_generate.click(
|
|
|
167 |
).to(device)
|
168 |
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
def generate_video_from_text(
|
171 |
prompt="",
|
172 |
negative_prompt="",
|
|
|
302 |
|
303 |
|
304 |
def create_advanced_options():
|
305 |
+
with gr.Accordion("Step 4: Advanced Options (Optional)", open=False):
|
306 |
+
seed = gr.Slider(
|
307 |
+
label="4.1 Seed", minimum=0, maximum=1000000, step=1, value=171198
|
308 |
+
)
|
309 |
inference_steps = gr.Slider(
|
310 |
+
label="4.2 Inference Steps", minimum=1, maximum=100, step=1, value=40
|
311 |
)
|
312 |
images_per_prompt = gr.Slider(
|
313 |
+
label="4.3 Images per Prompt", minimum=1, maximum=10, step=1, value=1
|
314 |
)
|
315 |
guidance_scale = gr.Slider(
|
316 |
+
label="4.4 Guidance Scale", minimum=1.0, maximum=20.0, step=0.1, value=3.0
|
317 |
)
|
318 |
|
319 |
height_slider = gr.Slider(
|
320 |
+
label="4.5 Height",
|
321 |
+
minimum=256,
|
322 |
+
maximum=1024,
|
323 |
+
step=64,
|
324 |
+
value=704,
|
325 |
+
visible=False,
|
326 |
)
|
327 |
width_slider = gr.Slider(
|
328 |
+
label="4.6 Width",
|
329 |
+
minimum=256,
|
330 |
+
maximum=1024,
|
331 |
+
step=64,
|
332 |
+
value=1216,
|
333 |
+
visible=False,
|
334 |
)
|
335 |
num_frames_slider = gr.Slider(
|
336 |
+
label="4.7 Number of Frames",
|
337 |
minimum=1,
|
338 |
maximum=200,
|
339 |
step=1,
|
|
|
341 |
visible=False,
|
342 |
)
|
343 |
frame_rate = gr.Slider(
|
344 |
+
label="4.8 Frame Rate",
|
345 |
+
minimum=1,
|
346 |
+
maximum=60,
|
347 |
+
step=1,
|
348 |
+
value=25,
|
349 |
+
visible=False,
|
350 |
)
|
351 |
|
352 |
return [
|
|
|
362 |
|
363 |
|
364 |
# Define the Gradio interface with tabs
|
365 |
+
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
366 |
gr.Markdown("# Video Generation with LTX Video")
|
367 |
|
368 |
with gr.Tabs():
|
369 |
+
# Text to Video Tab
|
370 |
with gr.TabItem("Text to Video"):
|
371 |
with gr.Row():
|
372 |
with gr.Column():
|
373 |
txt2vid_prompt = gr.Textbox(
|
374 |
+
label="Step 1: Enter Your Prompt",
|
375 |
+
placeholder="Describe the video you want to generate (minimum 50 characters)...",
|
376 |
+
value="A man riding a motorcycle down a winding road, surrounded by lush, green scenery and distant mountains. The sky is clear with a few wispy clouds, and the sunlight glistens on the motorcycle as it speeds along.",
|
377 |
+
lines=5,
|
378 |
)
|
379 |
txt2vid_negative_prompt = gr.Textbox(
|
380 |
+
label="Step 2: Enter Negative Prompt (Optional)",
|
381 |
+
placeholder="Describe what you don't want in the video...",
|
382 |
value="worst quality, inconsistent motion...",
|
383 |
+
lines=2,
|
384 |
)
|
385 |
|
|
|
386 |
txt2vid_preset = gr.Dropdown(
|
387 |
choices=[p["label"] for p in preset_options],
|
388 |
value="1216x704, 41 frames",
|
389 |
+
label="Step 3: Choose Resolution Preset",
|
390 |
)
|
391 |
|
392 |
txt2vid_advanced = create_advanced_options()
|
393 |
+
txt2vid_generate = gr.Button(
|
394 |
+
"Step 5: Generate Video", variant="primary", size="lg"
|
395 |
+
)
|
396 |
|
397 |
with gr.Column():
|
398 |
+
txt2vid_output = gr.Video(label="Step 6: Generated Output")
|
399 |
|
400 |
+
# Image to Video Tab
|
401 |
with gr.TabItem("Image to Video"):
|
402 |
with gr.Row():
|
403 |
with gr.Column():
|
404 |
+
img2vid_image = gr.Image(
|
405 |
+
type="filepath",
|
406 |
+
label="Step 1: Upload Input Image",
|
407 |
+
elem_id="image_upload",
|
408 |
+
)
|
409 |
img2vid_prompt = gr.Textbox(
|
410 |
+
label="Step 2: Enter Your Prompt",
|
411 |
+
placeholder="Describe how you want to animate the image (minimum 50 characters)...",
|
412 |
+
value="A man riding a motorcycle down a winding road, surrounded by lush, green scenery...",
|
413 |
+
lines=5,
|
414 |
)
|
415 |
img2vid_negative_prompt = gr.Textbox(
|
416 |
+
label="Step 3: Enter Negative Prompt (Optional)",
|
417 |
+
placeholder="Describe what you don't want in the video...",
|
418 |
value="worst quality, inconsistent motion...",
|
419 |
+
lines=2,
|
420 |
)
|
421 |
|
422 |
img2vid_preset = gr.Dropdown(
|
423 |
choices=[p["label"] for p in preset_options],
|
424 |
value="1216x704, 41 frames",
|
425 |
+
label="Step 4: Choose Resolution Preset",
|
426 |
)
|
427 |
|
428 |
img2vid_advanced = create_advanced_options()
|
429 |
+
img2vid_generate = gr.Button(
|
430 |
+
"Step 6: Generate Video", variant="primary", size="lg"
|
431 |
+
)
|
432 |
|
433 |
with gr.Column():
|
434 |
+
img2vid_output = gr.Video(label="Step 7: Generated Output")
|
435 |
|
436 |
+
# [Previous event handlers remain the same]
|
437 |
txt2vid_preset.change(
|
438 |
+
fn=preset_changed, inputs=[txt2vid_preset], outputs=txt2vid_advanced[4:]
|
|
|
|
|
439 |
)
|
440 |
|
441 |
txt2vid_generate.click(
|
|
|
444 |
outputs=txt2vid_output,
|
445 |
)
|
446 |
|
|
|
447 |
img2vid_preset.change(
|
448 |
+
fn=preset_changed, inputs=[img2vid_preset], outputs=img2vid_advanced[4:]
|
|
|
|
|
449 |
)
|
450 |
|
451 |
img2vid_generate.click(
|