Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import spaces
|
|
4 |
Copyright NewGenAI
|
5 |
Code can't be included in commercial app used for monetary gain. No derivative code allowed.
|
6 |
"""
|
|
|
7 |
import json
|
8 |
import torch
|
9 |
import tqdm
|
@@ -23,10 +24,6 @@ from huggingface_hub import hf_hub_download
|
|
23 |
STATE_FILE = "LTX091_state.json"
|
24 |
queue = []
|
25 |
|
26 |
-
torch._inductor.config.conv_1x1_as_mm = True
|
27 |
-
torch._inductor.config.coordinate_descent_tuning = True
|
28 |
-
torch._inductor.config.epilogue_fusion = False
|
29 |
-
torch._inductor.config.coordinate_descent_check_all_directions = True
|
30 |
|
31 |
def load_state():
|
32 |
if os.path.exists(STATE_FILE):
|
@@ -144,9 +141,9 @@ except Exception as e:
|
|
144 |
|
145 |
|
146 |
single_file_url = repo_id+"/ltx-video-2b-v0.9.1.safetensors"
|
147 |
-
text_encoder =
|
148 |
repo_id, subfolder="text_encoder", torch_dtype=torch.bfloat16
|
149 |
-
)
|
150 |
tokenizer = T5Tokenizer.from_pretrained(
|
151 |
repo_id, subfolder="tokenizer", torch_dtype=torch.bfloat16
|
152 |
)
|
@@ -162,9 +159,6 @@ pipe.to("cuda")
|
|
162 |
# pipe.load_lora_weights("TODO/TODO", adapter_name="ltx-lora")
|
163 |
# pipe.set_adapters(["lrx-lora"], adapter_weights=[1.0])
|
164 |
|
165 |
-
pipe.vae.decode = torch.compile(pipe.vae.decode, mode="max-autotune", fullgraph=True)
|
166 |
-
pipe.vae = torch.compile(pipe.vae.decode, mode="reduce-overhead", fullgraph=True)
|
167 |
-
|
168 |
@spaces.GPU(duration=120)
|
169 |
@torch.inference_mode()
|
170 |
def generate_video(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed, progress=gr.Progress(track_tqdm=True)):
|
@@ -187,8 +181,10 @@ def generate_video(prompt, negative_prompt, height, width, num_frames, num_infer
|
|
187 |
|
188 |
# Randomize seed if seed is 0
|
189 |
if seed == 0:
|
190 |
-
seed =
|
191 |
-
|
|
|
|
|
192 |
# Generating the video <Does not support seed :( >
|
193 |
video = pipe(
|
194 |
prompt=prompt,
|
@@ -209,7 +205,9 @@ def generate_video(prompt, negative_prompt, height, width, num_frames, num_infer
|
|
209 |
os.makedirs("output_LTX091", exist_ok=True)
|
210 |
output_path = f"./output_LTX091/{filename}"
|
211 |
export_to_video(video, output_path, fps=fps)
|
212 |
-
|
|
|
|
|
213 |
return output_path
|
214 |
|
215 |
# Gradio UI setup
|
@@ -223,13 +221,13 @@ with gr.Blocks() as demo:
|
|
223 |
prompt = gr.Textbox(label="Prompt", lines=3, value=initial_state.get("prompt", "A dramatic view of the pyramids at Giza during sunset."))
|
224 |
negative_prompt = gr.Textbox(label="Negative Prompt", lines=3, value=initial_state.get("negative_prompt", "worst quality, blurry, distorted"))
|
225 |
with gr.Row():
|
226 |
-
height = gr.Slider(label="Height", minimum=
|
227 |
-
width = gr.Slider(label="Width", minimum=320, maximum=
|
228 |
with gr.Row():
|
229 |
-
num_frames = gr.Slider(label="Number of Frames", minimum=1, maximum=
|
230 |
-
num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=
|
231 |
with gr.Row():
|
232 |
-
fps = gr.Slider(label="FPS", minimum=1, maximum=
|
233 |
seed = gr.Number(label="Seed", value=initial_state.get("seed", 0))
|
234 |
random_seed_button = gr.Button("Randomize Seed")
|
235 |
|
@@ -237,7 +235,7 @@ with gr.Blocks() as demo:
|
|
237 |
generate_button = gr.Button("Generate Video")
|
238 |
save_state_button = gr.Button("Save State")
|
239 |
|
240 |
-
random_seed_button.click(
|
241 |
generate_button.click(
|
242 |
generate_video,
|
243 |
inputs=[prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed],
|
@@ -254,13 +252,13 @@ with gr.Blocks() as demo:
|
|
254 |
batch_prompt = gr.Textbox(label="Prompt", lines=3, value="A batch of videos depicting different landscapes.")
|
255 |
batch_negative_prompt = gr.Textbox(label="Negative Prompt", lines=3, value="low quality, inconsistent, jittery")
|
256 |
with gr.Row():
|
257 |
-
batch_height = gr.Slider(label="Height", minimum=
|
258 |
-
batch_width = gr.Slider(label="Width", minimum=320, maximum=
|
259 |
with gr.Row():
|
260 |
-
batch_num_frames = gr.Slider(label="Number of Frames", minimum=1, maximum=
|
261 |
-
batch_num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=
|
262 |
with gr.Row():
|
263 |
-
batch_fps = gr.Slider(label="FPS", minimum=1, maximum=
|
264 |
batch_seed = gr.Number(label="Seed", value=0)
|
265 |
random_seed_batch_button = gr.Button("Randomize Seed")
|
266 |
|
@@ -270,7 +268,7 @@ with gr.Blocks() as demo:
|
|
270 |
|
271 |
queue_status = gr.Text(label="Queue Status")
|
272 |
|
273 |
-
random_seed_batch_button.click(
|
274 |
add_to_queue_button.click(
|
275 |
add_to_queue,
|
276 |
inputs=[batch_prompt, batch_negative_prompt, batch_height, batch_width, batch_num_frames, batch_num_inference_steps, batch_fps, batch_seed],
|
|
|
4 |
Copyright NewGenAI
|
5 |
Code can't be included in commercial app used for monetary gain. No derivative code allowed.
|
6 |
"""
|
7 |
+
import gc
|
8 |
import json
|
9 |
import torch
|
10 |
import tqdm
|
|
|
24 |
STATE_FILE = "LTX091_state.json"
|
25 |
queue = []
|
26 |
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def load_state():
|
29 |
if os.path.exists(STATE_FILE):
|
|
|
141 |
|
142 |
|
143 |
single_file_url = repo_id+"/ltx-video-2b-v0.9.1.safetensors"
|
144 |
+
text_encoder = T5EncoderModel.from_pretrained(
|
145 |
repo_id, subfolder="text_encoder", torch_dtype=torch.bfloat16
|
146 |
+
)
|
147 |
tokenizer = T5Tokenizer.from_pretrained(
|
148 |
repo_id, subfolder="tokenizer", torch_dtype=torch.bfloat16
|
149 |
)
|
|
|
159 |
# pipe.load_lora_weights("TODO/TODO", adapter_name="ltx-lora")
|
160 |
# pipe.set_adapters(["lrx-lora"], adapter_weights=[1.0])
|
161 |
|
|
|
|
|
|
|
162 |
@spaces.GPU(duration=120)
|
163 |
@torch.inference_mode()
|
164 |
def generate_video(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed, progress=gr.Progress(track_tqdm=True)):
|
|
|
181 |
|
182 |
# Randomize seed if seed is 0
|
183 |
if seed == 0:
|
184 |
+
seed = randomize_seed()
|
185 |
+
|
186 |
+
torch.cuda.empty_cache()
|
187 |
+
torch.cuda.synchronize()
|
188 |
# Generating the video <Does not support seed :( >
|
189 |
video = pipe(
|
190 |
prompt=prompt,
|
|
|
205 |
os.makedirs("output_LTX091", exist_ok=True)
|
206 |
output_path = f"./output_LTX091/{filename}"
|
207 |
export_to_video(video, output_path, fps=fps)
|
208 |
+
|
209 |
+
torch.cuda.empty_cache()
|
210 |
+
gc.collect()
|
211 |
return output_path
|
212 |
|
213 |
# Gradio UI setup
|
|
|
221 |
prompt = gr.Textbox(label="Prompt", lines=3, value=initial_state.get("prompt", "A dramatic view of the pyramids at Giza during sunset."))
|
222 |
negative_prompt = gr.Textbox(label="Negative Prompt", lines=3, value=initial_state.get("negative_prompt", "worst quality, blurry, distorted"))
|
223 |
with gr.Row():
|
224 |
+
height = gr.Slider(label="Height", minimum=224, maximum=720, step=1, value=initial_state.get("height", 384))
|
225 |
+
width = gr.Slider(label="Width", minimum=320, maximum=1280, step=1, value=initial_state.get("width", 640))
|
226 |
with gr.Row():
|
227 |
+
num_frames = gr.Slider(label="Number of Frames", minimum=1, maximum=121, step=1, value=initial_state.get("num_frames", 49))
|
228 |
+
num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=30, step=1, value=initial_state.get("num_inference_steps", 20))
|
229 |
with gr.Row():
|
230 |
+
fps = gr.Slider(label="FPS", minimum=1, maximum=30, step=1, value=initial_state.get("fps", 16))
|
231 |
seed = gr.Number(label="Seed", value=initial_state.get("seed", 0))
|
232 |
random_seed_button = gr.Button("Randomize Seed")
|
233 |
|
|
|
235 |
generate_button = gr.Button("Generate Video")
|
236 |
save_state_button = gr.Button("Save State")
|
237 |
|
238 |
+
random_seed_button.click(randomize_seed, outputs=seed)
|
239 |
generate_button.click(
|
240 |
generate_video,
|
241 |
inputs=[prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed],
|
|
|
252 |
batch_prompt = gr.Textbox(label="Prompt", lines=3, value="A batch of videos depicting different landscapes.")
|
253 |
batch_negative_prompt = gr.Textbox(label="Negative Prompt", lines=3, value="low quality, inconsistent, jittery")
|
254 |
with gr.Row():
|
255 |
+
batch_height = gr.Slider(label="Height", minimum=224, maximum=720, step=1, value=384)
|
256 |
+
batch_width = gr.Slider(label="Width", minimum=320, maximum=1280, step=1, value=640)
|
257 |
with gr.Row():
|
258 |
+
batch_num_frames = gr.Slider(label="Number of Frames", minimum=1, maximum=121, step=1, value=49)
|
259 |
+
batch_num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=30, step=1, value=20)
|
260 |
with gr.Row():
|
261 |
+
batch_fps = gr.Slider(label="FPS", minimum=1, maximum=30, step=1, value=16)
|
262 |
batch_seed = gr.Number(label="Seed", value=0)
|
263 |
random_seed_batch_button = gr.Button("Randomize Seed")
|
264 |
|
|
|
268 |
|
269 |
queue_status = gr.Text(label="Queue Status")
|
270 |
|
271 |
+
random_seed_batch_button.click(randomize_seed, outputs=batch_seed)
|
272 |
add_to_queue_button.click(
|
273 |
add_to_queue,
|
274 |
inputs=[batch_prompt, batch_negative_prompt, batch_height, batch_width, batch_num_frames, batch_num_inference_steps, batch_fps, batch_seed],
|