Update api/ltx_server_refactored.py
Browse files- api/ltx_server_refactored.py +20 -27
api/ltx_server_refactored.py
CHANGED
|
@@ -37,8 +37,6 @@ from safetensors import safe_open
|
|
| 37 |
from managers.vae_manager import vae_manager_singleton
|
| 38 |
from tools.video_encode_tool import video_encode_tool_singleton
|
| 39 |
|
| 40 |
-
from api.aduc_ltx_latent_patch import LTXLatentConditioningPatch, PatchedConditioningItem
|
| 41 |
-
|
| 42 |
# --- Constantes Globais ---
|
| 43 |
LTXV_DEBUG = True # Mude para False para desativar logs de debug
|
| 44 |
LTXV_FRAME_LOG_EVERY = 8
|
|
@@ -305,7 +303,7 @@ class VideoService:
|
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
-
def generate_low_resolution1(self, prompt: str, negative_prompt: str, height: int, width: int, duration_secs: float, guidance_scale: float, seed: Optional[int] = None, conditioning_items: Optional[List[
|
| 309 |
"""
|
| 310 |
Gera um vídeo de baixa resolução e retorna os caminhos para o vídeo e os latentes.
|
| 311 |
"""
|
|
@@ -356,28 +354,13 @@ class VideoService:
|
|
| 356 |
finally:
|
| 357 |
self._finalize()
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
width_padded = ((width - 1) // 8 + 1) * 8
|
| 367 |
-
padding_values = calculate_padding(height, width, height_padded, width_padded)
|
| 368 |
-
|
| 369 |
-
conditioning_items = []
|
| 370 |
-
for media, frame_idx, weight in items_list:
|
| 371 |
-
if isinstance(media, str):
|
| 372 |
-
tensor = self._prepare_conditioning_tensor_from_path(media, height, width, padding_values)
|
| 373 |
-
else: # Assume que é um tensor
|
| 374 |
-
tensor = media.to(self.device, dtype=self.runtime_autocast_dtype)
|
| 375 |
-
|
| 376 |
-
# Garante que o frame de condicionamento esteja dentro dos limites do vídeo
|
| 377 |
-
safe_frame_idx = int(frame_idx)
|
| 378 |
-
conditioning_items.append(PatchedConditioningItem(tensor, safe_frame_idx, float(weight)))
|
| 379 |
-
|
| 380 |
-
return PatchedConditioningItem
|
| 381 |
|
| 382 |
|
| 383 |
def generate_upscale_denoise(self, latents_path: str, prompt: str, negative_prompt: str, guidance_scale: float, seed: Optional[int] = None) -> Tuple[str, str]:
|
|
@@ -444,7 +427,7 @@ class VideoService:
|
|
| 444 |
duration_secs: float,
|
| 445 |
guidance_scale: float,
|
| 446 |
seed: Optional[int] = None,
|
| 447 |
-
|
| 448 |
) -> Tuple[str, str, int]:
|
| 449 |
"""
|
| 450 |
ETAPA 1: Gera um vídeo e latentes em resolução base a partir de um prompt e
|
|
@@ -468,6 +451,16 @@ class VideoService:
|
|
| 468 |
downscaled_width = width
|
| 469 |
#self._calculate_downscaled_dims(height, width)
|
| 470 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
|
| 472 |
print(f" - Frames: {actual_num_frames}, Duração: {duration_secs}s")
|
| 473 |
print(f" - Dimensões de Saída: {downscaled_height}x{downscaled_width}")
|
|
@@ -525,7 +518,7 @@ class VideoService:
|
|
| 525 |
negative_prompt: str,
|
| 526 |
guidance_scale: float,
|
| 527 |
seed: Optional[int] = None,
|
| 528 |
-
conditioning_items: Optional[List[
|
| 529 |
) -> Tuple[str, str]:
|
| 530 |
"""
|
| 531 |
ETAPA 2: Refina a textura dos latentes existentes SEM alterar sua resolução
|
|
|
|
| 37 |
from managers.vae_manager import vae_manager_singleton
|
| 38 |
from tools.video_encode_tool import video_encode_tool_singleton
|
| 39 |
|
|
|
|
|
|
|
| 40 |
# --- Constantes Globais ---
|
| 41 |
LTXV_DEBUG = True # Mude para False para desativar logs de debug
|
| 42 |
LTXV_FRAME_LOG_EVERY = 8
|
|
|
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
+
def generate_low_resolution1(self, prompt: str, negative_prompt: str, height: int, width: int, duration_secs: float, guidance_scale: float, seed: Optional[int] = None, conditioning_items: Optional[List[ConditioningItem]] = None) -> Tuple[str, str, int]:
|
| 307 |
"""
|
| 308 |
Gera um vídeo de baixa resolução e retorna os caminhos para o vídeo e os latentes.
|
| 309 |
"""
|
|
|
|
| 354 |
finally:
|
| 355 |
self._finalize()
|
| 356 |
|
| 357 |
+
def _prepare_conditioning_tensor(self, filepath, height, width, padding_values):
|
| 358 |
+
print(f"[DEBUG] Carregando condicionamento: {filepath}")
|
| 359 |
+
tensor = load_image_to_tensor_with_resize_and_crop(filepath, height, width)
|
| 360 |
+
tensor = torch.nn.functional.pad(tensor, padding_values)
|
| 361 |
+
out = tensor.to(self.device, dtype=self.runtime_autocast_dtype) if self.device == "cuda" else tensor.to(self.device)
|
| 362 |
+
print(f"[DEBUG] Cond shape={tuple(out.shape)} dtype={out.dtype} device={out.device}")
|
| 363 |
+
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
|
| 366 |
def generate_upscale_denoise(self, latents_path: str, prompt: str, negative_prompt: str, guidance_scale: float, seed: Optional[int] = None) -> Tuple[str, str]:
|
|
|
|
| 427 |
duration_secs: float,
|
| 428 |
guidance_scale: float,
|
| 429 |
seed: Optional[int] = None,
|
| 430 |
+
image_filepaths: Optional[List[str]] = None
|
| 431 |
) -> Tuple[str, str, int]:
|
| 432 |
"""
|
| 433 |
ETAPA 1: Gera um vídeo e latentes em resolução base a partir de um prompt e
|
|
|
|
| 451 |
downscaled_width = width
|
| 452 |
#self._calculate_downscaled_dims(height, width)
|
| 453 |
|
| 454 |
+
|
| 455 |
+
height_padded = ((downscaled_height - 1) // 32 + 1) * 32
|
| 456 |
+
width_padded = ((downscaled_width - 1) // 32 + 1) * 32
|
| 457 |
+
padding_values = calculate_padding(downscaled_height, downscaled_width, height_padded, width_padded)
|
| 458 |
+
|
| 459 |
+
conditioning_items = []
|
| 460 |
+
for filepath in image_filepaths:
|
| 461 |
+
cond_tensor = self._prepare_conditioning_tensor(filepath, downscaled_height, downscaled_width, padding_values)
|
| 462 |
+
conditioning_items.append(ConditioningItem(cond_tensor, 0, 1.0))
|
| 463 |
+
|
| 464 |
|
| 465 |
print(f" - Frames: {actual_num_frames}, Duração: {duration_secs}s")
|
| 466 |
print(f" - Dimensões de Saída: {downscaled_height}x{downscaled_width}")
|
|
|
|
| 518 |
negative_prompt: str,
|
| 519 |
guidance_scale: float,
|
| 520 |
seed: Optional[int] = None,
|
| 521 |
+
conditioning_items: Optional[List[ConditioningItem]] = None
|
| 522 |
) -> Tuple[str, str]:
|
| 523 |
"""
|
| 524 |
ETAPA 2: Refina a textura dos latentes existentes SEM alterar sua resolução
|