Aduc-sdr commited on
Commit
8c232e4
·
verified ·
1 Parent(s): 70c5d9b

Update aduc_orchestrator.py

Browse files
Files changed (1) hide show
  1. aduc_orchestrator.py +96 -117
aduc_orchestrator.py CHANGED
@@ -1,13 +1,39 @@
1
  # aduc_orchestrator.py
2
  #
3
- # Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
 
4
  #
5
- # Version: 2.2.0
 
 
 
6
  #
7
- # This file contains the core ADUC (Automated Discovery and Orchestration of Complex tasks)
8
- # orchestrator, known as the "Maestro" (Γ). Its responsibility is to manage the high-level
9
- # creative workflow of film production. This version is updated to reflect the final
10
- # refactored project structure with `engineers` and `managers`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  import os
13
  import logging
@@ -16,18 +42,17 @@ from typing import List, Dict, Any, Generator, Tuple
16
  import gradio as gr
17
  from PIL import Image, ImageOps
18
 
19
- from engineers.deformes4D import Deformes4DEngine
 
 
20
  from engineers.deformes2D_thinker import deformes2d_thinker_singleton
21
- from engineers.deformes3D import deformes3d_engine_singleton
22
 
23
- # The logger is configured in app.py; here we just get the instance.
24
  logger = logging.getLogger(__name__)
25
 
26
  class AducDirector:
27
  """
28
- Represents the Scene Director, responsible for managing the production state.
29
- Acts as the "score" for the orchestra, keeping track of all generated artifacts
30
- (script, keyframes, etc.) during the creative process.
31
  """
32
  def __init__(self, workspace_dir: str):
33
  self.workspace_dir = workspace_dir
@@ -44,19 +69,21 @@ class AducDirector:
44
 
45
  class AducOrchestrator:
46
  """
47
- Implements the Maestro (Γ), the central orchestration layer of the ADUC architecture.
48
- It does not execute AI tasks directly but delegates each step of the creative
49
- process (scriptwriting, art direction, cinematography) to the appropriate Specialists.
50
  """
51
  def __init__(self, workspace_dir: str):
 
 
 
52
  self.director = AducDirector(workspace_dir)
53
- self.editor = Deformes4DEngine(workspace_dir)
54
- self.painter = deformes3d_engine_singleton
55
- logger.info("ADUC Maestro is on the podium. Musicians (specialists) are ready.")
56
 
57
  def process_image_for_story(self, image_path: str, size: int, filename: str) -> str:
58
  """
59
- Pre-processes a reference image, standardizing it for use by the Specialists.
60
  """
61
  img = Image.open(image_path).convert("RGB")
62
  img_square = ImageOps.fit(img, (size, size), Image.Resampling.LANCZOS)
@@ -65,135 +92,87 @@ class AducOrchestrator:
65
  logger.info(f"Reference image processed and saved to: {processed_path}")
66
  return processed_path
67
 
68
- # --- PRE-PRODUCTION TASKS ---
69
 
70
  def task_generate_storyboard(self, prompt: str, num_keyframes: int, ref_image_paths: List[str],
71
  progress: gr.Progress) -> Tuple[List[str], str, Any]:
72
  """
73
- Delegates the task of creating the storyboard to the Scriptwriter (deformes2D_thinker).
74
  """
75
- logger.info(f"Act 1, Scene 1: Script. Instructing Scriptwriter to create {num_keyframes} scenes.")
76
- progress(0.2, desc="Consulting AI Scriptwriter...")
77
 
78
- storyboard = deformes2d_thinker_singleton.generate_storyboard(prompt, num_keyframes, ref_image_paths)
79
 
80
- logger.info(f"Scriptwriter returned the score: {storyboard}")
81
  self.director.update_state("storyboard", storyboard)
82
  self.director.update_state("processed_ref_paths", ref_image_paths)
83
  return storyboard, ref_image_paths[0], gr.update(visible=True, open=True)
84
 
 
 
85
  def task_select_keyframes(self, storyboard: List[str], base_ref_paths: List[str],
86
  pool_ref_paths: List[str]) -> List[str]:
87
- """
88
- Delegates to the Photographer (deformes2D_thinker) the task of selecting keyframes.
89
- """
90
- logger.info(f"Act 1, Scene 2 (Photographer Mode): Instructing Photographer to select {len(storyboard)} keyframes.")
91
- selected_paths = deformes2d_thinker_singleton.select_keyframes_from_pool(storyboard, base_ref_paths, pool_ref_paths)
92
- logger.info(f"Photographer selected the following scenes: {[os.path.basename(p) for p in selected_paths]}")
93
  self.director.update_state("keyframes", selected_paths)
