Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,9 @@ pipe.to("cuda")
|
|
| 11 |
pipe_upsample.to("cuda")
|
| 12 |
pipe.vae.enable_tiling()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 16 |
height = height - (height % pipe.vae_temporal_compression_ratio)
|
|
@@ -24,12 +27,16 @@ def generate(prompt,
|
|
| 24 |
steps,
|
| 25 |
num_frames,
|
| 26 |
seed,
|
| 27 |
-
randomize_seed
|
|
|
|
| 28 |
|
| 29 |
expected_height, expected_width = 768, 1152
|
| 30 |
downscale_factor = 2 / 3
|
| 31 |
|
| 32 |
-
if
|
|
|
|
|
|
|
|
|
|
| 33 |
condition1 = LTXVideoCondition(video=image, frame_index=0)
|
| 34 |
else:
|
| 35 |
condition1 = None
|
|
@@ -43,8 +50,8 @@ def generate(prompt,
|
|
| 43 |
conditions=condition1,
|
| 44 |
prompt=prompt,
|
| 45 |
negative_prompt=negative_prompt,
|
| 46 |
-
width=downscaled_width,
|
| 47 |
-
height=downscaled_height,
|
| 48 |
num_frames=num_frames,
|
| 49 |
num_inference_steps=steps,
|
| 50 |
decode_timestep = 0.05,
|
|
@@ -55,7 +62,7 @@ def generate(prompt,
|
|
| 55 |
|
| 56 |
# Part 2. Upscale generated video using latent upsampler with fewer inference steps
|
| 57 |
# The available latent upsampler upscales the height/width by 2x
|
| 58 |
-
upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
|
| 59 |
# upscaled_latents = pipe_upsample(
|
| 60 |
# latents=latents,
|
| 61 |
# output_type="latent"
|
|
@@ -112,6 +119,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 112 |
with gr.Group():
|
| 113 |
image = gr.Image(label="")
|
| 114 |
prompt = gr.Textbox(label="prompt")
|
|
|
|
| 115 |
run_button = gr.Button()
|
| 116 |
with gr.Column():
|
| 117 |
output = gr.Video(interactive=False)
|
|
@@ -134,7 +142,7 @@ with gr.Blocks(css=css, theme=gr.themes.Ocean()) as demo:
|
|
| 134 |
steps,
|
| 135 |
num_frames,
|
| 136 |
seed,
|
| 137 |
-
randomize_seed],
|
| 138 |
outputs=[output])
|
| 139 |
|
| 140 |
|
|
|
|
| 11 |
pipe_upsample.to("cuda")
|
| 12 |
pipe.vae.enable_tiling()
|
| 13 |
|
| 14 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 15 |
+
MAX_IMAGE_SIZE = 2048
|
| 16 |
+
|
| 17 |
|
| 18 |
def round_to_nearest_resolution_acceptable_by_vae(height, width):
|
| 19 |
height = height - (height % pipe.vae_temporal_compression_ratio)
|
|
|
|
| 27 |
steps,
|
| 28 |
num_frames,
|
| 29 |
seed,
|
| 30 |
+
randomize_seed,
|
| 31 |
+
t2v, progress=gr.Progress(track_tqdm=True)):
|
| 32 |
|
| 33 |
expected_height, expected_width = 768, 1152
|
| 34 |
downscale_factor = 2 / 3
|
| 35 |
|
| 36 |
+
if randomize_seed:
|
| 37 |
+
seed = random.randint(0, MAX_SEED)
|
| 38 |
+
|
| 39 |
+
if image is not None or t2v:
|
| 40 |
condition1 = LTXVideoCondition(video=image, frame_index=0)
|
| 41 |
else:
|
| 42 |
condition1 = None
|
|
|
|
| 50 |
conditions=condition1,
|
| 51 |
prompt=prompt,
|
| 52 |
negative_prompt=negative_prompt,
|
| 53 |
+
# width=downscaled_width,
|
| 54 |
+
# height=downscaled_height,
|
| 55 |
num_frames=num_frames,
|
| 56 |
num_inference_steps=steps,
|
| 57 |
decode_timestep = 0.05,
|
|
|
|
| 62 |
|
| 63 |
# Part 2. Upscale generated video using latent upsampler with fewer inference steps
|
| 64 |
# The available latent upsampler upscales the height/width by 2x
|
| 65 |
+
# upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
|
| 66 |
# upscaled_latents = pipe_upsample(
|
| 67 |
# latents=latents,
|
| 68 |
# output_type="latent"
|
|
|
|
| 119 |
with gr.Group():
|
| 120 |
image = gr.Image(label="")
|
| 121 |
prompt = gr.Textbox(label="prompt")
|
| 122 |
+
t2v = gr.Checkbox(label="run text-to-video", value=False)
|
| 123 |
run_button = gr.Button()
|
| 124 |
with gr.Column():
|
| 125 |
output = gr.Video(interactive=False)
|
|
|
|
| 142 |
steps,
|
| 143 |
num_frames,
|
| 144 |
seed,
|
| 145 |
+
randomize_seed, t2v],
|
| 146 |
outputs=[output])
|
| 147 |
|
| 148 |
|