Update api/ltx_server_refactored.py
Browse files- api/ltx_server_refactored.py +9 -10
api/ltx_server_refactored.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# ltx_server_refactored.py — VideoService (Modular Version)
|
| 2 |
|
| 3 |
# --- 0. WARNINGS E AMBIENTE ---
|
| 4 |
import warnings
|
|
@@ -395,10 +395,6 @@ class VideoService:
|
|
| 395 |
# ==============================================================================
|
| 396 |
|
| 397 |
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int):
|
| 398 |
-
"""
|
| 399 |
-
Prepara a lista de tensores de condicionamento a partir de uma lista de imagens ou tensores.
|
| 400 |
-
Formato da lista de entrada: [[media_path_ou_tensor, frame_alvo, peso], ...]
|
| 401 |
-
"""
|
| 402 |
if not items_list:
|
| 403 |
return []
|
| 404 |
|
|
@@ -428,10 +424,6 @@ class VideoService:
|
|
| 428 |
return conditioning_items
|
| 429 |
|
| 430 |
def generate_low(self, prompt, negative_prompt, height, width, duration, guidance_scale, seed, conditioning_items=None):
|
| 431 |
-
"""
|
| 432 |
-
Gera um vídeo em baixa resolução (primeiro passe).
|
| 433 |
-
Retorna: (caminho_do_video_mp4, caminho_do_tensor_cpu, seed_usado)
|
| 434 |
-
"""
|
| 435 |
print("\n--- INICIANDO ETAPA 1: GERAÇÃO EM BAIXA RESOLUÇÃO ---")
|
| 436 |
self._log_gpu_memory("Início da Geração Low-Res")
|
| 437 |
|
|
@@ -449,4 +441,11 @@ class VideoService:
|
|
| 449 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_low_"); self._register_tmp_dir(temp_dir)
|
| 450 |
results_dir = "/app/output"; os.makedirs(results_dir, exist_ok=True)
|
| 451 |
|
| 452 |
-
downscale_factor = self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ltx_server_refactored.py — VideoService (Modular Version with Exact Dimension Calculation)
|
| 2 |
|
| 3 |
# --- 0. WARNINGS E AMBIENTE ---
|
| 4 |
import warnings
|
|
|
|
| 395 |
# ==============================================================================
|
| 396 |
|
| 397 |
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
if not items_list:
|
| 399 |
return []
|
| 400 |
|
|
|
|
| 424 |
return conditioning_items
|
| 425 |
|
| 426 |
def generate_low(self, prompt, negative_prompt, height, width, duration, guidance_scale, seed, conditioning_items=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
print("\n--- INICIANDO ETAPA 1: GERAÇÃO EM BAIXA RESOLUÇÃO ---")
|
| 428 |
self._log_gpu_memory("Início da Geração Low-Res")
|
| 429 |
|
|
|
|
| 441 |
temp_dir = tempfile.mkdtemp(prefix="ltxv_low_"); self._register_tmp_dir(temp_dir)
|
| 442 |
results_dir = "/app/output"; os.makedirs(results_dir, exist_ok=True)
|
| 443 |
|
| 444 |
+
downscale_factor = self.config.get("downscale_factor", 0.6666666)
|
| 445 |
+
vae_scale_factor = self.pipeline.vae_scale_factor
|
| 446 |
+
|
| 447 |
+
# --- <INÍCIO DA LÓGICA DE CÁLCULO EXATA> ---
|
| 448 |
+
# Replica a fórmula da LTXMultiScalePipeline
|
| 449 |
+
x_width = int(width_padded * downscale_factor)
|
| 450 |
+
downscaled_width = x_width - (x_width % vae_scale_factor)
|
| 451 |
+
|