Update core/prompt_engineering.py
Browse files- core/prompt_engineering.py +93 -16
core/prompt_engineering.py
CHANGED
@@ -1,42 +1,119 @@
|
|
1 |
# core/prompt_engineering.py
|
2 |
-
|
|
|
3 |
return f"""
|
4 |
You are an expert screenwriter and visual storyteller.
|
5 |
Based on the user's idea: "{user_idea}"
|
6 |
And considering the genre: "{genre}" and mood: "{mood}"
|
7 |
|
8 |
-
Generate a
|
9 |
1. scene_number (int)
|
10 |
2. setting_description (str): Vivid description of the location and atmosphere.
|
11 |
3. characters_involved (list of str): Names of characters in the scene.
|
12 |
4. key_action (str): The main event or action happening.
|
13 |
-
5.
|
14 |
-
6.
|
|
|
|
|
15 |
|
16 |
-
Output ONLY the JSON object
|
|
|
17 |
{{
|
18 |
"scene_number": 1,
|
19 |
"setting_description": "A dimly lit, cluttered spaceship cockpit. Warning lights flash intermittently.",
|
20 |
"characters_involved": ["Captain Eva Rostova"],
|
21 |
"key_action": "Eva notices an unusual energy signature on the main console.",
|
|
|
22 |
"visual_style_suggestion": "Claustrophobic, practical lighting, lens flares.",
|
23 |
-
"camera_angle_suggestion": "Close-up on Eva's face, then a point-of-view shot of the console."
|
|
|
24 |
}}
|
25 |
|
26 |
-
Provide the full JSON structure for
|
27 |
[
|
28 |
{{scene1_details...}},
|
29 |
{{scene2_details...}},
|
30 |
-
|
31 |
]
|
32 |
"""
|
33 |
|
34 |
-
def
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
Output only the prompt string.
|
42 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"""
|
5 |
You are an expert screenwriter and visual storyteller.
|
6 |
Based on the user's idea: "{user_idea}"
|
7 |
And considering the genre: "{genre}" and mood: "{mood}"
|
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"
|
17 |
+
8. emotional_beat (str): The core emotion or turning point in the scene.
|
18 |
|
19 |
+
Output ONLY the JSON object for the list of scenes.
|
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 notices an unusual energy signature on the main console.",
|
26 |
+
"dialogue_snippet": "Eva: 'What in the void is that?'",
|
27 |
"visual_style_suggestion": "Claustrophobic, practical lighting, lens flares.",
|
28 |
+
"camera_angle_suggestion": "Close-up on Eva's face, then a point-of-view shot of the console.",
|
29 |
+
"emotional_beat": "Curiosity mixed with apprehension."
|
30 |
}}
|
31 |
|
32 |
+
Provide the full JSON structure for {num_scenes} scenes in a list:
|
33 |
[
|
34 |
{{scene1_details...}},
|
35 |
{{scene2_details...}},
|
36 |
+
...
|
37 |
]
|
38 |
"""
|
39 |
|
40 |
+
def create_image_prompt_from_scene_data(scene_data, character_details=None, style_reference_desc=None):
|
41 |
+
"""
|
42 |
+
Generates an image prompt from structured scene data.
|
43 |
+
scene_data: dictionary for a single scene.
|
44 |
+
character_details: dict {char_name: description} for consistency (future use).
|
45 |
+
style_reference_desc: textual description of a desired style (future use).
|
46 |
+
"""
|
47 |
+
base_desc = f"Scene {scene_data.get('scene_number', '')}: {scene_data.get('key_action', '')}. Setting: {scene_data.get('setting_description', '')}."
|
48 |
+
visual_style = scene_data.get('visual_style_suggestion', 'cinematic')
|
49 |
+
camera_angle = scene_data.get('camera_angle_suggestion', '')
|
50 |
+
|
51 |
+
char_info = ""
|
52 |
+
if character_details and scene_data.get('characters_involved'):
|
53 |
+
for char_name in scene_data.get('characters_involved'):
|
54 |
+
if char_name in character_details:
|
55 |
+
char_info += f" {char_name} ({character_details[char_name]})."
|
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 image generation prompt.
|
63 |
+
The image should depict: {base_desc}{char_info}
|
64 |
+
Visual Style: {visual_style}{style_mod}.
|
65 |
+
Camera Perspective: {camera_angle}.
|
66 |
+
Emphasize mood: {scene_data.get('emotional_beat', '')}.
|
67 |
+
Focus on cinematic composition, lighting. Suitable for DALL-E 3 or Midjourney.
|
68 |
Output only the prompt string.
|
69 |
+
"""
|
70 |
+
return full_prompt.strip()
|
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 |
+
(scene_number, setting_description, characters_involved, key_action, dialogue_snippet, visual_style_suggestion, camera_angle_suggestion, emotional_beat).
|
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 |
+
Creates a prompt for Gemini to regenerate an image prompt based on feedback.
|
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 that incorporates this feedback.
|
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
|