eeuuia commited on
Commit
4957d04
·
verified ·
1 Parent(s): cf51351

Update api/ltx/ltx_aduc_orchestrator.py

Browse files
Files changed (1) hide show
  1. api/ltx/ltx_aduc_orchestrator.py +20 -25
api/ltx/ltx_aduc_orchestrator.py CHANGED
@@ -1,20 +1,18 @@
1
  # FILE: api/ltx_aduc_orchestrator.py
2
  # DESCRIPTION: The main workflow orchestrator for the ADUC-SDR LTX suite.
3
- # It acts as the primary entry point for the UI, coordinating the specialized
4
- # LTX and VAE clients to execute a complete video generation pipeline from prompt to MP4.
5
 
6
  import logging
7
  import time
8
  import yaml
9
  from PIL import Image
10
  from typing import Optional, Dict
11
- import os
12
 
13
- # O Orquestrador importa os CLIENTES especialistas que ele vai coordenar.
14
  from api.ltx.ltx_aduc_pipeline import ltx_aduc_pipeline
15
- from api.ltx.vae_aduc_pipeline import vae_aduc_pipeline
16
 
17
- # O Orquestrador importa as FERRAMENTAS de que precisa.
18
  from tools.video_encode_tool import video_encode_tool_singleton
19
 
20
  # Importa o Path para carregar a configuração.
@@ -27,8 +25,8 @@ LTX_VIDEO_REPO_DIR = Path("/data/LTX-Video")
27
 
28
  class LtxAducOrchestrator:
29
  """
30
- Orquestra o fluxo de trabalho completo de geração de vídeo.
31
- É o ponto de entrada principal para a UI, preparando e delegando tarefas.
32
  """
33
  def __init__(self):
34
  """
@@ -86,16 +84,14 @@ class LtxAducOrchestrator:
86
 
87
  initial_conditioning_items = []
88
  if initial_image:
89
- logging.info("Delegating to VAE client: create conditioning item.")
90
  conditioning_params = [(0, 1.0)] # (frame_number, strength)
91
- initial_conditioning_items = vae_aduc_pipeline(
92
- media=[initial_image],
93
- task='create_conditioning_items',
94
- target_resolution=(height, width),
95
- conditioning_params=conditioning_params
96
  )
97
 
98
- # Prepara a lista de argumentos comuns para todos os chunks de LTX.
99
  common_ltx_args = self.base_config.get("first_pass", {}).copy()
100
  common_ltx_args.update({
101
  'negative_prompt': "blurry, low quality, bad anatomy, deformed",
@@ -108,8 +104,8 @@ class LtxAducOrchestrator:
108
  # =================================================================
109
  # --- ETAPA 2: DELEGAR GERAÇÃO DO VÍDEO LATENTE ---
110
  # =================================================================
111
- logging.info("Delegating to LTX client: generate latent video.")
112
- final_latents, used_seed = ltx_aduc_pipeline(
113
  prompt_list=prompt_list,
114
  duration_in_seconds=duration_in_seconds,
115
  common_ltx_args=common_ltx_args,
@@ -117,16 +113,16 @@ class LtxAducOrchestrator:
117
  )
118
  if final_latents is None:
119
  raise RuntimeError("LTX client failed to generate a latent tensor.")
120
- logging.info(f"LTX client returned latent tensor with shape: {final_latents.shape}")
121
 
122
  # =================================================================
123
  # --- ETAPA 3: DELEGAR DECODIFICAÇÃO PARA PIXELS ---
124
  # =================================================================
125
- logging.info("Delegating to VAE client: decode latent to pixels.")
126
- pixel_tensor = vae_aduc_pipeline(media=final_latents, task='decode')
127
  if pixel_tensor is None:
128
- raise RuntimeError("VAE client failed to decode the latent tensor.")
129
- logging.info(f"VAE client returned pixel tensor with shape: {pixel_tensor.shape}")
130
 
131
  # =================================================================
132
  # --- ETAPA 4: TAREFA FINAL - CODIFICAR PARA MP4 ---
@@ -134,7 +130,7 @@ class LtxAducOrchestrator:
134
  video_filename = f"{output_filename_base}_{int(time.time())}_{used_seed}.mp4"
135
  output_path = f"{self.output_dir}/{video_filename}"
136
 
137
- logging.info(f"Executing final task: saving tensor to MP4 at {output_path}")
138
  video_encode_tool_singleton.save_video_from_tensor(
139
  pixel_5d=pixel_tensor,
140
  path=output_path,
@@ -152,10 +148,9 @@ class LtxAducOrchestrator:
152
 
153
  # ==============================================================================
154
  # --- INSTÂNCIA SINGLETON DO ORQUESTRADOR ---
155
- # Este é o ponto de entrada principal que a UI (app.py) irá chamar.
156
  # ==============================================================================
157
  try:
158
  ltx_aduc_orchestrator = LtxAducOrchestrator()
159
- except Exception as e:
160
  logging.critical("CRITICAL: Failed to initialize the LtxAducOrchestrator.", exc_info=True)
161
  ltx_aduc_orchestrator = None
 
1
  # FILE: api/ltx_aduc_orchestrator.py
2
  # DESCRIPTION: The main workflow orchestrator for the ADUC-SDR LTX suite.
3
+ # In this simplified architecture, it coordinates a single unified client (LtxAducPipeline)
4
+ # to execute the complete video generation pipeline from prompt to MP4.
5
 
6
  import logging
7
  import time
8
  import yaml
9
  from PIL import Image
10
  from typing import Optional, Dict
 
11
 
12
+ # O Orquestrador importa o CLIENTE UNIFICADO que ele vai coordenar.
13
  from api.ltx.ltx_aduc_pipeline import ltx_aduc_pipeline
 
14
 
15
+ # O Orquestrador importa as FERRAMENTAS de que precisa para as tarefas finais.
16
  from tools.video_encode_tool import video_encode_tool_singleton
17
 
18
  # Importa o Path para carregar a configuração.
 
25
 
26
  class LtxAducOrchestrator:
27
  """
