Spaces:
Running
on
Zero
Running
on
Zero
ui changes part 1
Browse files
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
|
@@ -175,9 +199,9 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
175 |
video_n_hidden = gr.Textbox(label="video_n", visible=False, value=None)
|
176 |
t2v_prompt = gr.Textbox(label="Prompt", value="A majestic dragon flying over a medieval castle", lines=3)
|
177 |
t2v_button = gr.Button("Generate Text-to-Video", variant="primary")
|
178 |
-
with gr.Tab("video-to-video"
|
179 |
image_v_hidden = gr.Textbox(label="image_v", visible=False, value=None)
|
180 |
-
video_v2v = gr.Video(label="Input Video"
|
181 |
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.")
|
182 |
v2v_prompt = gr.Textbox(label="Prompt", value="Change the style to cinematic anime", lines=3)
|
183 |
v2v_button = gr.Button("Generate Video-to-Video", variant="primary")
|
@@ -205,7 +229,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
205 |
with gr.Row():
|
206 |
guidance_scale= gr.Slider(label="guidance scale", minimum=0, maximum=10, value=1, step=1)
|
207 |
steps = gr.Slider(label="Steps", minimum=1, maximum=30, value=8, step=1)
|
208 |
-
num_frames = gr.Slider(label="# frames", minimum=1, maximum=161, value=96, step=1)
|
209 |
with gr.Row():
|
210 |
height = gr.Slider(label="height", value=512, step=1, maximum=2048)
|
211 |
width = gr.Slider(label="width", value=704, step=1, maximum=2048)
|
@@ -213,8 +237,8 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
213 |
t2v_button.click(fn=generate,
|
214 |
inputs=[t2v_prompt,
|
215 |
negative_prompt,
|
216 |
-
|
217 |
-
|
218 |
height,
|
219 |
width,
|
220 |
gr.State("text-to-video"),
|
@@ -222,14 +246,14 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
222 |
num_frames,
|
223 |
frames_to_use,
|
224 |
seed,
|
225 |
-
randomize_seed,guidance_scale, improve_texture],
|
226 |
outputs=[output])
|
227 |
|
228 |
i2v_button.click(fn=generate,
|
229 |
inputs=[i2v_prompt,
|
230 |
negative_prompt,
|
231 |
-
|
232 |
-
|
233 |
height,
|
234 |
width,
|
235 |
gr.State("image-to-video"),
|
@@ -237,14 +261,14 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
237 |
num_frames,
|
238 |
frames_to_use,
|
239 |
seed,
|
240 |
-
randomize_seed,guidance_scale, improve_texture],
|
241 |
outputs=[output])
|
242 |
|
243 |
v2v_button.click(fn=generate,
|
244 |
inputs=[v2v_prompt,
|
245 |
negative_prompt,
|
246 |
-
|
247 |
-
|
248 |
height,
|
249 |
width,
|
250 |
gr.State("video-to-video"),
|
@@ -252,7 +276,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
252 |
num_frames,
|
253 |
frames_to_use,
|
254 |
seed,
|
255 |
-
randomize_seed,guidance_scale, improve_texture],
|
256 |
outputs=[output])
|
257 |
|
258 |
|
|
|
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
|
|
|
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")
|
|
|
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 |
|