Spaces:
Paused
Paused
Update api/ltx_server_refactored.py
Browse files- api/ltx_server_refactored.py +18 -13
api/ltx_server_refactored.py
CHANGED
|
@@ -235,7 +235,7 @@ class VideoService:
|
|
| 235 |
t0 = time.perf_counter()
|
| 236 |
print("[INFO] Inicializando VideoService...")
|
| 237 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 238 |
-
self.config = self._load_config("ltxv-13b-0.9.8-
|
| 239 |
|
| 240 |
self.pipeline, self.latent_upsampler = self._load_models_from_hub()
|
| 241 |
self._move_models_to_device()
|
|
@@ -487,7 +487,7 @@ class VideoService:
|
|
| 487 |
|
| 488 |
# --- Configuração de Seed e Diretórios ---
|
| 489 |
used_seed = random.randint(0, 2**32 - 1) if seed is None else int(seed)
|
| 490 |
-
|
| 491 |
print(f" - Usando Seed: {used_seed}")
|
| 492 |
|
| 493 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_low_")
|
|
@@ -495,12 +495,11 @@ class VideoService:
|
|
| 495 |
results_dir = "/app/output"
|
| 496 |
os.makedirs(results_dir, exist_ok=True)
|
| 497 |
|
| 498 |
-
# --- Cálculo de
|
| 499 |
actual_num_frames = int(round(duration_secs * DEFAULT_FPS))
|
| 500 |
-
downscaled_height = height
|
| 501 |
-
downscaled_width = width
|
| 502 |
-
#self._calculate_downscaled_dims(height, width)
|
| 503 |
|
|
|
|
| 504 |
|
| 505 |
print(f" - Frames: {actual_num_frames}, Duração: {duration_secs}s")
|
| 506 |
print(f" - Dimensões de Saída: {downscaled_height}x{downscaled_width}")
|
|
@@ -513,7 +512,7 @@ class VideoService:
|
|
| 513 |
"negative_prompt": negative_prompt,
|
| 514 |
"height": downscaled_height,
|
| 515 |
"width": downscaled_width,
|
| 516 |
-
"num_frames":
|
| 517 |
"frame_rate": int(DEFAULT_FPS),
|
| 518 |
"generator": torch.Generator(device=self.device).manual_seed(used_seed),
|
| 519 |
"output_type": "latent",
|
|
@@ -536,6 +535,9 @@ class VideoService:
|
|
| 536 |
self._finalize()
|
| 537 |
|
| 538 |
final_video_path, final_latents_path = self.refine_texture_only(
|
|
|
|
|
|
|
|
|
|
| 539 |
latents_path=tensor_path,
|
| 540 |
prompt=prompt,
|
| 541 |
negative_prompt=negative_prompt,
|
|
@@ -553,6 +555,7 @@ class VideoService:
|
|
| 553 |
|
| 554 |
def refine_texture_only(
|
| 555 |
self,
|
|
|
|
| 556 |
latents_path: str,
|
| 557 |
prompt: str,
|
| 558 |
negative_prompt: str,
|
|
@@ -568,8 +571,8 @@ class VideoService:
|
|
| 568 |
print("[INFO] Iniciando ETAPA 2: Refinamento de Textura...")
|
| 569 |
|
| 570 |
# --- Configuração de Seed e Diretórios ---
|
| 571 |
-
used_seed =
|
| 572 |
-
|
| 573 |
print(f" - Usando Seed (consistente com Etapa 1): {used_seed}")
|
| 574 |
|
| 575 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_refine_single_")
|
|
@@ -592,10 +595,10 @@ class VideoService:
|
|
| 592 |
second_pass_kwargs = {
|
| 593 |
"prompt": prompt,
|
| 594 |
"negative_prompt": negative_prompt,
|
| 595 |
-
"height":
|
| 596 |
-
"width":
|
| 597 |
"frame_rate": int(DEFAULT_FPS),
|
| 598 |
-
"num_frames":
|
| 599 |
"latents": latents_to_refine, # O tensor completo é passado aqui
|
| 600 |
"guidance_scale": float(guidance_scale),
|
| 601 |
"output_type": "latent",
|
|
@@ -607,7 +610,9 @@ class VideoService:
|
|
| 607 |
print(" - Enviando tensor completo para a pipeline de refinamento...")
|
| 608 |
final_latents = self.pipeline(**second_pass_kwargs).images
|
| 609 |
print(f" - Latentes refinados com shape: {final_latents.shape}")
|
| 610 |
-
|
|
|
|
|
|
|
| 611 |
# Decodifica os latentes refinados para pixels
|
| 612 |
pixel_tensor = vae_manager_singleton.decode(final_latents, decode_timestep=float(self.config.get("decode_timestep", 0.05)))
|
| 613 |
|
|
|
|
| 235 |
t0 = time.perf_counter()
|
| 236 |
print("[INFO] Inicializando VideoService...")
|
| 237 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 238 |
+
self.config = self._load_config("ltxv-13b-0.9.8-dev-fp8.yaml")
|
| 239 |
|
| 240 |
self.pipeline, self.latent_upsampler = self._load_models_from_hub()
|
| 241 |
self._move_models_to_device()
|
|
|
|
| 487 |
|
| 488 |
# --- Configuração de Seed e Diretórios ---
|
| 489 |
used_seed = random.randint(0, 2**32 - 1) if seed is None else int(seed)
|
| 490 |
+
self._seed_everething(used_seed)
|
| 491 |
print(f" - Usando Seed: {used_seed}")
|
| 492 |
|
| 493 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_low_")
|
|
|
|
| 495 |
results_dir = "/app/output"
|
| 496 |
os.makedirs(results_dir, exist_ok=True)
|
| 497 |
|
| 498 |
+
# --- Cálculo de Dimen.sões e Frames ---
|
| 499 |
actual_num_frames = int(round(duration_secs * DEFAULT_FPS))
|
| 500 |
+
downscaled_height, downscaled_width = self._calculate_downscaled_dims(height, width)
|
|
|
|
|
|
|
| 501 |
|
| 502 |
+
num_frames = (actual_num_frames//8)+1
|
| 503 |
|
| 504 |
print(f" - Frames: {actual_num_frames}, Duração: {duration_secs}s")
|
| 505 |
print(f" - Dimensões de Saída: {downscaled_height}x{downscaled_width}")
|
|
|
|
| 512 |
"negative_prompt": negative_prompt,
|
| 513 |
"height": downscaled_height,
|
| 514 |
"width": downscaled_width,
|
| 515 |
+
"num_frames": num_frames,
|
| 516 |
"frame_rate": int(DEFAULT_FPS),
|
| 517 |
"generator": torch.Generator(device=self.device).manual_seed(used_seed),
|
| 518 |
"output_type": "latent",
|
|
|
|
| 535 |
self._finalize()
|
| 536 |
|
| 537 |
final_video_path, final_latents_path = self.refine_texture_only(
|
| 538 |
+
height=downscaled_height,
|
| 539 |
+
width=downscaled_width,
|
| 540 |
+
num_frames=num_frames,
|
| 541 |
latents_path=tensor_path,
|
| 542 |
prompt=prompt,
|
| 543 |
negative_prompt=negative_prompt,
|
|
|
|
| 555 |
|
| 556 |
def refine_texture_only(
|
| 557 |
self,
|
| 558 |
+
height, width, num_frames,
|
| 559 |
latents_path: str,
|
| 560 |
prompt: str,
|
| 561 |
negative_prompt: str,
|
|
|
|
| 571 |
print("[INFO] Iniciando ETAPA 2: Refinamento de Textura...")
|
| 572 |
|
| 573 |
# --- Configuração de Seed e Diretórios ---
|
| 574 |
+
used_seed = seed
|
| 575 |
+
self._seed_everething(used_seed)
|
| 576 |
print(f" - Usando Seed (consistente com Etapa 1): {used_seed}")
|
| 577 |
|
| 578 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_refine_single_")
|
|
|
|
| 595 |
second_pass_kwargs = {
|
| 596 |
"prompt": prompt,
|
| 597 |
"negative_prompt": negative_prompt,
|
| 598 |
+
"height": height,
|
| 599 |
+
"width": width,
|
| 600 |
"frame_rate": int(DEFAULT_FPS),
|
| 601 |
+
"num_frames": num_frames,
|
| 602 |
"latents": latents_to_refine, # O tensor completo é passado aqui
|
| 603 |
"guidance_scale": float(guidance_scale),
|
| 604 |
"output_type": "latent",
|
|
|
|
| 610 |
print(" - Enviando tensor completo para a pipeline de refinamento...")
|
| 611 |
final_latents = self.pipeline(**second_pass_kwargs).images
|
| 612 |
print(f" - Latentes refinados com shape: {final_latents.shape}")
|
| 613 |
+
|
| 614 |
+
final_latents_filter = adain_filter_latent(latents=final_latents, reference_latents=latents_to_refine)
|
| 615 |
+
|
| 616 |
# Decodifica os latentes refinados para pixels
|
| 617 |
pixel_tensor = vae_manager_singleton.decode(final_latents, decode_timestep=float(self.config.get("decode_timestep", 0.05)))
|
| 618 |
|