Spaces:
Running
on
Zero
Running
on
Zero
revise ui from Lightricks/ltx-video-distilled (#3)
Browse files- revise ui from Lightricks/ltx-video-distilled (0dcc0bdac16da93c8d5fe44594e010baab8d5909)
- Delete pipeline_ltx_condition.py (433ae54ab7775b637c6b7a5ea236d31ee268c14d)
- ui changes part 1 (84bff9fe4140bd320824f0edd1d4924b04219022)
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
-
# from pipeline_ltx_condition import LTXVideoCondition, LTXConditionPipeline
|
| 5 |
-
# from diffusers import LTXLatentUpsamplePipeline
|
| 6 |
from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
|
| 7 |
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
|
| 8 |
from diffusers.utils import export_to_video, load_video, load_image
|
|
@@ -26,8 +24,28 @@ def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
|
| 26 |
width = width - (width % pipe.vae_spatial_compression_ratio)
|
| 27 |
print("after rounding",height, width)
|
| 28 |
return height, width
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
@spaces.GPU
|
| 31 |
def generate(prompt,
|
| 32 |
negative_prompt,
|
| 33 |
image,
|
|
@@ -47,12 +65,18 @@ def generate(prompt,
|
|
| 47 |
if randomize_seed:
|
| 48 |
seed = random.randint(0, MAX_SEED)
|
| 49 |
|
|
|
|
| 50 |
target_frames_ideal = duration_input * FPS
|
| 51 |
-
|
| 52 |
-
if
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
print(mode)
|
| 56 |
if mode == "video-to-video" and (video is not None):
|
| 57 |
video = load_video(video)[:frames_to_use]
|
| 58 |
condition = True
|
|
@@ -161,25 +185,28 @@ function refresh() {
|
|
| 161 |
with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
| 162 |
|
| 163 |
gr.Markdown("# LTX Video 0.9.7 Distilled")
|
|
|
|
|
|
|
| 164 |
with gr.Row():
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
| 183 |
label="Video Duration (seconds)",
|
| 184 |
minimum=0.3,
|
| 185 |
maximum=8.5,
|
|
@@ -187,9 +214,11 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 187 |
step=0.1,
|
| 188 |
info=f"Target video duration (0.3s to 8.5s)"
|
| 189 |
)
|
|
|
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|
|
|
|
| 193 |
|
| 194 |
|
| 195 |
with gr.Accordion("Advanced settings", open=False):
|
|
@@ -200,7 +229,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 200 |
with gr.Row():
|
| 201 |
guidance_scale= gr.Slider(label="guidance scale", minimum=0, maximum=10, value=1, step=1)
|
| 202 |
steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)
|
| 203 |
-
num_frames = gr.Slider(label="# frames", minimum=1, maximum=161, value=96, step=1)
|
| 204 |
with gr.Row():
|
| 205 |
height = gr.Slider(label="height", value=512, step=1, maximum=2048)
|
| 206 |
width = gr.Slider(label="width", value=704, step=1, maximum=2048)
|
|
@@ -208,8 +237,8 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 208 |
t2v_button.click(fn=generate,
|
| 209 |
inputs=[t2v_prompt,
|
| 210 |
negative_prompt,
|
| 211 |
-
|
| 212 |
-
|
| 213 |
height,
|
| 214 |
width,
|
| 215 |
gr.State("text-to-video"),
|
|
@@ -217,14 +246,14 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 217 |
num_frames,
|
| 218 |
frames_to_use,
|
| 219 |
seed,
|
| 220 |
-
randomize_seed,guidance_scale, improve_texture],
|
| 221 |
outputs=[output])
|
| 222 |
|
| 223 |
i2v_button.click(fn=generate,
|
| 224 |
inputs=[i2v_prompt,
|
| 225 |
negative_prompt,
|
| 226 |
-
|
| 227 |
-
|
| 228 |
height,
|
| 229 |
width,
|
| 230 |
gr.State("image-to-video"),
|
|
@@ -232,14 +261,14 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 232 |
num_frames,
|
| 233 |
frames_to_use,
|
| 234 |
seed,
|
| 235 |
-
randomize_seed,guidance_scale, improve_texture],
|
| 236 |
outputs=[output])
|
| 237 |
|
| 238 |
v2v_button.click(fn=generate,
|
| 239 |
inputs=[v2v_prompt,
|
| 240 |
negative_prompt,
|
| 241 |
-
|
| 242 |
-
|
| 243 |
height,
|
| 244 |
width,
|
| 245 |
gr.State("video-to-video"),
|
|
@@ -247,7 +276,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 247 |
num_frames,
|
| 248 |
frames_to_use,
|
| 249 |
seed,
|
| 250 |
-
randomize_seed,guidance_scale, improve_texture],
|
| 251 |
outputs=[output])
|
| 252 |
|
| 253 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
|
|
|
|
|
|
| 4 |
from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
|
| 5 |
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
|
| 6 |
from diffusers.utils import export_to_video, load_video, load_image
|
|
|
|
| 24 |
width = width - (width % pipe.vae_spatial_compression_ratio)
|
| 25 |
print("after rounding",height, width)
|
| 26 |
return height, width
|
| 27 |
+
|
| 28 |
+
def get_duration(prompt,
|
| 29 |
+
negative_prompt,
|
| 30 |
+
image,
|
| 31 |
+
video,
|
| 32 |
+
height,
|
| 33 |
+
width,
|
| 34 |
+
mode,
|
| 35 |
+
steps,
|
| 36 |
+
num_frames,
|
| 37 |
+
frames_to_use,
|
| 38 |
+
seed,
|
| 39 |
+
randomize_seed,
|
| 40 |
+
guidance_scale,
|
| 41 |
+
duration_input,
|
| 42 |
+
improve_texture, progress):
|
| 43 |
+
if duration_input > 7:
|
| 44 |
+
return 75
|
| 45 |
+
else:
|
| 46 |
+
return 60
|
| 47 |
|
| 48 |
+
@spaces.GPU(duration=get_duration)
|
| 49 |
def generate(prompt,
|
| 50 |
negative_prompt,
|
| 51 |
image,
|
|
|
|
| 65 |
if randomize_seed:
|
| 66 |
seed = random.randint(0, MAX_SEED)
|
| 67 |
|
| 68 |
+
# calculate number of frames based on the duration input in seconds
|
| 69 |
target_frames_ideal = duration_input * FPS
|
| 70 |
+
target_frames_rounded = round(target_frames_ideal)
|
| 71 |
+
if target_frames_rounded < 1:
|
| 72 |
+
target_frames_rounded = 1
|
| 73 |
+
|
| 74 |
+
n_val = round((float(target_frames_rounded) - 1.0) / 8.0)
|
| 75 |
+
actual_num_frames = int(n_val * 8 + 1)
|
| 76 |
+
|
| 77 |
+
actual_num_frames = max(9, actual_num_frames)
|
| 78 |
+
num_frames = min(MAX_NUM_FRAMES, actual_num_frames)
|
| 79 |
|
|
|
|
| 80 |
if mode == "video-to-video" and (video is not None):
|
| 81 |
video = load_video(video)[:frames_to_use]
|
| 82 |
condition = True
|
|
|
|
| 185 |
with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
| 186 |
|
| 187 |
gr.Markdown("# LTX Video 0.9.7 Distilled")
|
| 188 |
+
gr.Markdown("Fast high quality video generation. [Model](https://huggingface.co/Lightricks/LTX-Video/blob/main/ltxv-13b-0.9.7-distilled.safetensors) [GitHub](https://github.com/Lightricks/LTX-Video) [Diffusers](#)")
|
| 189 |
+
|
| 190 |
with gr.Row():
|
| 191 |
+
with gr.Column():
|
| 192 |
+
with gr.Tab("image-to-video") as image_tab:
|
| 193 |
+
video_i_hidden = gr.Textbox(label="video_i", visible=False, value=None)
|
| 194 |
+
image_i2v = gr.Image(label="Input Image", type="filepath", sources=["upload", "webcam", "clipboard"])
|
| 195 |
+
i2v_prompt = gr.Textbox(label="Prompt", value="The creature from the image starts to move", lines=3)
|
| 196 |
+
i2v_button = gr.Button("Generate Image-to-Video", variant="primary")
|
| 197 |
+
with gr.Tab("text-to-video") as text_tab:
|
| 198 |
+
image_n_hidden = gr.Textbox(label="image_n", visible=False, value=None)
|
| 199 |
+
video_n_hidden = gr.Textbox(label="video_n", visible=False, value=None)
|
| 200 |
+
t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3)
|
| 201 |
+
t2v_button = gr.Button("Generate Text-to-Video", variant="primary")
|
| 202 |
+
with gr.Tab("video-to-video") as video_tab:
|
| 203 |
+
image_v_hidden = gr.Textbox(label="image_v", visible=False, value=None)
|
| 204 |
+
video_v2v = gr.Video(label="Input Video")
|
| 205 |
+
frames_to_use = gr.Slider(label="Frames to use from input video", minimum=9, maximum=MAX_NUM_FRAMES, value=9, step=8, info="Number of initial frames to use for conditioning/transformation. Must be N*8+1.")
|
| 206 |
+
v2v_prompt = gr.Textbox(label="Prompt", value="Change the style to cinematic anime", lines=3)
|
| 207 |
+
v2v_button = gr.Button("Generate Video-to-Video", variant="primary")
|
| 208 |
+
|
| 209 |
+
duration_input = gr.Slider(
|
| 210 |
label="Video Duration (seconds)",
|
| 211 |
minimum=0.3,
|
| 212 |
maximum=8.5,
|
|
|
|
| 214 |
step=0.1,
|
| 215 |
info=f"Target video duration (0.3s to 8.5s)"
|
| 216 |
)
|
| 217 |
+
improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True, info="Uses a two-pass generation for better quality, but is slower. Recommended for final output.")
|
| 218 |
|
| 219 |
+
with gr.Column():
|
| 220 |
+
output_video = gr.Video(label="Generated Video", interactive=False)
|
| 221 |
+
gr.DeepLinkButton()
|
| 222 |
|
| 223 |
|
| 224 |
with gr.Accordion("Advanced settings", open=False):
|
|
|
|
| 229 |
with gr.Row():
|
| 230 |
guidance_scale= gr.Slider(label="guidance scale", minimum=0, maximum=10, value=1, step=1)
|
| 231 |
steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)
|
| 232 |
+
num_frames = gr.Slider(label="# frames", minimum=1, maximum=161, value=96, step=1, visible=False)
|
| 233 |
with gr.Row():
|
| 234 |
height = gr.Slider(label="height", value=512, step=1, maximum=2048)
|
| 235 |
width = gr.Slider(label="width", value=704, step=1, maximum=2048)
|
|
|
|
| 237 |
t2v_button.click(fn=generate,
|
| 238 |
inputs=[t2v_prompt,
|
| 239 |
negative_prompt,
|
| 240 |
+
image_n_hidden,
|
| 241 |
+
video_n_hidden,
|
| 242 |
height,
|
| 243 |
width,
|
| 244 |
gr.State("text-to-video"),
|
|
|
|
| 246 |
num_frames,
|
| 247 |
frames_to_use,
|
| 248 |
seed,
|
| 249 |
+
randomize_seed,guidance_scale, duration_input, improve_texture],
|
| 250 |
outputs=[output])
|
| 251 |
|
| 252 |
i2v_button.click(fn=generate,
|
| 253 |
inputs=[i2v_prompt,
|
| 254 |
negative_prompt,
|
| 255 |
+
image_i2v,
|
| 256 |
+
video_i_hidden,
|
| 257 |
height,
|
| 258 |
width,
|
| 259 |
gr.State("image-to-video"),
|
|
|
|
| 261 |
num_frames,
|
| 262 |
frames_to_use,
|
| 263 |
seed,
|
| 264 |
+
randomize_seed,guidance_scale, duration_input, improve_texture],
|
| 265 |
outputs=[output])
|
| 266 |
|
| 267 |
v2v_button.click(fn=generate,
|
| 268 |
inputs=[v2v_prompt,
|
| 269 |
negative_prompt,
|
| 270 |
+
image_v_hidden,
|
| 271 |
+
video_v2v,
|
| 272 |
height,
|
| 273 |
width,
|
| 274 |
gr.State("video-to-video"),
|
|
|
|
| 276 |
num_frames,
|
| 277 |
frames_to_use,
|
| 278 |
seed,
|
| 279 |
+
randomize_seed,guidance_scale, duration_input, improve_texture],
|
| 280 |
outputs=[output])
|
| 281 |
|
| 282 |
|