28
+ Orquestra o fluxo de trabalho completo de geração de vídeo,
29
+ coordenando o cliente unificado LTX. É o ponto de entrada principal para a UI.
30
  """
31
  def __init__(self):
32
  """
 
84
 
85
  initial_conditioning_items = []
86
  if initial_image:
87
+ logging.info("Orchestrator delegating: create conditioning item.")
88
  conditioning_params = [(0, 1.0)] # (frame_number, strength)
89
+ initial_conditioning_items = ltx_aduc_pipeline.encode_to_conditioning_items(
90
+ media_list=[initial_image],
91
+ params=conditioning_params,
92
+ resolution=(height, width)
 
93
  )
94
 
 
95
  common_ltx_args = self.base_config.get("first_pass", {}).copy()
96
  common_ltx_args.update({
97
  'negative_prompt': "blurry, low quality, bad anatomy, deformed",
 
104
  # =================================================================
105
  # --- ETAPA 2: DELEGAR GERAÇÃO DO VÍDEO LATENTE ---
106
  # =================================================================
107
+ logging.info("Orchestrator delegating: generate latent video.")
108
+ final_latents, used_seed = ltx_aduc_pipeline.generate_latents(
109
  prompt_list=prompt_list,
110
  duration_in_seconds=duration_in_seconds,
111
  common_ltx_args=common_ltx_args,
 
113
  )
114
  if final_latents is None:
115
  raise RuntimeError("LTX client failed to generate a latent tensor.")
116
+ logging.info(f"Orchestrator received latent tensor with shape: {final_latents.shape}")
117
 
118
  # =================================================================
119
  # --- ETAPA 3: DELEGAR DECODIFICAÇÃO PARA PIXELS ---
120
  # =================================================================
121
+ logging.info("Orchestrator delegating: decode latent to pixels.")
122
+ pixel_tensor = ltx_aduc_pipeline.decode_to_pixels(final_latents)
123
  if pixel_tensor is None:
124
+ raise RuntimeError("LTX client failed to decode the latent tensor.")
125
+ logging.info(f"Orchestrator received pixel tensor with shape: {pixel_tensor.shape}")
126
 
127
  # =================================================================
128
  # --- ETAPA 4: TAREFA FINAL - CODIFICAR PARA MP4 ---
 
130
  video_filename = f"{output_filename_base}_{int(time.time())}_{used_seed}.mp4"
131
  output_path = f"{self.output_dir}/{video_filename}"
132
 
133
+ logging.info(f"Orchestrator executing final task: saving tensor to MP4 at {output_path}")
134
  video_encode_tool_singleton.save_video_from_tensor(
135
  pixel_5d=pixel_tensor,
136
  path=output_path,
 
148
 
149
  # ==============================================================================
150
  # --- INSTÂNCIA SINGLETON DO ORQUESTRADOR ---
 
151
  # ==============================================================================
152
  try:
153
  ltx_aduc_orchestrator = LtxAducOrchestrator()
154
+ except Exception:
155
  logging.critical("CRITICAL: Failed to initialize the LtxAducOrchestrator.", exc_info=True)
156
  ltx_aduc_orchestrator = None