94
  return selected_paths
95
 
96
- def task_generate_keyframes(self, storyboard: List[str], initial_ref_path: str, global_prompt: str,
97
- keyframe_resolution: int, progress_callback_factory=None) -> List[str]:
98
- """
99
- Delegates to the Art Director (Deformes3DEngine) the task of generating keyframes.
100
- """
101
- logger.info("Act 1, Scene 2 (Art Director Mode): Delegating to Art Director.")
102
- general_ref_paths = self.director.get_state("processed_ref_paths", [])
103
 
104
- final_keyframes = self.painter.generate_keyframes_from_storyboard(
105
- storyboard=storyboard,
106
- initial_ref_path=initial_ref_path,
107
- global_prompt=global_prompt,
108
- keyframe_resolution=keyframe_resolution,
109
- general_ref_paths=general_ref_paths,
110
- progress_callback_factory=progress_callback_factory
111
- )
112
- self.director.update_state("keyframes", final_keyframes)
113
- logger.info("Maestro: Art Director has completed keyframe generation.")
114
- return final_keyframes
115
-
116
- # --- PRODUCTION & POST-PRODUCTION TASKS ---
117
-
118
- def task_produce_original_movie(self, keyframes: List[str], global_prompt: str, seconds_per_fragment: float,
119
- trim_percent: int, handler_strength: float,
120
- destination_convergence_strength: float,
121
- guidance_scale: float, stg_scale: float, inference_steps: int,
122
- video_resolution: int, use_continuity_director: bool,
123
- progress: gr.Progress) -> Dict[str, Any]:
124
  """
125
- Delegates the production of the original master video to the Deformes4DEngine.
126
  """
127
- logger.info("Maestro: Delegating production of the original movie to Deformes4DEngine.")
128
  storyboard = self.director.get_state("storyboard", [])
129
-
130
- result = self.editor.generate_original_movie(
131
- keyframes=keyframes,
132
- global_prompt=global_prompt,
 
 
 
 
 
 
 
 
133
  storyboard=storyboard,
 
 
134
  seconds_per_fragment=seconds_per_fragment,
135
  trim_percent=trim_percent,
136
  handler_strength=handler_strength,
137
- destination_convergence_strength=destination_convergence_strength,
138
- video_resolution=video_resolution,
139
- use_continuity_director=use_continuity_director,
140
- guidance_scale=guidance_scale,
141
- stg_scale=stg_scale,
142
- num_inference_steps=inference_steps,
143
  progress=progress
144
  )
145
 
146
  self.director.update_state("final_video_path", result["final_path"])
147
- self.director.update_state("latent_paths", result["latent_paths"])
148
- logger.info("Maestro: Original movie production complete.")
149
  return result
150
 
151
- def task_run_latent_upscaler(self, latent_paths: List[str], chunk_size: int, progress: gr.Progress) -> Generator[Dict[str, Any], None, None]:
152
- """
153
- Orchestrates the latent upscaling task.
154
- """
155
- logger.info(f"Maestro: Delegating latent upscaling task for {len(latent_paths)} fragments.")
156
- for update in self.editor.upscale_latents_and_create_video(
157
- latent_paths=latent_paths,
158
- chunk_size=chunk_size,
159
- progress=progress
160
- ):
161
- if "final_path" in update and update["final_path"]:
162
- self.director.update_state("final_video_path", update["final_path"])
163
- yield update
164
- break
165
- logger.info("Maestro: Latent upscaling complete.")
166
-
167
  def task_run_hd_mastering(self, source_video_path: str, model_version: str, steps: int, prompt: str, progress: gr.Progress) -> Generator[Dict[str, Any], None, None]:
168
- """
169
- Orchestrates the HD mastering task.
170
- """
171
- logger.info(f"Maestro: Delegating HD mastering task using SeedVR {model_version}.")
172
- for update in self.editor.master_video_hd(
173
- source_video_path=source_video_path,
174
- model_version=model_version,
175
- steps=steps,
176
- prompt=prompt,
177
- progress=progress
178
  ):
179
- if "final_path" in update and update["final_path"]:
180
- self.director.update_state("final_video_path", update["final_path"])
181
- yield update
182
- break
183
- logger.info("Maestro: HD mastering complete.")
184
-
185
  def task_run_audio_generation(self, source_video_path: str, audio_prompt: str, progress: gr.Progress) -> Generator[Dict[str, Any], None, None]:
