Delete aduc_orchestrator1.py
Browse files- aduc_orchestrator1.py +0 -138
aduc_orchestrator1.py
DELETED
|
@@ -1,138 +0,0 @@
|
|
| 1 |
-
# aduc_orchestrator.py
|
| 2 |
-
# Copyright (C) 4 de Agosto de 2025 Carlos Rodrigues dos Santos
|
| 3 |
-
#
|
| 4 |
-
# Este programa é software livre: você pode redistribuí-lo e/ou modificá-lo
|
| 5 |
-
# sob os termos da Licença Pública Geral Affero GNU...
|
| 6 |
-
# AVISO DE PATENTE PENDENTE: Consulte NOTICE.md.
|
| 7 |
-
|
| 8 |
-
import os
|
| 9 |
-
import time
|
| 10 |
-
import shutil
|
| 11 |
-
import logging
|
| 12 |
-
import gradio as gr
|
| 13 |
-
from PIL import Image, ImageOps
|
| 14 |
-
import subprocess
|
| 15 |
-
from pathlib import Path
|
| 16 |
-
import json
|
| 17 |
-
|
| 18 |
-
from deformes4D_engine import Deformes4DEngine
|
| 19 |
-
from ltx_manager_helpers import ltx_manager_singleton
|
| 20 |
-
from gemini_helpers import gemini_singleton
|
| 21 |
-
from image_specialist import image_specialist_singleton
|
| 22 |
-
|
| 23 |
-
# Configuração de logging centralizada deve ser feita no app.py
|
| 24 |
-
logger = logging.getLogger(__name__)
|
| 25 |
-
|
| 26 |
-
class AducDirector:
|
| 27 |
-
def __init__(self, workspace_dir):
|
| 28 |
-
self.workspace_dir = workspace_dir
|
| 29 |
-
os.makedirs(self.workspace_dir, exist_ok=True)
|
| 30 |
-
self.state = {}
|
| 31 |
-
logger.info(f"O palco está pronto. Workspace em '{self.workspace_dir}'.")
|
| 32 |
-
|
| 33 |
-
def reset(self):
|
| 34 |
-
os.makedirs(self.workspace_dir, exist_ok=True)
|
| 35 |
-
self.state = {}
|
| 36 |
-
logger.info("Partitura limpa. Estado do Diretor reiniciado.")
|
| 37 |
-
|
| 38 |
-
def update_state(self, key, value):
|
| 39 |
-
log_value = value if not isinstance(value, (dict, list)) and not hasattr(value, 'shape') else f"Objeto complexo"
|
| 40 |
-
logger.info(f"Anotando na partitura: Estado '{key}' atualizado.")
|
| 41 |
-
self.state[key] = value
|
| 42 |
-
|
| 43 |
-
def get_state(self, key, default=None):
|
| 44 |
-
return self.state.get(key, default)
|
| 45 |
-
|
| 46 |
-
class AducOrchestrator:
|
| 47 |
-
def __init__(self, workspace_dir: str):
|
| 48 |
-
self.director = AducDirector(workspace_dir)
|
| 49 |
-
self.editor = Deformes4DEngine(ltx_manager_singleton, workspace_dir)
|
| 50 |
-
self.painter = image_specialist_singleton
|
| 51 |
-
logger.info("Maestro ADUC está no pódio. Músicos (especialistas) prontos.")
|
| 52 |
-
|
| 53 |
-
def process_image_for_story(self, image_path: str, size: int, filename: str = None) -> str:
|
| 54 |
-
"""
|
| 55 |
-
Pré-processa uma imagem de referência: converte para RGB, redimensiona para um
|
| 56 |
-
quadrado e salva no diretório de trabalho.
|
| 57 |
-
"""
|
| 58 |
-
img = Image.open(image_path).convert("RGB")
|
| 59 |
-
img_square = ImageOps.fit(img, (size, size), Image.Resampling.LANCZOS)
|
| 60 |
-
|
| 61 |
-
if filename:
|
| 62 |
-
processed_path = os.path.join(self.director.workspace_dir, filename)
|
| 63 |
-
else:
|
| 64 |
-
processed_path = os.path.join(self.director.workspace_dir, f"ref_processed_{int(time.time()*1000)}.png")
|
| 65 |
-
|
| 66 |
-
img_square.save(processed_path)
|
| 67 |
-
logger.info(f"Imagem de referência processada e salva em: {processed_path}")
|
| 68 |
-
return processed_path
|
| 69 |
-
|
| 70 |
-
def task_generate_storyboard(self, prompt, num_keyframes, processed_ref_image_paths, progress):
|
| 71 |
-
logger.info(f"Ato 1, Cena 1: Roteiro. Instruindo o Roteirista (Gemini) a criar {num_keyframes} cenas a partir de: '{prompt}'")
|
| 72 |
-
progress(0.2, desc="Consultando Roteirista IA (Gemini)...")
|
| 73 |
-
storyboard = gemini_singleton.generate_storyboard(prompt, num_keyframes, processed_ref_image_paths)
|
| 74 |
-
logger.info(f"Roteirista retornou a partitura: {storyboard}")
|
| 75 |
-
self.director.update_state("storyboard", storyboard)
|
| 76 |
-
self.director.update_state("processed_ref_paths", processed_ref_image_paths)
|
| 77 |
-
return storyboard, processed_ref_image_paths[0], gr.update(visible=True, open=True)
|
| 78 |
-
|
| 79 |
-
def task_select_keyframes(self, storyboard, base_ref_paths, pool_ref_paths):
|
| 80 |
-
logger.info(f"Ato 1, Cena 2 (Alternativa): Fotografia. Instruindo o Editor (Gemini) a selecionar {len(storyboard)} keyframes de um banco de {len(pool_ref_paths)} imagens.")
|
| 81 |
-
selected_paths = gemini_singleton.select_keyframes_from_pool(storyboard, base_ref_paths, pool_ref_paths)
|
| 82 |
-
logger.info(f"Editor selecionou as seguintes cenas: {[os.path.basename(p) for p in selected_paths]}")
|
| 83 |
-
self.director.update_state("keyframes", selected_paths)
|
| 84 |
-
return selected_paths
|
| 85 |
-
|
| 86 |
-
def task_generate_keyframes(self, storyboard, initial_ref_path, global_prompt, keyframe_resolution, progress_callback_factory=None):
|
| 87 |
-
"""
|
| 88 |
-
Delega a tarefa de geração de keyframes para o ImageSpecialist.
|
| 89 |
-
"""
|
| 90 |
-
logger.info(f"Ato 1, Cena 2: Direção de Arte. Delegando ao Especialista de Imagem.")
|
| 91 |
-
|
| 92 |
-
general_ref_paths = self.director.get_state("processed_ref_paths", [])
|
| 93 |
-
|
| 94 |
-
final_keyframes = self.painter.generate_keyframes_from_storyboard(
|
| 95 |
-
storyboard=storyboard,
|
| 96 |
-
initial_ref_path=initial_ref_path,
|
| 97 |
-
global_prompt=global_prompt,
|
| 98 |
-
keyframe_resolution=int(keyframe_resolution),
|
| 99 |
-
general_ref_paths=general_ref_paths,
|
| 100 |
-
progress_callback_factory=progress_callback_factory
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
self.director.update_state("keyframes", final_keyframes)
|
| 104 |
-
logger.info("Maestro: Especialista de Imagem concluiu a geração dos keyframes.")
|
| 105 |
-
return final_keyframes
|
| 106 |
-
|
| 107 |
-
def task_produce_final_movie_with_feedback(self, keyframes, global_prompt, seconds_per_fragment,
|
| 108 |
-
trim_percent: int,
|
| 109 |
-
handler_strength,
|
| 110 |
-
destination_convergence_strength,
|
| 111 |
-
video_resolution, use_continuity_director,
|
| 112 |
-
use_cinematographer, progress):
|
| 113 |
-
|
| 114 |
-
logger.info("AducOrchestrator: Delegando a produção do filme completo ao Deformes4DEngine.")
|
| 115 |
-
storyboard = self.director.get_state("storyboard", [])
|
| 116 |
-
|
| 117 |
-
# A chamada para generate_full_movie agora usa `trim_percent` e ignora os parâmetros antigos.
|
| 118 |
-
for update in self.editor.generate_full_movie(
|
| 119 |
-
keyframes=keyframes,
|
| 120 |
-
global_prompt=global_prompt,
|
| 121 |
-
storyboard=storyboard,
|
| 122 |
-
seconds_per_fragment=seconds_per_fragment,
|
| 123 |
-
trim_percent=trim_percent,
|
| 124 |
-
handler_strength=handler_strength,
|
| 125 |
-
destination_convergence_strength=destination_convergence_strength,
|
| 126 |
-
video_resolution=video_resolution,
|
| 127 |
-
use_continuity_director=use_continuity_director,
|
| 128 |
-
progress=progress
|
| 129 |
-
):
|
| 130 |
-
if "fragment_path" in update and update["fragment_path"]:
|
| 131 |
-
yield {"fragment_path": update["fragment_path"]}
|
| 132 |
-
elif "final_path" in update and update["final_path"]:
|
| 133 |
-
final_movie_path = update["final_path"]
|
| 134 |
-
self.director.update_state("final_video_path", final_movie_path)
|
| 135 |
-
yield {"final_path": final_movie_path}
|
| 136 |
-
break
|
| 137 |
-
|
| 138 |
-
logger.info("AducOrchestrator: Produção do filme concluída e estado do diretor atualizado.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|