mgbam commited on
Commit
5083a4b
Β·
verified Β·
1 Parent(s): 3399f15

Update core/prompt_engineering.py

Browse files
Files changed (1) hide show
  1. core/prompt_engineering.py +117 -84
core/prompt_engineering.py CHANGED
@@ -21,115 +21,148 @@ def create_cinematic_treatment_prompt(user_idea, genre, mood, num_scenes=3, crea
21
  Number of Key Scenes: {num_scenes}
22
  Creative Guidance Level: {creative_guidance} ({guidance_detail})
23
 
24
- Task: Develop a rich cinematic treatment. For EACH of the {num_scenes} key scenes, provide:
25
  1. `scene_number` (int): Sequential.
26
  2. `scene_title` (str): A short, evocative title for the scene (e.g., "The Neon Rains of Sector 7", "Echoes in the Void").
27
  3. `setting_description` (str): Vivid, sensory details (sight, sound, atmosphere). Where are we? What makes it unique? (40-60 words).
28
- 4. `characters_involved` (list of str): Names of characters central to this scene.
29
- 5. `character_focus_moment` (str): For the primary character(s) in this scene, describe a key internal thought, subtle expression, or micro-action that reveals their state of mind or advances their arc.
30
- 6. `key_plot_beat` (str): The most critical plot development or character action in this scene (1-2 sentences).
31
- 7. `suggested_dialogue_hook` (str): One potent line of dialogue that captures the scene's essence or a character's voice. (If no dialogue, state "Silent scene").
32
  8. `PROACTIVE_visual_style_감독` (str): Your proactive, detailed suggestion for this scene's visual style. Go beyond generic terms. Think specific art movements, film references, color theory, lighting techniques (e.g., "Dutch angles with chiaroscuro lighting, using a desaturated palette with piercing cyan highlights, reminiscent of early Tarkovsky but with a cyberpunk edge").
33
  9. `PROACTIVE_camera_work_감독` (str): Your proactive suggestion for impactful camera work. Describe a specific shot or short sequence (e.g., "Slow dolly zoom into the protagonist's eyes, followed by a whip pan to reveal the approaching threat off-screen").
34
  10. `PROACTIVE_sound_design_감독` (str): Key ambient sounds, specific SFX, and a suggestion for the musical mood/instrumentation for this scene (e.g., "Ambient: Distant city hum, dripping water. SFX: Glitching electronic spark. Music: Low, ominous synth pads with a recurring, detuned piano motif").
35
- 11. `dalle_image_prompt_keywords` (str): A concise list of 5-7 powerful keywords extracted from the above, specifically for generating a DALL-E image that captures the visual essence of this scene. Focus on nouns, strong adjectives, and artistic styles. (e.g., "cyberpunk alleyway, neon rain, lone figure, glowing data streams, high contrast, cinematic").
36
- 12. `pexels_search_query_감독` (str): A concise, effective search query (2-4 words) for Pexels to find a background or atmospheric shot relevant to this scene's setting or mood (e.g., "rainy neon city," "vast desert landscape," "server room interior").
37
 
38
- If `creative_guidance` is "experimental_narrative", for one scene, you may subtly alter `key_plot_beat` or add a symbolic element to `setting_description` to introduce an unexpected twist, explaining your reasoning briefly in a `director_note` field for that scene only.
39
 
40
  Output ONLY a valid JSON list of these scene objects. Ensure all field names are exactly as specified (감독 denotes your proactive directorial input).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  """
42
 
43
- # create_image_prompt_from_scene_data - THIS WILL NOW BE SIMPLER.
44
- # Gemini already gave us dalle_image_prompt_keywords. We can build upon that.
45
  def construct_dalle_prompt(scene_data, character_definitions=None, global_style_additions=""):
46
  """
47
- Constructs the final DALL-E prompt using keywords from Gemini,
48
- character details, and global style.
49
  """
50
- base_keywords = scene_data.get('dalle_image_prompt_keywords', 'cinematic scene')
51
- setting_desc = scene_data.get('setting_description', '') # For context
52
- action_desc = scene_data.get('key_plot_beat', '') # For context
53
- director_visual_style = scene_data.get('PROACTIVE_visual_style_감독', '')
54
- director_camera = scene_data.get('PROACTIVE_camera_work_감독', '')
55
-
56
- character_details_for_prompt = []
57
- # ... (Character injection logic remains the same as your last version, using char_name_lookup etc.)
58
- if scene_data.get('characters_involved'):
59
- for char_name_in_scene in scene_data.get('characters_involved', []):
60
- char_name_clean = char_name_in_scene.strip(); char_lookup_key = char_name_clean.lower()
 
 
 
 
 
 
61
  if character_definitions and char_lookup_key in character_definitions:
62
- character_details_for_prompt.append(f"{char_name_clean} ({character_definitions[char_lookup_key]})")
63
- else: character_prompt_segments.append(char_name_clean)
 
 
64
 
65
  character_narrative = ""
66
- if character_details_for_prompt:
67
- character_narrative = f" Characters featured: {', '.join(character_details_for_prompt)}."
68
-
69
- # DALL-E 3 often prefers more natural language but benefits from strong keywords.
70
- # We combine Gemini's suggestions with a structured approach.
 
 
 
 
 
 
 
71
  prompt = (
72
- f"Create an ultra-detailed, photorealistic, and highly cinematic masterpiece image. "
73
- f"Theme: '{scene_data.get('scene_title', 'A dramatic moment')}'. "
74
- f"Core visual elements based on keywords: {base_keywords}. " # Gemini's keywords
75
- f"{character_narrative} " # Injected character descriptions
76
- f"The scene unfolds in this setting: {setting_desc}. The key moment is: {action_desc}. "
77
- f"Artistic Direction -- Visual Style: {director_visual_style}. {global_style_additions}. "
78
- f"Cinematography -- Camera Work: {director_camera}. "
79
- f"Overall Impression: Evoke the mood of '{scene_data.get('mood', 'intense')}' with an atmosphere of '{scene_data.get('emotional_beat', 'suspense')}'. "
80
- f"Render with extreme detail, complex lighting, and rich textures suitable for a blockbuster film's concept art. "
 
 
81
  )
82
- return " ".join(prompt.split())
 
83
 
84
 
85
  def create_narration_script_prompt_enhanced(story_scenes_data, overall_mood, overall_genre, voice_style="cinematic_trailer"):
86
- """
87
- Generates a more nuanced narration script prompt for Gemini.
88
- voice_style: "cinematic_trailer", "documentary_neutral", "introspective_character"
89
- """
90
- # ... (scene summary logic remains the same as your last version) ...
91
  scenes_summary = []
92
  for i, scene in enumerate(story_scenes_data):
93
  scenes_summary.append(
94
- f"Scene {scene.get('scene_number', i+1)} ({scene.get('scene_title','Untitled')} - {scene.get('emotional_beat','')})"
95
- f": {scene.get('key_plot_beat','')} Focus: {scene.get('character_focus_moment','')} "
96
- f"Soundscape hint: {scene.get('PROACTIVE_sound_design_감독','')}"
 
 
 
97
  )
98
- full_summary_text = "\n".join(scenes_summary)
99
 
100
  voice_style_description = {
101
- "cinematic_trailer": "deep, resonant, and slightly epic, building anticipation.",
102
- "documentary_neutral": "clear, informative, and objective.",
103
- "introspective_character": f"reflective, personal, perhaps echoing the thoughts of a key character (e.g., Jax, if present)."
104
  }[voice_style]
105
 
106
  prompt = f"""
107
- You are an award-winning voiceover scriptwriter.
108
- Craft a compelling, continuous narration script for a short cinematic animatic based on these scene insights:
109
- --- SCENE INSIGHTS ---
 
110
  {full_summary_text}
111
- --- END SCENE INSIGHTS ---
112
 
113
- Overall Genre: {overall_genre}
114
- Overall Mood: {overall_mood}
115
  Desired Voiceover Style: {voice_style} (Characteristics: {voice_style_description})
116
 
117
- The narration should:
118
- - Weave a cohesive narrative thread through the scenes.
119
- - Enhance emotional impact and atmosphere, guided by the scene's 'emotional_beat' and 'soundscape_hint'.
120
- - Be concise: Aim for 1-2 powerful sentences per scene. Total words ~60-100 for 3-4 scenes.
121
- - Avoid merely describing the action; instead, offer insight, build tension, or evoke thematic depth.
122
- - If style is 'introspective_character', imagine one of the characters is narrating their internal monologue.
 
123
 
124
- Output ONLY the pure narration script text, ready for text-to-speech. No scene numbers, no "VO:", just the spoken words.
 
 
 
125
  """
126
  return " ".join(prompt.split())
127
 
128
- # create_scene_regeneration_prompt - Now uses the new fields
129
  def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_story_context=None):
130
- # ... (context_str same) ...
131
  context_str = f"Original scene (Scene Number {original_scene_data.get('scene_number')} - Title: {original_scene_data.get('scene_title')} ):\n{json.dumps(original_scene_data, indent=2)}\n\n"
132
- if full_story_context: context_str += f"Full story context:\n{json.dumps(full_story_context, indent=2)}\n\n"
133
 
134
  return f"""
135
  You are an AI Script Supervisor and Creative Consultant.
@@ -138,24 +171,23 @@ def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_st
138
 
139
  Regenerate ONLY the JSON object for this single scene, incorporating the feedback.
140
  Maintain the exact field structure: (scene_number, scene_title, setting_description, characters_involved, character_focus_moment, key_plot_beat, suggested_dialogue_hook, PROACTIVE_visual_style_감독, PROACTIVE_camera_work_감독, PROACTIVE_sound_design_감독, dalle_image_prompt_keywords, pexels_search_query_감독).
141
- 'scene_number' MUST NOT change.
142
- If feedback targets plot, characters, or dialogue, adjust relevant fields.
143
- If feedback targets visuals, camera, or sound, update the 'PROACTIVE_..._감독' fields AND the 'dalle_image_prompt_keywords' and 'pexels_search_query_감독' to reflect the new direction.
144
- Ensure 'key_plot_beat' is a concise sentence (max 15-20 words).
145
- If adding a `director_note` due to experimental narrative changes, ensure it's brief.
146
  """
147
 
148
- # create_visual_regeneration_prompt - Now uses more context for Gemini to rewrite DALL-E prompt
149
  def create_visual_regeneration_prompt(original_dalle_prompt, user_feedback, scene_data, character_definitions=None, global_style_additions=""):
150
- # ... (character_narrative same as in construct_dalle_prompt) ...
151
  characters_involved_in_scene = scene_data.get('characters_involved', [])
152
- character_prompt_segments = []
153
  if characters_involved_in_scene:
154
  for char_name_from_scene in characters_involved_in_scene:
155
  char_name_clean = char_name_from_scene.strip(); char_lookup_key = char_name_clean.lower()
156
- if character_definitions and char_lookup_key in character_definitions: character_prompt_segments.append(f"{char_name_clean} ({character_definitions[char_lookup_key]})")
157
- else: character_prompt_segments.append(char_name_clean)
158
- characters_narrative = f" Characters to feature: {', '.join(character_prompt_segments) if character_prompt_segments else 'None specifically detailed'}."
 
159
 
160
  full_prompt_for_gemini = f"""
161
  You are an AI Art Director specializing in refining DALL-E 3 prompts for cinematic visuals.
@@ -170,20 +202,21 @@ def create_visual_regeneration_prompt(original_dalle_prompt, user_feedback, scen
170
  - Director's Suggested Camera: "{scene_data.get('PROACTIVE_camera_work_감독', '')}"
171
  - Current Global Style Additions: "{global_style_additions}"
172
 
173
- The PREVIOUS DALL-E 3 prompt was:
174
  "{original_dalle_prompt}"
175
 
176
- User Feedback on the image generated by the previous prompt:
177
  "{user_feedback}"
178
 
179
  Your Task: Generate a NEW, revised DALL-E 3 prompt.
180
  This new prompt must incorporate the user's feedback to achieve the desired visual changes.
181
  It should remain ultra-detailed, photorealistic, and highly cinematic.
182
  The prompt should guide DALL-E 3 to create a stunning image suitable for a film's concept art.
183
- Maintain core scene elements (setting, characters, plot beat) unless feedback explicitly requests changes.
184
  Translate feedback into concrete visual descriptions (lighting, color, composition, character appearance/pose, atmosphere).
185
- Reinforce character descriptions if they are relevant to the feedback.
 
186
 
187
- Output ONLY the new, revised DALL-E 3 prompt string. Do not add any other text.
188
  """
189
  return " ".join(full_prompt_for_gemini.split())
 
21
  Number of Key Scenes: {num_scenes}
22
  Creative Guidance Level: {creative_guidance} ({guidance_detail})
23
 
24
+ Task: Develop a rich cinematic treatment. For EACH of the {num_scenes} key scenes, provide the following fields EXACTLY as named:
25
  1. `scene_number` (int): Sequential.
26
  2. `scene_title` (str): A short, evocative title for the scene (e.g., "The Neon Rains of Sector 7", "Echoes in the Void").
27
  3. `setting_description` (str): Vivid, sensory details (sight, sound, atmosphere). Where are we? What makes it unique? (40-60 words).
28
+ 4. `characters_involved` (list of str): Names of characters central to this scene. If a character is non-speaking or an entity (e.g., "Scavenger Drone"), list them.
29
+ 5. `character_focus_moment` (str): For the primary character(s) in this scene, describe a key internal thought, subtle expression, or micro-action that reveals their state of mind or advances their arc. If no specific character focus, describe the general atmosphere's impact.
30
+ 6. `key_plot_beat` (str): The most critical plot development or character action in this scene (1-2 sentences). This should be suitable for a brief video overlay.
31
+ 7. `suggested_dialogue_hook` (str): One potent line of dialogue that captures the scene's essence or a character's voice. (If no dialogue, state "Silent scene" or describe key non-verbal communication).
32
  8. `PROACTIVE_visual_style_감독` (str): Your proactive, detailed suggestion for this scene's visual style. Go beyond generic terms. Think specific art movements, film references, color theory, lighting techniques (e.g., "Dutch angles with chiaroscuro lighting, using a desaturated palette with piercing cyan highlights, reminiscent of early Tarkovsky but with a cyberpunk edge").
33
  9. `PROACTIVE_camera_work_감독` (str): Your proactive suggestion for impactful camera work. Describe a specific shot or short sequence (e.g., "Slow dolly zoom into the protagonist's eyes, followed by a whip pan to reveal the approaching threat off-screen").
34
  10. `PROACTIVE_sound_design_감독` (str): Key ambient sounds, specific SFX, and a suggestion for the musical mood/instrumentation for this scene (e.g., "Ambient: Distant city hum, dripping water. SFX: Glitching electronic spark. Music: Low, ominous synth pads with a recurring, detuned piano motif").
35
+ 11. `dalle_image_prompt_keywords` (str): A concise list of 5-7 powerful keywords extracted from all the above details (setting, characters, action, style, camera), specifically for generating a DALL-E image that captures the visual essence of this scene. Focus on nouns, strong adjectives, and artistic styles. (e.g., "cyberpunk alleyway, neon rain, lone figure Jax, glowing data streams, high contrast shadows, cinematic low-angle").
36
+ 12. `pexels_search_query_감독` (str): A concise, effective search query (2-4 words) for Pexels to find a background or atmospheric shot relevant to this scene's setting or mood (e.g., "rainy neon city," "vast desert landscape," "dark server room interior").
37
 
38
+ If `creative_guidance` is "experimental_narrative", for ONLY ONE of the scenes, you may subtly alter `key_plot_beat` or add a symbolic element to `setting_description` to introduce an unexpected twist. If you do this, add a field `director_note` (str) to THAT SCENE ONLY, briefly explaining your creative choice for the twist.
39
 
40
  Output ONLY a valid JSON list of these scene objects. Ensure all field names are exactly as specified (감독 denotes your proactive directorial input).
41
+ Example for one scene object (ensure all fields are present for every scene):
42
+ {{
43
+ "scene_number": 1,
44
+ "scene_title": "Sun-Bleached Mirage",
45
+ "setting_description": "The relentless sun beats down on endless rust-colored dunes, shimmering with heat haze. Skeletal remains of colossal, forgotten machinery litter the landscape, half-buried by the sands of time. The air hangs heavy with the scent of dust and decay, punctuated by the occasional groan of shifting metal.",
46
+ "characters_involved": ["Anya"],
47
+ "character_focus_moment": "Anya's hand, cracked and sunburnt, instinctively reaches for the worn leather strap of her water canteen - almost empty. A flicker of doubt crosses her face, quickly masked by a determined set to her jaw.",
48
+ "key_plot_beat": "Anya, fueled by a tattered map and dwindling hope, navigates the treacherous dunes, avoiding a patrol of mechanical scavengers.",
49
+ "suggested_dialogue_hook": "(Anya, to herself, raspy whisper) 'Almost there... just a little further.'",
50
+ "PROACTIVE_visual_style_감독": "Widescreen anamorphic, sun-bleached desaturated palette with occasional metallic glints. High dynamic range, emphasizing the harshness of the sun and the deep shadows. Inspired by 'Mad Max: Fury Road' meets 'Dune (2021)' cinematography. Visible heat distortion.",
51
+ "PROACTIVE_camera_work_감독": "Extreme long shot establishing Anya as a tiny figure in the vast desert, then a gritty close-up on her determined, weathered face. Slow, deliberate tracking shots as she moves.",
52
+ "PROACTIVE_sound_design_감독": "Ambient: Howling wind, metallic creaks of distant machinery. SFX: Crunch of sand underfoot, Anya's strained breathing. Music: Sparse, atmospheric, with low, mournful synth drones and occasional percussive hits.",
53
+ "dalle_image_prompt_keywords": "post-apocalyptic desert, lone wanderer Anya, rust-colored dunes, colossal wreckages, heat haze, cinematic widescreen, sun-bleached",
54
+ "pexels_search_query_감독": "vast desert sun"
55
+ }}
56
  """
57
 
 
 
58
  def construct_dalle_prompt(scene_data, character_definitions=None, global_style_additions=""):
59
  """
60
+ Constructs the final DALL-E prompt using keywords from Gemini's treatment,
61
+ injecting character details, and global style preferences.
62
  """
63
+ scene_title = scene_data.get('scene_title', 'A dramatic moment')
64
+ base_keywords = scene_data.get('dalle_image_prompt_keywords', 'cinematic scene, highly detailed')
65
+ setting_desc_context = scene_data.get('setting_description', '')
66
+ action_desc_context = scene_data.get('key_plot_beat', '')
67
+ director_visual_style = scene_data.get('PROACTIVE_visual_style_감독', '') # This is key
68
+ director_camera = scene_data.get('PROACTIVE_camera_work_감독', '') # This is key
69
+ emotional_beat_context = scene_data.get('emotional_beat', scene_title) # Fallback to scene_title
70
+
71
+ # --- Character Injection ---
72
+ # This variable MUST be initialized OUTSIDE the conditional block if it's used in an else inside the loop
73
+ current_scene_character_details = []
74
+ characters_involved_in_scene = scene_data.get('characters_involved', [])
75
+ if characters_involved_in_scene:
76
+ for char_name_from_scene in characters_involved_in_scene:
77
+ char_name_clean = char_name_from_scene.strip()
78
+ char_lookup_key = char_name_clean.lower()
79
+
80
  if character_definitions and char_lookup_key in character_definitions:
81
+ char_visual_desc = character_definitions[char_lookup_key]
82
+ current_scene_character_details.append(f"{char_name_clean} (depicted as: {char_visual_desc})")
83
+ else:
84
+ current_scene_character_details.append(char_name_clean) # Character present but no specific definition
85
 
86
  character_narrative = ""
87
+ if current_scene_character_details:
88
+ if len(current_scene_character_details) == 1:
89
+ character_narrative = f"The scene focuses on {current_scene_character_details[0]}."
90
+ else:
91
+ character_narrative = f"The scene prominently features {', '.join(current_scene_character_details[:-1])} and {current_scene_character_details[-1]}."
92
+ # --- End Character Injection ---
93
+
94
+ final_style_directive = director_visual_style
95
+ if global_style_additions:
96
+ final_style_directive = f"{director_visual_style}. Additional global style notes: {global_style_additions}."
97
+
98
+ # Constructing the DALL-E 3 prompt
99
  prompt = (
100
+ f"Create an ultra-detailed, photorealistic, and intensely cinematic digital painting or high-fidelity concept art. "
101
+ f"The image must visually embody the scene titled: '{scene_title}'. "
102
+ f"Core visual elements and keywords to include: {base_keywords}. "
103
+ f"{character_narrative} "
104
+ f"Contextual narrative for the visual: The setting is '{setting_desc_context}'. The key moment unfolding is '{action_desc_context}'. "
105
+ f"Artistic Direction -- Overall Visual Style and Mood: {final_style_directive}. "
106
+ f"Cinematography -- Camera Framing and Perspective: {director_camera}. "
107
+ f"Emotional Impact: Convey a strong sense of '{emotional_beat_context}'. "
108
+ f"Technical Execution: Render with extreme detail, sophisticated lighting that sculpts the forms and defines the mood (e.g., dramatic rim lighting, soft diffused light, harsh contrasts), rich and believable textures, and palpable atmospheric effects (e.g., mist, dust, lens flares, rain). "
109
+ f"The final image should be of exceptional quality, suitable for a major film production's visual development phase. "
110
+ f"Ensure all specified characters are distinct and adhere to their descriptions if provided."
111
  )
112
+
113
+ return " ".join(prompt.split()) # Normalize whitespace
114
 
115
 
116
  def create_narration_script_prompt_enhanced(story_scenes_data, overall_mood, overall_genre, voice_style="cinematic_trailer"):
 
 
 
 
 
117
  scenes_summary = []
118
  for i, scene in enumerate(story_scenes_data):
119
  scenes_summary.append(
120
+ f"Scene {scene.get('scene_number', i+1)} (Title: '{scene.get('scene_title','Untitled')}', Beat: '{scene.get('emotional_beat','')}'):\n"
121
+ f" Setting: {scene.get('setting_description','')}\n"
122
+ f" Plot Beat: {scene.get('key_plot_beat','')}\n"
123
+ f" Character Focus: {scene.get('character_focus_moment','(general atmosphere)')}\n"
124
+ f" Dialogue Hook: {scene.get('suggested_dialogue_hook','(none)')}\n"
125
+ f" Director's Sound Hint: {scene.get('PROACTIVE_sound_design_감독','')}"
126
  )
127
+ full_summary_text = "\n\n".join(scenes_summary)
128
 
129
  voice_style_description = {
130
+ "cinematic_trailer": "deep, resonant, slightly epic, building anticipation, and authoritative.",
131
+ "documentary_neutral": "clear, informative, objective, and well-paced.",
132
+ "introspective_character": f"reflective, personal, possibly first-person, echoing the thoughts of a key character involved in the scenes."
133
  }[voice_style]
134
 
135
  prompt = f"""
136
+ You are an award-winning voiceover scriptwriter tasked with creating narration for a cinematic animatic.
137
+ The animatic is based on the following scene treatments:
138
+
139
+ --- SCENE TREATMENTS ---
140
  {full_summary_text}
141
+ --- END SCENE TREATMENTS ---
142
 
143
+ Overall Story Genre: {overall_genre}
144
+ Overall Story Mood: {overall_mood}
145
  Desired Voiceover Style: {voice_style} (Characteristics: {voice_style_description})
146
 
147
+ Your narration script should:
148
+ - Weave a cohesive and compelling narrative thread through all the provided scenes.
149
+ - Enhance the emotional impact and atmosphere, drawing inspiration from each scene's 'emotional_beat', 'character_focus_moment', and 'sound_hint'.
150
+ - Be concise yet powerful. Aim for 1-3 impactful sentences per scene. For {len(story_scenes_data)} scenes, the total script should be roughly {len(story_scenes_data) * 20}-{len(story_scenes_data) * 30} words.
151
+ - Transcend simple description of action. Instead, offer insight, build tension/emotion, or evoke thematic depth.
152
+ - If the style is 'introspective_character', choose one prominent character and write from their perspective, reflecting their internal state and observations.
153
+ - The final output must be ONLY the narration script text, ready for text-to-speech. Do not include scene numbers, titles, or any directives like "(Voiceover)" or "Narrator:".
154
 
155
+ Example of desired output format (for a different story):
156
+ "Dust motes danced in the lone shaft of light, illuminating forgotten relics. Each step echoed in the vast silence, a countdown to an unknown answerm or perhaps, a more terrifying question. The air grew colder, heavy with the scent of ozone and ancient despair..."
157
+
158
+ Craft your narration now.
159
  """
160
  return " ".join(prompt.split())
161
 
162
+
163
  def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_story_context=None):
 
164
  context_str = f"Original scene (Scene Number {original_scene_data.get('scene_number')} - Title: {original_scene_data.get('scene_title')} ):\n{json.dumps(original_scene_data, indent=2)}\n\n"
165
+ if full_story_context: context_str += f"Full story context for reference:\n{json.dumps(full_story_context, indent=2)}\n\n"
166
 
167
  return f"""
168
  You are an AI Script Supervisor and Creative Consultant.
 
171
 
172
  Regenerate ONLY the JSON object for this single scene, incorporating the feedback.
173
  Maintain the exact field structure: (scene_number, scene_title, setting_description, characters_involved, character_focus_moment, key_plot_beat, suggested_dialogue_hook, PROACTIVE_visual_style_감독, PROACTIVE_camera_work_감독, PROACTIVE_sound_design_감독, dalle_image_prompt_keywords, pexels_search_query_감독).
174
+ The 'scene_number' MUST NOT change.
175
+ The 'key_plot_beat' should be a concise descriptive sentence (max 15-20 words).
176
+ The 'dalle_image_prompt_keywords' should be updated to reflect any visual changes.
177
+ The 'pexels_search_query_감독' should also be updated if the setting or mood changes significantly.
178
+ If the user's feedback implies experimental narrative changes and the original scene had a `director_note`, you may update or remove it. If introducing a new experimental twist, add/update the `director_note` field.
179
  """
180
 
 
181
  def create_visual_regeneration_prompt(original_dalle_prompt, user_feedback, scene_data, character_definitions=None, global_style_additions=""):
 
182
  characters_involved_in_scene = scene_data.get('characters_involved', [])
183
+ current_scene_character_details = [] # Initialize correctly
184
  if characters_involved_in_scene:
185
  for char_name_from_scene in characters_involved_in_scene:
186
  char_name_clean = char_name_from_scene.strip(); char_lookup_key = char_name_clean.lower()
187
+ if character_definitions and char_lookup_key in character_definitions:
188
+ current_scene_character_details.append(f"{char_name_clean} (described as: {character_definitions[char_lookup_key]})")
189
+ else: current_scene_character_details.append(char_name_clean)
190
+ characters_narrative = f" Characters to feature: {', '.join(current_scene_character_details) if current_scene_character_details else 'None specifically detailed'}."
191
 
192
  full_prompt_for_gemini = f"""
193
  You are an AI Art Director specializing in refining DALL-E 3 prompts for cinematic visuals.
 
202
  - Director's Suggested Camera: "{scene_data.get('PROACTIVE_camera_work_감독', '')}"
203
  - Current Global Style Additions: "{global_style_additions}"
204
 
205
+ The PREVIOUS DALL-E 3 prompt (that generated the image the user wants to change) was:
206
  "{original_dalle_prompt}"
207
 
208
+ User Feedback on the visual generated by the previous prompt:
209
  "{user_feedback}"
210
 
211
  Your Task: Generate a NEW, revised DALL-E 3 prompt.
212
  This new prompt must incorporate the user's feedback to achieve the desired visual changes.
213
  It should remain ultra-detailed, photorealistic, and highly cinematic.
214
  The prompt should guide DALL-E 3 to create a stunning image suitable for a film's concept art.
215
+ Maintain core scene elements (setting, characters, plot beat) unless feedback explicitly asks to change them.
216
  Translate feedback into concrete visual descriptions (lighting, color, composition, character appearance/pose, atmosphere).
217
+ Reinforce character descriptions from the context if they are relevant to the feedback.
218
+ The prompt should be a single block of text.
219
 
220
+ Output ONLY the new, revised DALL-E 3 prompt string. Do not add any other text before or after the prompt.
221
  """
222
  return " ".join(full_prompt_for_gemini.split())