186
- """
187
- Orchestrates the audio generation task.
188
- """
189
- logger.info(f"Maestro: Delegating audio generation task.")
190
- for update in self.editor.generate_audio_for_final_video(
191
- source_video_path=source_video_path,
192
- audio_prompt=audio_prompt,
193
- progress=progress
194
  ):
195
- if "final_path" in update and update["final_path"]:
196
- self.director.update_state("final_video_path", update["final_path"])
197
- yield update
198
- break
199
- logger.info("Maestro: Audio generation complete.")
 
1
  # aduc_orchestrator.py
2
  #
3
+ # AducSdr: Uma implementação aberta e funcional da arquitetura ADUC-SDR
4
+ # Copyright (C) 4 de Agosto de 2025 Carlos Rodrigues dos Santos
5
  #
6
+ # Contato:
7
+ # Carlos Rodrigues dos Santos
8
+ # carlex22@gmail.com
9
+ # Rua Eduardo Carlos Pereira, 4125, B1 Ap32, Curitiba, PR, Brazil, CEP 8102025
10
  #
11
+ # Repositórios e Projetos Relacionados:
12
+ # GitHub: https://github.com/carlex22/Aduc-sdr
13
+ #
14
+ # This program is free software: you can redistribute it and/or modify
15
+ # it under the terms of the GNU Affero General Public License as published by
16
+ # the Free Software Foundation, either version 3 of the License, or
17
+ # (at your option) any later version.
18
+ #
19
+ # This program is distributed in the hope that it will be useful,
20
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ # GNU Affero General Public License for more details.
23
+ #
24
+ # You should have received a copy of the GNU Affero General Public License
25
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
26
+ #
27
+ # This program is free software: you can redistribute it and/or modify
28
+ # it under the terms of the GNU Affero General Public License...
29
+ # PENDING PATENT NOTICE: Please see NOTICE.md.
30
+ #
31
+ # Version: 3.0.0
32
+ #
33
+ # This version adapts the Maestro to command the new unified "Turbo Intergalactic
34
+ # Multiverse Engine": the Deformes7DEngine. The orchestrator is now a lean
35
+ # command layer, delegating all complex production and post-production tasks
36
+ # to its single, powerful Chief Engineer.
37
 
38
  import os
39
  import logging
 
42
  import gradio as gr
43
  from PIL import Image, ImageOps
44
 
45
+ # O Orquestrador agora só precisa de dois engenheiros:
46
+ # - O Pensador (2D) para a lógica criativa
47
+ # - O Engenheiro-Chefe (7D) para toda a execução
48
  from engineers.deformes2D_thinker import deformes2d_thinker_singleton
49
+ from engineers.deformes7D import deformes7d_engine_singleton
50
 
 
51
  logger = logging.getLogger(__name__)
52
 
53
  class AducDirector:
54
  """
55
+ Representa o Diretor de Cena, gerenciando o estado da produção.
 
 
56
  """
57
  def __init__(self, workspace_dir: str):
58
  self.workspace_dir = workspace_dir
 
69
 
70
  class AducOrchestrator:
71
  """
72
+ Implementa o Maestro (Γ), a camada de orquestração que comanda
73
+ o Engenheiro-Chefe Deformes7D.
 
74
  """
75
  def __init__(self, workspace_dir: str):
76
+ """
77
+ Inicializa o Maestro e seu Engenheiro-Chefe.
78
+ """
79
  self.director = AducDirector(workspace_dir)
80
+ self.thinker = deformes2d_thinker_singleton
81
+ self.chief_engineer = deformes7d_engine_singleton
82
+ logger.info("ADUC Maestro is on the podium with the Chief Engineer (Deformes7D) ready.")
83
 
84
  def process_image_for_story(self, image_path: str, size: int, filename: str) -> str:
85
  """
86
+ Pré-processa uma imagem de referência, padronizando-a.
87
  """
88
  img = Image.open(image_path).convert("RGB")
89
  img_square = ImageOps.fit(img, (size, size), Image.Resampling.LANCZOS)
 
92
  logger.info(f"Reference image processed and saved to: {processed_path}")
93
  return processed_path
94
 
95
+ # --- TAREFAS DE PRÉ-PRODUÇÃO (Delegadas ao Pensador 2D) ---
96
 
97
  def task_generate_storyboard(self, prompt: str, num_keyframes: int, ref_image_paths: List[str],
98
  progress: gr.Progress) -> Tuple[List[str], str, Any]:
99
  """
100
+ Delega a criação do storyboard para o Deformes2DThinker.
101
  """
