Update core/prompt_engineering.py
Browse files- core/prompt_engineering.py +68 -54
core/prompt_engineering.py
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
# core/prompt_engineering.py
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful", num_scenes=3):
|
4 |
return f"""
|
@@ -8,9 +14,9 @@ def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful",
|
|
8 |
|
9 |
Generate a {num_scenes}-scene story breakdown. For each scene, provide:
|
10 |
1. scene_number (int)
|
11 |
-
2. setting_description (str): Vivid description of the location and atmosphere.
|
12 |
3. characters_involved (list of str): Names of characters in the scene.
|
13 |
-
4. key_action (str): The main event or action happening.
|
14 |
5. dialogue_snippet (str): A brief, impactful line of dialogue if applicable.
|
15 |
6. visual_style_suggestion (str): e.g., "Dark and gritty, high contrast, Blade Runner-esque neon"
|
16 |
7. camera_angle_suggestion (str): e.g., "Low-angle shot to emphasize power"
|
@@ -20,13 +26,13 @@ def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful",
|
|
20 |
Example for one scene:
|
21 |
{{
|
22 |
"scene_number": 1,
|
23 |
-
"setting_description": "A dimly lit, cluttered spaceship cockpit. Warning lights flash intermittently.",
|
24 |
"characters_involved": ["Captain Eva Rostova"],
|
25 |
-
"key_action": "Eva
|
26 |
-
"dialogue_snippet": "Eva: '
|
27 |
-
"visual_style_suggestion": "Claustrophobic, practical lighting, lens flares.",
|
28 |
-
"camera_angle_suggestion": "Close-up on Eva's face,
|
29 |
-
"emotional_beat": "
|
30 |
}}
|
31 |
|
32 |
Provide the full JSON structure for {num_scenes} scenes in a list:
|
@@ -37,83 +43,91 @@ def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful",
|
|
37 |
]
|
38 |
"""
|
39 |
|
40 |
-
def create_image_prompt_from_scene_data(scene_data,
|
41 |
"""
|
42 |
-
Generates an image prompt from structured scene data.
|
43 |
scene_data: dictionary for a single scene.
|
44 |
-
|
45 |
-
style_reference_desc: textual description of a desired style
|
46 |
"""
|
47 |
-
|
|
|
48 |
visual_style = scene_data.get('visual_style_suggestion', 'cinematic')
|
49 |
camera_angle = scene_data.get('camera_angle_suggestion', '')
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
style_mod = ""
|
58 |
if style_reference_desc:
|
59 |
style_mod = f" Artistic style inspired by: {style_reference_desc}."
|
60 |
|
|
|
|
|
61 |
full_prompt = f"""
|
62 |
-
Generate a highly detailed, photorealistic
|
63 |
-
|
64 |
-
Visual Style: {visual_style}{style_mod}
|
65 |
Camera Perspective: {camera_angle}.
|
66 |
-
|
67 |
-
|
68 |
-
Output
|
69 |
"""
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_story_context=None):
|
74 |
-
|
75 |
-
Creates a prompt for Gemini to regenerate a specific scene's script details.
|
76 |
-
original_scene_data: The JSON object of the scene to be modified.
|
77 |
-
user_feedback: Text from the user describing desired changes.
|
78 |
-
full_story_context: (Optional) JSON of all scenes for better consistency.
|
79 |
-
"""
|
80 |
context_str = f"Original scene details:\n{json.dumps(original_scene_data, indent=2)}\n\n"
|
81 |
if full_story_context:
|
82 |
context_str += f"Full story context (this scene is number {original_scene_data.get('scene_number')}):\n{json.dumps(full_story_context, indent=2)}\n\n"
|
83 |
-
|
84 |
return f"""
|
85 |
You are an expert script doctor.
|
86 |
{context_str}
|
87 |
The user wants to modify this scene based on the following feedback: "{user_feedback}"
|
88 |
-
|
89 |
Please regenerate ONLY the JSON object for this single scene, incorporating the feedback.
|
90 |
-
Maintain the same JSON structure as the original scene
|
91 |
-
|
92 |
-
Ensure the scene_number remains the same.
|
93 |
-
Focus on making the changes impactful while keeping the scene coherent.
|
94 |
-
If the feedback is about visual style or camera, update those fields accordingly.
|
95 |
-
If the feedback is about action or dialogue, update those.
|
96 |
"""
|
97 |
|
98 |
def create_visual_regeneration_prompt(original_image_prompt, user_feedback_on_visuals, scene_data):
|
99 |
-
|
100 |
-
|
101 |
-
"""
|
102 |
return f"""
|
103 |
-
The previous image prompt for a scene was: "{original_image_prompt}"
|
104 |
The scene details are:
|
105 |
Setting: {scene_data.get('setting_description')}
|
106 |
Action: {scene_data.get('key_action')}
|
|
|
107 |
Mood/Emotion: {scene_data.get('emotional_beat')}
|
108 |
-
Visual Style: {scene_data.get('visual_style_suggestion')}
|
109 |
-
Camera: {scene_data.get('camera_angle_suggestion')}
|
110 |
|
111 |
The user provided this feedback on the visuals: "{user_feedback_on_visuals}"
|
112 |
|
113 |
-
Generate a new, refined image generation prompt
|
114 |
-
The new prompt should aim to correct or enhance the visuals as per the user's request.
|
|
|
|
|
115 |
Output only the new prompt string.
|
116 |
-
"""
|
117 |
-
|
118 |
-
# (Keep other prompt functions if needed)
|
119 |
-
import json # Add this at the top of prompt_engineering.py if not already there
|
|
|
1 |
# core/prompt_engineering.py
|
2 |
+
import json
|
3 |
+
|
4 |
+
# create_story_breakdown_prompt can remain mostly the same, but ensure 'key_action' is descriptive.
|
5 |
+
# If key_action is very short, text overlays on video might not be useful.
|
6 |
+
# Consider making 'key_action' slightly more verbose or adding a 'video_overlay_text' field.
|
7 |
+
# For now, we'll use key_action.
|
8 |
|
9 |
def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful", num_scenes=3):
|
10 |
return f"""
|
|
|
14 |
|
15 |
Generate a {num_scenes}-scene story breakdown. For each scene, provide:
|
16 |
1. scene_number (int)
|
17 |
+
2. setting_description (str): Vivid description of the location and atmosphere (approx 20-40 words).
|
18 |
3. characters_involved (list of str): Names of characters in the scene.
|
19 |
+
4. key_action (str): The main event or action happening in one concise sentence (approx 10-20 words). This will be used for video overlays.
|
20 |
5. dialogue_snippet (str): A brief, impactful line of dialogue if applicable.
|
21 |
6. visual_style_suggestion (str): e.g., "Dark and gritty, high contrast, Blade Runner-esque neon"
|
22 |
7. camera_angle_suggestion (str): e.g., "Low-angle shot to emphasize power"
|
|
|
26 |
Example for one scene:
|
27 |
{{
|
28 |
"scene_number": 1,
|
29 |
+
"setting_description": "A dimly lit, cluttered spaceship cockpit. Warning lights flash intermittently. Steam vents from a broken pipe.",
|
30 |
"characters_involved": ["Captain Eva Rostova"],
|
31 |
+
"key_action": "Eva frantically works at a console, trying to divert a catastrophic system failure.",
|
32 |
+
"dialogue_snippet": "Eva: 'Come on, come on... don't do this to me now!'",
|
33 |
+
"visual_style_suggestion": "Claustrophobic, practical lighting, lens flares, metallic sheens.",
|
34 |
+
"camera_angle_suggestion": "Close-up on Eva's determined face, sweat beading on her forehead.",
|
35 |
+
"emotional_beat": "Desperation and intense focus."
|
36 |
}}
|
37 |
|
38 |
Provide the full JSON structure for {num_scenes} scenes in a list:
|
|
|
43 |
]
|
44 |
"""
|
45 |
|
46 |
+
def create_image_prompt_from_scene_data(scene_data, character_definitions=None, style_reference_desc=None):
|
47 |
"""
|
48 |
+
Generates an image prompt from structured scene data, injecting character details.
|
49 |
scene_data: dictionary for a single scene.
|
50 |
+
character_definitions: dict {char_name_lower: description} for consistency.
|
51 |
+
style_reference_desc: textual description of a desired style.
|
52 |
"""
|
53 |
+
setting_desc = scene_data.get('setting_description', '')
|
54 |
+
key_action_desc = scene_data.get('key_action', '')
|
55 |
visual_style = scene_data.get('visual_style_suggestion', 'cinematic')
|
56 |
camera_angle = scene_data.get('camera_angle_suggestion', '')
|
57 |
+
emotional_beat = scene_data.get('emotional_beat', '')
|
58 |
+
|
59 |
+
characters_str_parts = []
|
60 |
+
if character_definitions and scene_data.get('characters_involved'):
|
61 |
+
for char_name in scene_data.get('characters_involved', []):
|
62 |
+
# Match character name case-insensitively, but use original name from scene_data
|
63 |
+
defined_desc = character_definitions.get(char_name.lower().strip())
|
64 |
+
if defined_desc:
|
65 |
+
characters_str_parts.append(f"{char_name.strip()} ({defined_desc})")
|
66 |
+
else:
|
67 |
+
characters_str_parts.append(char_name.strip()) # Character mentioned but not defined
|
68 |
+
elif scene_data.get('characters_involved'): # Characters mentioned but no definitions provided
|
69 |
+
characters_str_parts = [name.strip() for name in scene_data.get('characters_involved', [])]
|
70 |
+
|
71 |
+
characters_involved_str = ""
|
72 |
+
if characters_str_parts:
|
73 |
+
if len(characters_str_parts) == 1:
|
74 |
+
characters_involved_str = f" The scene features {characters_str_parts[0]}."
|
75 |
+
else:
|
76 |
+
characters_involved_str = f" The scene features {', '.join(characters_str_parts[:-1])} and {characters_str_parts[-1]}."
|
77 |
+
|
78 |
+
base_desc = f"Depict: Scene {scene_data.get('scene_number', '')}. {key_action_desc} {characters_involved_str} Setting: {setting_desc}."
|
79 |
+
|
80 |
style_mod = ""
|
81 |
if style_reference_desc:
|
82 |
style_mod = f" Artistic style inspired by: {style_reference_desc}."
|
83 |
|
84 |
+
# Constructing a more robust prompt for DALL-E 3
|
85 |
+
# DALL-E 3 benefits from descriptive, story-like prompts.
|
86 |
full_prompt = f"""
|
87 |
+
Generate a highly detailed, photorealistic and cinematic image.
|
88 |
+
Image Description: {base_desc}
|
89 |
+
Visual Style: {visual_style}. {style_mod}
|
90 |
Camera Perspective: {camera_angle}.
|
91 |
+
Emotional Tone: {emotional_beat}.
|
92 |
+
Key elements to emphasize: Cinematic composition, dramatic lighting, depth of field, rich textures, and atmospheric effects.
|
93 |
+
Output a visually stunning image suitable for a film storyboard.
|
94 |
"""
|
95 |
+
# Removed "Output only the prompt string" as this function *is* the prompt string builder.
|
96 |
+
# DALL-E 3 does not need "Suitable for DALL-E 3 or Midjourney".
|
97 |
+
return " ".join(full_prompt.split()) # Cleans up extra whitespace
|
98 |
|
99 |
def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_story_context=None):
|
100 |
+
# ... (remains the same as your last working version) ...
|
|
|
|
|
|
|
|
|
|
|
101 |
context_str = f"Original scene details:\n{json.dumps(original_scene_data, indent=2)}\n\n"
|
102 |
if full_story_context:
|
103 |
context_str += f"Full story context (this scene is number {original_scene_data.get('scene_number')}):\n{json.dumps(full_story_context, indent=2)}\n\n"
|
|
|
104 |
return f"""
|
105 |
You are an expert script doctor.
|
106 |
{context_str}
|
107 |
The user wants to modify this scene based on the following feedback: "{user_feedback}"
|
|
|
108 |
Please regenerate ONLY the JSON object for this single scene, incorporating the feedback.
|
109 |
+
Maintain the same JSON structure as the original scene (scene_number, setting_description, characters_involved, key_action, dialogue_snippet, visual_style_suggestion, camera_angle_suggestion, emotional_beat).
|
110 |
+
Ensure the scene_number remains the same. The 'key_action' should be a concise descriptive sentence (10-20 words).
|
|
|
|
|
|
|
|
|
111 |
"""
|
112 |
|
113 |
def create_visual_regeneration_prompt(original_image_prompt, user_feedback_on_visuals, scene_data):
|
114 |
+
# ... (remains the same, this prompt is for Gemini to *rewrite* an image prompt) ...
|
115 |
+
# This prompt should also be updated to be DALL-E 3 friendly if it's rewriting.
|
|
|
116 |
return f"""
|
117 |
+
The previous detailed image generation prompt for a scene was: "{original_image_prompt}"
|
118 |
The scene details are:
|
119 |
Setting: {scene_data.get('setting_description')}
|
120 |
Action: {scene_data.get('key_action')}
|
121 |
+
Characters: {', '.join(scene_data.get('characters_involved',[]))}
|
122 |
Mood/Emotion: {scene_data.get('emotional_beat')}
|
123 |
+
Current Visual Style: {scene_data.get('visual_style_suggestion')}
|
124 |
+
Current Camera: {scene_data.get('camera_angle_suggestion')}
|
125 |
|
126 |
The user provided this feedback on the visuals: "{user_feedback_on_visuals}"
|
127 |
|
128 |
+
Generate a new, refined, highly detailed, photorealistic and cinematic image generation prompt based on this feedback.
|
129 |
+
The new prompt should aim to correct or enhance the visuals as per the user's request, while maintaining the core scene elements.
|
130 |
+
Ensure the prompt is descriptive and suitable for generating a stunning image for a film storyboard with DALL-E 3.
|
131 |
+
Focus on cinematic composition, dramatic lighting, depth of field, rich textures, and atmospheric effects.
|
132 |
Output only the new prompt string.
|
133 |
+
"""
|
|
|
|
|
|