Aduc-sdr commited on
Commit
9fc61b2
·
verified ·
1 Parent(s): 228911e

Create deformes3D_thinker.py

Browse files
Files changed (1) hide show
  1. engineers/deformes3D_thinker.py +77 -0
engineers/deformes3D_thinker.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # engineers/deformes3D_thinker.py
2
+ #
3
+ # Copyright (C) 2025 Carlos Rodrigues dos Santos
4
+ #
5
+ # Version: 1.0.0
6
+ #
7
+ # This file defines the Deformes3DThinker, the tactical cinematic director
8
+ # of the ADUC framework. Its sole responsibility is to analyze the immediate
9
+ # temporal context (past, present, future keyframes) to generate the optimal
10
+ # motion prompt for the video generation engine.
11
+
12
+ import logging
13
+ from pathlib import Path
14
+ from PIL import Image
15
+ import gradio as gr
16
+
17
+ from managers.gemini_manager import gemini_manager_singleton
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ class Deformes3DThinker:
22
+ """
23
+ The tactical specialist that handles cinematic decision-making.
24
+ """
25
+ def _read_prompt_template(self, filename: str) -> str:
26
+ """Reads a prompt template file from the 'prompts' directory."""
27
+ try:
28
+ prompts_dir = Path(__file__).resolve().parent.parent / "prompts"
29
+ with open(prompts_dir / filename, "r", encoding="utf-8") as f:
30
+ return f.read()
31
+ except FileNotFoundError:
32
+ raise gr.Error(f"Prompt template file not found: prompts/{filename}")
33
+
34
+ def get_cinematic_decision(self, global_prompt: str, story_history: str,
35
+ past_keyframe_path: str, present_keyframe_path: str, future_keyframe_path: str,
36
+ past_scene_desc: str, present_scene_desc: str, future_scene_desc: str) -> dict:
37
+ """
38
+ Acts as a Film Director to make editing decisions and generate motion prompts
39
+ by analyzing the past, present, and future visual and narrative context.
40
+ """
41
+ try:
42
+ template = self._read_prompt_template("cinematic_director_prompt.txt")
43
+ prompt_text = template.format(
44
+ global_prompt=global_prompt,
45
+ story_history=story_history,
46
+ past_scene_desc=past_scene_desc,
47
+ present_scene_desc=present_scene_desc,
48
+ future_scene_desc=future_scene_desc
49
+ )
50
+
51
+ prompt_parts = [
52
+ prompt_text,
53
+ "[PAST_IMAGE]:", Image.open(past_keyframe_path),
54
+ "[PRESENT_IMAGE]:", Image.open(present_keyframe_path),
55
+ "[FUTURE_IMAGE]:", Image.open(future_keyframe_path)
56
+ ]
57
+
58
+ decision_data = gemini_manager_singleton.get_json_object(prompt_parts)
59
+
60
+ if "transition_type" not in decision_data or "motion_prompt" not in decision_data:
61
+ raise ValueError("AI response (Cinematographer) is malformed. Missing 'transition_type' or 'motion_prompt'.")
62
+
63
+ # --- LOGGING ADICIONADO ---
64
+ logger.info(f"Deformes3DThinker Decision -> Transition: '{decision_data['transition_type']}', Motion Prompt: '{decision_data['motion_prompt']}'")
65
+
66
+ return decision_data
67
+ except Exception as e:
68
+ logger.error(f"The Film Director (Deformes3D Thinker) failed: {e}. Using fallback.", exc_info=True)
69
+ fallback_prompt = f"A smooth, continuous cinematic transition from '{present_scene_desc}' to '{future_scene_desc}'."
70
+ logger.info(f"Deformes3DThinker Fallback -> Transition: 'continuous', Motion Prompt: '{fallback_prompt}'")
71
+ return {
72
+ "transition_type": "continuous",
73
+ "motion_prompt": fallback_prompt
74
+ }
75
+
76
+ # --- Singleton Instance ---
77
+ deformes3d_thinker_singleton = Deformes3DThinker()