Update engineers/deformes3D.py
Browse files- engineers/deformes3D.py +24 -22
engineers/deformes3D.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
# engineers/deformes3D.py
|
|
|
|
| 2 |
# Copyright (C) 2025 Carlos Rodrigues dos Santos
|
| 3 |
#
|
| 4 |
-
#
|
| 5 |
-
#
|
| 6 |
-
#
|
|
|
|
|
|
|
| 7 |
|
| 8 |
from PIL import Image
|
| 9 |
import os
|
|
@@ -19,52 +22,48 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
|
| 20 |
class Deformes3DEngine:
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
"""
|
| 25 |
def __init__(self, workspace_dir):
|
| 26 |
self.workspace_dir = workspace_dir
|
| 27 |
self.image_generation_helper = flux_kontext_singleton
|
| 28 |
-
logger.info("
|
| 29 |
|
| 30 |
def _generate_single_keyframe(self, prompt: str, reference_images: list[Image.Image], output_filename: str, width: int, height: int, callback: callable = None) -> str:
|
| 31 |
"""
|
| 32 |
-
|
| 33 |
"""
|
| 34 |
-
logger.info(f"
|
| 35 |
generated_image = self.image_generation_helper.generate_image(
|
| 36 |
reference_images=reference_images, prompt=prompt, width=width,
|
| 37 |
height=height, seed=int(time.time()), callback=callback
|
| 38 |
)
|
| 39 |
final_path = os.path.join(self.workspace_dir, output_filename)
|
| 40 |
generated_image.save(final_path)
|
| 41 |
-
logger.info(f"Keyframe
|
| 42 |
return final_path
|
| 43 |
|
| 44 |
def generate_keyframes_from_storyboard(self, storyboard: list, initial_ref_path: str, global_prompt: str, keyframe_resolution: int, general_ref_paths: list, progress_callback_factory: callable = None):
|
| 45 |
"""
|
| 46 |
-
|
| 47 |
"""
|
| 48 |
current_base_image_path = initial_ref_path
|
| 49 |
-
previous_prompt = "N/A (
|
| 50 |
final_keyframes = [current_base_image_path]
|
| 51 |
width, height = keyframe_resolution, keyframe_resolution
|
| 52 |
|
| 53 |
-
# O número de keyframes a gerar é len(storyboard) - 1, pois o primeiro keyframe já existe (initial_ref_path)
|
| 54 |
-
# E o storyboard tem o mesmo número de elementos que o número total de keyframes desejados.
|
| 55 |
num_keyframes_to_generate = len(storyboard) - 1
|
| 56 |
|
| 57 |
-
logger.info(f"
|
| 58 |
|
| 59 |
for i in range(num_keyframes_to_generate):
|
| 60 |
-
# A cena atual é a transição de storyboard[i] para storyboard[i+1]
|
| 61 |
current_scene = storyboard[i]
|
| 62 |
future_scene = storyboard[i+1]
|
| 63 |
progress_callback = progress_callback_factory(i + 1, num_keyframes_to_generate) if progress_callback_factory else None
|
| 64 |
|
| 65 |
-
logger.info(f"-->
|
| 66 |
|
| 67 |
-
# O próprio especialista consulta o Gemini para o prompt de imagem
|
| 68 |
new_flux_prompt = gemini_manager_singleton.get_anticipatory_keyframe_prompt(
|
| 69 |
global_prompt=global_prompt, scene_history=previous_prompt,
|
| 70 |
current_scene_desc=current_scene, future_scene_desc=future_scene,
|
|
@@ -84,15 +83,18 @@ class Deformes3DEngine:
|
|
| 84 |
current_base_image_path = new_keyframe_path
|
| 85 |
previous_prompt = new_flux_prompt
|
| 86 |
|
| 87 |
-
logger.info(f"
|
| 88 |
return final_keyframes
|
| 89 |
|
| 90 |
-
# Singleton
|
| 91 |
try:
|
| 92 |
with open("config.yaml", 'r') as f:
|
| 93 |
config = yaml.safe_load(f)
|
| 94 |
WORKSPACE_DIR = config['application']['workspace_dir']
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
except Exception as e:
|
| 97 |
-
logger.error(f"
|
| 98 |
-
|
|
|
|
| 1 |
# engineers/deformes3D.py
|
| 2 |
+
#
|
| 3 |
# Copyright (C) 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Version: 1.1.0
|
| 6 |
+
#
|
| 7 |
+
# This program is free software: you can redistribute it and/or modify
|
| 8 |
+
# it under the terms of the GNU Affero General Public License...
|
| 9 |
+
# PENDING PATENT NOTICE: Please see NOTICE.md.
|
| 10 |
|
| 11 |
from PIL import Image
|
| 12 |
import os
|
|
|
|
| 22 |
|
| 23 |
class Deformes3DEngine:
|
| 24 |
"""
|
| 25 |
+
ADUC Specialist for static image (keyframe) generation.
|
| 26 |
+
This is responsible for the entire process of turning a script into a gallery of keyframes.
|
| 27 |
"""
|
| 28 |
def __init__(self, workspace_dir):
|
| 29 |
self.workspace_dir = workspace_dir
|
| 30 |
self.image_generation_helper = flux_kontext_singleton
|
| 31 |
+
logger.info("3D Engine (Image Specialist) ready to receive orders from the Maestro.")
|
| 32 |
|
| 33 |
def _generate_single_keyframe(self, prompt: str, reference_images: list[Image.Image], output_filename: str, width: int, height: int, callback: callable = None) -> str:
|
| 34 |
"""
|
| 35 |
+
Low-level function that generates a single image.
|
| 36 |
"""
|
| 37 |
+
logger.info(f"Generating keyframe '{output_filename}' with prompt: '{prompt}'")
|
| 38 |
generated_image = self.image_generation_helper.generate_image(
|
| 39 |
reference_images=reference_images, prompt=prompt, width=width,
|
| 40 |
height=height, seed=int(time.time()), callback=callback
|
| 41 |
)
|
| 42 |
final_path = os.path.join(self.workspace_dir, output_filename)
|
| 43 |
generated_image.save(final_path)
|
| 44 |
+
logger.info(f"Keyframe successfully saved to: {final_path}")
|
| 45 |
return final_path
|
| 46 |
|
| 47 |
def generate_keyframes_from_storyboard(self, storyboard: list, initial_ref_path: str, global_prompt: str, keyframe_resolution: int, general_ref_paths: list, progress_callback_factory: callable = None):
|
| 48 |
"""
|
| 49 |
+
Orchestrates the generation of all keyframes from a storyboard.
|
| 50 |
"""
|
| 51 |
current_base_image_path = initial_ref_path
|
| 52 |
+
previous_prompt = "N/A (initial reference image)"
|
| 53 |
final_keyframes = [current_base_image_path]
|
| 54 |
width, height = keyframe_resolution, keyframe_resolution
|
| 55 |
|
|
|
|
|
|
|
| 56 |
num_keyframes_to_generate = len(storyboard) - 1
|
| 57 |
|
| 58 |
+
logger.info(f"IMAGE SPECIALIST: Received order to generate {num_keyframes_to_generate} keyframes.")
|
| 59 |
|
| 60 |
for i in range(num_keyframes_to_generate):
|
|
|
|
| 61 |
current_scene = storyboard[i]
|
| 62 |
future_scene = storyboard[i+1]
|
| 63 |
progress_callback = progress_callback_factory(i + 1, num_keyframes_to_generate) if progress_callback_factory else None
|
| 64 |
|
| 65 |
+
logger.info(f"--> Generating Keyframe {i+1}/{num_keyframes_to_generate}...")
|
| 66 |
|
|
|
|
| 67 |
new_flux_prompt = gemini_manager_singleton.get_anticipatory_keyframe_prompt(
|
| 68 |
global_prompt=global_prompt, scene_history=previous_prompt,
|
| 69 |
current_scene_desc=current_scene, future_scene_desc=future_scene,
|
|
|
|
| 83 |
current_base_image_path = new_keyframe_path
|
| 84 |
previous_prompt = new_flux_prompt
|
| 85 |
|
| 86 |
+
logger.info(f"IMAGE SPECIALIST: Keyframe generation complete.")
|
| 87 |
return final_keyframes
|
| 88 |
|
| 89 |
+
# --- Singleton Instantiation ---
|
| 90 |
try:
|
| 91 |
with open("config.yaml", 'r') as f:
|
| 92 |
config = yaml.safe_load(f)
|
| 93 |
WORKSPACE_DIR = config['application']['workspace_dir']
|
| 94 |
+
|
| 95 |
+
# Correctly instantiate the Deformes3DEngine class
|
| 96 |
+
deformes3d_engine_singleton = Deformes3DEngine(workspace_dir=WORKSPACE_DIR)
|
| 97 |
+
|
| 98 |
except Exception as e:
|
| 99 |
+
logger.error(f"Could not initialize Deformes3DEngine: {e}", exc_info=True)
|
| 100 |
+
deformes3d_engine_singleton = None
|