102
+ logger.info(f"Act 1, Scene 1: Delegating storyboard creation to the Thinker.")
103
+ progress(0.2, desc="Consulting the Thinker for the script...")
104
 
105
+ storyboard = self.thinker.generate_storyboard(prompt, num_keyframes, ref_image_paths)
106
 
107
+ logger.info(f"The Thinker returned the script: {storyboard}")
108
  self.director.update_state("storyboard", storyboard)
109
  self.director.update_state("processed_ref_paths", ref_image_paths)
110
  return storyboard, ref_image_paths[0], gr.update(visible=True, open=True)
111
 
112
+ # A geração de keyframes agora é parte da produção principal, então esta tarefa é removida.
113
+ # A seleção de keyframes para o modo fotógrafo permanece.
114
  def task_select_keyframes(self, storyboard: List[str], base_ref_paths: List[str],
115
  pool_ref_paths: List[str]) -> List[str]:
116
+ logger.info(f"Act 1, Scene 2 (Photographer Mode): Delegating keyframe selection to the Thinker.")
117
+ selected_paths = self.thinker.select_keyframes_from_pool(storyboard, base_ref_paths, pool_ref_paths)
 
 
 
 
118
  self.director.update_state("keyframes", selected_paths)
119
  return selected_paths
120
 
 
 
 
 
 
 
 
121
 
122
+ # --- TAREFA DE PRODUÇÃO UNIFICADA (Delegada ao Engenheiro-Chefe 7D) ---
123
+
124
+ def task_produce_full_movie(self, initial_ref_paths: List[str], global_prompt: str,
125
+ video_resolution: int, seconds_per_fragment: float,
126
+ # ... outros parâmetros do Deformes4D
127
+ trim_percent: int, handler_strength: float, dest_strength: float,
128
+ guidance_scale: float, stg_scale: float, inference_steps: int,
129
+ progress: gr.Progress) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
 
 
 
 
130
  """
131
+ Delega a produção completa do filme para o Deformes7DEngine.
132
  """
133
+ logger.info("Maestro: All systems go. Engaging the Turbo Intergalactic Engine (Deformes7D)...")
134
  storyboard = self.director.get_state("storyboard", [])
135
+ if not storyboard:
136
+ raise gr.Error("Storyboard not generated. Please complete Step 1 first.")
137
+
138
+ ltx_params = {
139
+ "guidance_scale": guidance_scale,
140
+ "stg_scale": stg_scale,
141
+ "num_inference_steps": inference_steps
142
+ }
143
+
144
+ # A chamada agora é para a função unificada do motor 7D
145
+ result = self.chief_engineer.generate_full_movie_interleaved(
146
+ initial_ref_paths=initial_ref_paths,
147
  storyboard=storyboard,
148
+ global_prompt=global_prompt,
149
+ video_resolution=video_resolution,
150
  seconds_per_fragment=seconds_per_fragment,
151
  trim_percent=trim_percent,
152
  handler_strength=handler_strength,
153
+ dest_strength=dest_strength,
154
+ ltx_params=ltx_params,
 
 
 
 
155
  progress=progress
156
  )
157
 
158
  self.director.update_state("final_video_path", result["final_path"])
159
+ self.director.update_state("all_keyframes", result["all_keyframes"])
160
+ logger.info("Maestro: Deformes7D has completed the main production run.")
161
  return result
162
 
163
+ # --- TAREFAS DE PÓS-PRODUÇÃO (Delegadas ao Engenheiro-Chefe 7D) ---
164
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def task_run_hd_mastering(self, source_video_path: str, model_version: str, steps: int, prompt: str, progress: gr.Progress) -> Generator[Dict[str, Any], None, None]:
166
+ logger.info(f"Maestro: Delegating HD mastering to the Chief Engineer.")
167
+ for update in self.chief_engineer.master_video_hd(
168
+ source_video_path=source_video_path, model_version=model_version,
169
+ steps=steps, prompt=prompt, progress=progress
 
 
 
 
 
 
170
  ):
171
+ yield update
172
+
 
 
 
 
173
  def task_run_audio_generation(self, source_video_path: str, audio_prompt: str, progress: gr.Progress) -> Generator[Dict[str, Any], None, None]:
174
+ logger.info(f"Maestro: Delegating audio generation to the Chief Engineer.")
175
+ for update in self.chief_engineer.generate_audio(
176
+ source_video_path=source_video_path, audio_prompt=audio_prompt, progress=progress
 
 
 
 
 
177
  ):
178
+ yield update