Spaces:
Runtime error
Runtime error
Update aduc_framework/orchestrator.py
Browse files- aduc_framework/orchestrator.py +28 -19
aduc_framework/orchestrator.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Versão
|
| 6 |
#
|
| 7 |
-
# Esta versão do orquestrador está alinhada com a arquitetura do
|
| 8 |
-
#
|
| 9 |
-
#
|
| 10 |
|
| 11 |
import logging
|
| 12 |
from typing import List, Dict, Any, Tuple, Callable, Optional, Generator
|
|
@@ -66,34 +66,42 @@ class AducOrchestrator:
|
|
| 66 |
logger.info(f"Imagem de referência processada e salva em: {processed_path}")
|
| 67 |
return processed_path
|
| 68 |
|
| 69 |
-
# --- ETAPA 1: PRÉ-PRODUÇÃO ---
|
| 70 |
-
def task_pre_production(self, params: PreProductionParams, progress_callback: ProgressCallback = None) ->
|
| 71 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 72 |
logger.info("Maestro: Iniciando tarefa de Pré-Produção.")
|
| 73 |
self.director.update_parameters("pre_producao", params)
|
| 74 |
|
| 75 |
-
# Passo 1A: Gerar o roteiro inicial (storyboard)
|
| 76 |
if progress_callback: progress_callback(0.1, "Gerando roteiro inicial...")
|
| 77 |
storyboard_list = deformes2d_thinker_singleton.generate_storyboard(
|
| 78 |
prompt=params.prompt, num_keyframes=params.num_keyframes, ref_image_paths=params.ref_paths
|
| 79 |
)
|
| 80 |
self.director.update_pre_production_state(params.prompt, params.ref_paths, storyboard_list)
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if progress_callback: progress_callback(0.2, "Entregando produção ao Diretor Autônomo...")
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
generation_state=self.director.get_full_state_as_dict(),
|
| 88 |
progress_callback=progress_callback
|
| 89 |
-
)
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
final_keyframe_paths = [kf["caminho_pixel"] for kf in keyframes_detailed_data]
|
| 94 |
-
final_state = self.director.get_full_state()
|
| 95 |
logger.info("Maestro: Tarefa de Pré-Produção concluída.")
|
| 96 |
-
return storyboard_list, final_keyframe_paths, final_state
|
| 97 |
|
| 98 |
# --- ETAPA 2: PRODUÇÃO ---
|
| 99 |
def task_produce_original_movie(self, params: ProductionParams, progress_callback: ProgressCallback = None) -> Tuple[str, List[str], GenerationState]:
|
|
@@ -113,7 +121,7 @@ class AducOrchestrator:
|
|
| 113 |
logger.info("Maestro: Tarefa de Produção do Filme Original concluída.")
|
| 114 |
return final_video_path, latent_paths, final_state
|
| 115 |
|
| 116 |
-
# --- ETAPA 3: PÓS-PRODUÇÃO (
|
| 117 |
|
| 118 |
def task_run_latent_upscaler(self, latent_paths: List[str], chunk_size: int, progress_callback: ProgressCallback = None) -> Generator[Dict[str, Any], None, None]:
|
| 119 |
"""Aplica upscale 2x nos latentes e os decodifica para um novo vídeo."""
|
|
@@ -138,7 +146,8 @@ class AducOrchestrator:
|
|
| 138 |
pixel_tensor = vae_manager_singleton.decode(upscaled_latent_chunk)
|
| 139 |
|
| 140 |
current_clip_path = os.path.join(temp_dir, f"upscaled_clip_{i:04d}.mp4")
|
| 141 |
-
|
|
|
|
| 142 |
final_upscaled_clip_paths.append(current_clip_path)
|
| 143 |
|
| 144 |
del tensors_in_chunk, sub_group_latent, upscaled_latent_chunk, pixel_tensor
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Versão 6.0.0 (Streaming Conductor)
|
| 6 |
#
|
| 7 |
+
# Esta versão final do orquestrador está alinhada com a arquitetura do
|
| 8 |
+
# Diretor Autônomo e suporta a emissão de atualizações em tempo real (yield)
|
| 9 |
+
# para interfaces de usuário interativas.
|
| 10 |
|
| 11 |
import logging
|
| 12 |
from typing import List, Dict, Any, Tuple, Callable, Optional, Generator
|
|
|
|
| 66 |
logger.info(f"Imagem de referência processada e salva em: {processed_path}")
|
| 67 |
return processed_path
|
| 68 |
|
| 69 |
+
# --- ETAPA 1: PRÉ-PRODUÇÃO (STREAMING) ---
|
| 70 |
+
def task_pre_production(self, params: PreProductionParams, progress_callback: ProgressCallback = None) -> Generator[Dict[str, Any], None, None]:
|
| 71 |
+
"""
|
| 72 |
+
Orquestra a pré-produção, agora como um gerador que emite
|
| 73 |
+
atualizações de estado para a UI em tempo real.
|
| 74 |
+
"""
|
| 75 |
logger.info("Maestro: Iniciando tarefa de Pré-Produção.")
|
| 76 |
self.director.update_parameters("pre_producao", params)
|
| 77 |
|
|
|
|
| 78 |
if progress_callback: progress_callback(0.1, "Gerando roteiro inicial...")
|
| 79 |
storyboard_list = deformes2d_thinker_singleton.generate_storyboard(
|
| 80 |
prompt=params.prompt, num_keyframes=params.num_keyframes, ref_image_paths=params.ref_paths
|
| 81 |
)
|
| 82 |
self.director.update_pre_production_state(params.prompt, params.ref_paths, storyboard_list)
|
| 83 |
|
| 84 |
+
yield {
|
| 85 |
+
"storyboard": storyboard_list,
|
| 86 |
+
"updated_state": self.director.get_full_state().model_dump()
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
if progress_callback: progress_callback(0.2, "Entregando produção ao Diretor Autônomo...")
|
| 90 |
|
| 91 |
+
final_keyframes_data = []
|
| 92 |
+
for keyframes_update in self.painter.generate_keyframes(
|
| 93 |
generation_state=self.director.get_full_state_as_dict(),
|
| 94 |
progress_callback=progress_callback
|
| 95 |
+
):
|
| 96 |
+
self.director.update_keyframes_state(keyframes_update)
|
| 97 |
+
final_keyframes_data = keyframes_update
|
| 98 |
+
|
| 99 |
+
yield {
|
| 100 |
+
"final_keyframes": [kf["caminho_pixel"] for kf in final_keyframes_data],
|
| 101 |
+
"updated_state": self.director.get_full_state().model_dump()
|
| 102 |
+
}
|
| 103 |
|
|
|
|
|
|
|
| 104 |
logger.info("Maestro: Tarefa de Pré-Produção concluída.")
|
|
|
|
| 105 |
|
| 106 |
# --- ETAPA 2: PRODUÇÃO ---
|
| 107 |
def task_produce_original_movie(self, params: ProductionParams, progress_callback: ProgressCallback = None) -> Tuple[str, List[str], GenerationState]:
|
|
|
|
| 121 |
logger.info("Maestro: Tarefa de Produção do Filme Original concluída.")
|
| 122 |
return final_video_path, latent_paths, final_state
|
| 123 |
|
| 124 |
+
# --- ETAPA 3: PÓS-PRODUÇÃO (CADEIA DE EFEITOS) ---
|
| 125 |
|
| 126 |
def task_run_latent_upscaler(self, latent_paths: List[str], chunk_size: int, progress_callback: ProgressCallback = None) -> Generator[Dict[str, Any], None, None]:
|
| 127 |
"""Aplica upscale 2x nos latentes e os decodifica para um novo vídeo."""
|
|
|
|
| 146 |
pixel_tensor = vae_manager_singleton.decode(upscaled_latent_chunk)
|
| 147 |
|
| 148 |
current_clip_path = os.path.join(temp_dir, f"upscaled_clip_{i:04d}.mp4")
|
| 149 |
+
# Usando o save_video do Deformes4D para consistência
|
| 150 |
+
self.editor._save_video_from_tensor(pixel_tensor, current_clip_path, fps=24)
|
| 151 |
final_upscaled_clip_paths.append(current_clip_path)
|
| 152 |
|
| 153 |
del tensors_in_chunk, sub_group_latent, upscaled_latent_chunk, pixel_tensor
|