Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ Code can't be included in commercial app used for monetary gain. No derivative c
|
|
6 |
"""
|
7 |
import json
|
8 |
import torch
|
|
|
9 |
import gradio as gr
|
10 |
import random
|
11 |
import time
|
@@ -22,6 +23,11 @@ from huggingface_hub import hf_hub_download
|
|
22 |
STATE_FILE = "LTX091_state.json"
|
23 |
queue = []
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
def load_state():
|
26 |
if os.path.exists(STATE_FILE):
|
27 |
with open(STATE_FILE, "r") as file:
|
@@ -58,11 +64,12 @@ def process_queue():
|
|
58 |
if not queue:
|
59 |
return "Queue is empty."
|
60 |
|
61 |
-
for i, task in enumerate(queue):
|
62 |
generate_video(**task)
|
63 |
time.sleep(1) # Simulate processing time
|
64 |
|
65 |
queue.clear()
|
|
|
66 |
return "All tasks in the queue have been processed."
|
67 |
|
68 |
def save_ui_state(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
@@ -149,11 +156,39 @@ pipe = LTXPipeline.from_single_file(
|
|
149 |
tokenizer=tokenizer,
|
150 |
torch_dtype=torch.bfloat16
|
151 |
)
|
152 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
-
@spaces.GPU(duration=120)
|
155 |
@torch.inference_mode()
|
156 |
def generate_video(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
# Randomize seed if seed is 0
|
158 |
if seed == 0:
|
159 |
seed = random.randint(0, 999999)
|
@@ -167,6 +202,7 @@ def generate_video(prompt, negative_prompt, height, width, num_frames, num_infer
|
|
167 |
num_frames=num_frames,
|
168 |
num_inference_steps=num_inference_steps,
|
169 |
generator=torch.Generator(device='cuda').manual_seed(seed),
|
|
|
170 |
).frames[0]
|
171 |
|
172 |
# Create output filename based on prompt and timestamp
|
|
|
6 |
"""
|
7 |
import json
|
8 |
import torch
|
9 |
+
import tqdm
|
10 |
import gradio as gr
|
11 |
import random
|
12 |
import time
|
|
|
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):
|
33 |
with open(STATE_FILE, "r") as file:
|
|
|
64 |
if not queue:
|
65 |
return "Queue is empty."
|
66 |
|
67 |
+
for i, task in tqdm(enumerate(queue)):
|
68 |
generate_video(**task)
|
69 |
time.sleep(1) # Simulate processing time
|
70 |
|
71 |
queue.clear()
|
72 |
+
tqdm.close()
|
73 |
return "All tasks in the queue have been processed."
|
74 |
|
75 |
def save_ui_state(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
|
|
156 |
tokenizer=tokenizer,
|
157 |
torch_dtype=torch.bfloat16
|
158 |
)
|
159 |
+
pipe.vae.enable_tiling()
|
160 |
+
pipe.to("cuda")
|
161 |
+
|
162 |
+
# pipe.load_lora_weights("TODO/TODO", adapter_name="ltx-lora")
|
163 |
+
# pipe.set_adapters(["lrx-lora"], adapter_weights=[1.0])
|
164 |
+
|
165 |
+
pipe.fuse_qkv_projections()
|
166 |
+
|
167 |
+
pipe.unet.to(memory_format=torch.channels_last)
|
168 |
+
pipe.vae.to(memory_format=torch.channels_last)
|
169 |
+
pipe.unet = torch.compile(pipe.unet, mode="max-autotune", fullgraph=True)
|
170 |
+
pipe.vae.decode = torch.compile(pipe.vae.decode, mode="max-autotune", fullgraph=True)
|
171 |
|
172 |
+
@spaces.GPU(duration=120, progress=gr.Progress(track_tqdm=True))
|
173 |
@torch.inference_mode()
|
174 |
def generate_video(prompt, negative_prompt, height, width, num_frames, num_inference_steps, fps, seed):
|
175 |
+
progress_steps = []
|
176 |
+
|
177 |
+
def setup_progressbar_length(_num_steps=num_inference_steps):
|
178 |
+
for _step in bytes(range(_num_steps)):
|
179 |
+
progress_steps.append(_step) # one step one byte - fq the logic
|
180 |
+
|
181 |
+
def progress_step():
|
182 |
+
if len(progress_steps) == 0:
|
183 |
+
return
|
184 |
+
for done_step in tqdm(enumerate(range(len(progress_steps)))):
|
185 |
+
progress_steps.pop()
|
186 |
+
if len(progress_steps) == 0:
|
187 |
+
tqdm.close()
|
188 |
+
break
|
189 |
+
|
190 |
+
setup_progressbar_length()
|
191 |
+
|
192 |
# Randomize seed if seed is 0
|
193 |
if seed == 0:
|
194 |
seed = random.randint(0, 999999)
|
|
|
202 |
num_frames=num_frames,
|
203 |
num_inference_steps=num_inference_steps,
|
204 |
generator=torch.Generator(device='cuda').manual_seed(seed),
|
205 |
+
callback_on_step_end=progress_step
|
206 |
).frames[0]
|
207 |
|
208 |
# Create output filename based on prompt and timestamp
|