# core/prompt_engineering.py import json # create_story_breakdown_prompt can remain mostly the same, but ensure 'key_action' is descriptive. # If key_action is very short, text overlays on video might not be useful. # Consider making 'key_action' slightly more verbose or adding a 'video_overlay_text' field. # For now, we'll use key_action. def create_story_breakdown_prompt(user_idea, genre="sci-fi", mood="suspenseful", num_scenes=3): return f""" You are an expert screenwriter and visual storyteller. Based on the user's idea: "{user_idea}" And considering the genre: "{genre}" and mood: "{mood}" Generate a {num_scenes}-scene story breakdown. For each scene, provide: 1. scene_number (int) 2. setting_description (str): Vivid description of the location and atmosphere (approx 20-40 words). 3. characters_involved (list of str): Names of characters in the scene. 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. 5. dialogue_snippet (str): A brief, impactful line of dialogue if applicable. 6. visual_style_suggestion (str): e.g., "Dark and gritty, high contrast, Blade Runner-esque neon" 7. camera_angle_suggestion (str): e.g., "Low-angle shot to emphasize power" 8. emotional_beat (str): The core emotion or turning point in the scene. Output ONLY the JSON object for the list of scenes. Example for one scene: {{ "scene_number": 1, "setting_description": "A dimly lit, cluttered spaceship cockpit. Warning lights flash intermittently. Steam vents from a broken pipe.", "characters_involved": ["Captain Eva Rostova"], "key_action": "Eva frantically works at a console, trying to divert a catastrophic system failure.", "dialogue_snippet": "Eva: 'Come on, come on... don't do this to me now!'", "visual_style_suggestion": "Claustrophobic, practical lighting, lens flares, metallic sheens.", "camera_angle_suggestion": "Close-up on Eva's determined face, sweat beading on her forehead.", "emotional_beat": "Desperation and intense focus." }} Provide the full JSON structure for {num_scenes} scenes in a list: [ {{scene1_details...}}, {{scene2_details...}}, ... ] """ def create_image_prompt_from_scene_data(scene_data, character_definitions=None, style_reference_desc=None): """ Generates an image prompt from structured scene data, injecting character details. scene_data: dictionary for a single scene. character_definitions: dict {char_name_lower: description} for consistency. style_reference_desc: textual description of a desired style. """ setting_desc = scene_data.get('setting_description', '') key_action_desc = scene_data.get('key_action', '') visual_style = scene_data.get('visual_style_suggestion', 'cinematic') camera_angle = scene_data.get('camera_angle_suggestion', '') emotional_beat = scene_data.get('emotional_beat', '') characters_str_parts = [] if character_definitions and scene_data.get('characters_involved'): for char_name in scene_data.get('characters_involved', []): # Match character name case-insensitively, but use original name from scene_data defined_desc = character_definitions.get(char_name.lower().strip()) if defined_desc: characters_str_parts.append(f"{char_name.strip()} ({defined_desc})") else: characters_str_parts.append(char_name.strip()) # Character mentioned but not defined elif scene_data.get('characters_involved'): # Characters mentioned but no definitions provided characters_str_parts = [name.strip() for name in scene_data.get('characters_involved', [])] characters_involved_str = "" if characters_str_parts: if len(characters_str_parts) == 1: characters_involved_str = f" The scene features {characters_str_parts[0]}." else: characters_involved_str = f" The scene features {', '.join(characters_str_parts[:-1])} and {characters_str_parts[-1]}." base_desc = f"Depict: Scene {scene_data.get('scene_number', '')}. {key_action_desc} {characters_involved_str} Setting: {setting_desc}." style_mod = "" if style_reference_desc: style_mod = f" Artistic style inspired by: {style_reference_desc}." # Constructing a more robust prompt for DALL-E 3 # DALL-E 3 benefits from descriptive, story-like prompts. full_prompt = f""" Generate a highly detailed, photorealistic and cinematic image. Image Description: {base_desc} Visual Style: {visual_style}. {style_mod} Camera Perspective: {camera_angle}. Emotional Tone: {emotional_beat}. Key elements to emphasize: Cinematic composition, dramatic lighting, depth of field, rich textures, and atmospheric effects. Output a visually stunning image suitable for a film storyboard. """ # Removed "Output only the prompt string" as this function *is* the prompt string builder. # DALL-E 3 does not need "Suitable for DALL-E 3 or Midjourney". return " ".join(full_prompt.split()) # Cleans up extra whitespace def create_scene_regeneration_prompt(original_scene_data, user_feedback, full_story_context=None): # ... (remains the same as your last working version) ... context_str = f"Original scene details:\n{json.dumps(original_scene_data, indent=2)}\n\n" if full_story_context: 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" return f""" You are an expert script doctor. {context_str} The user wants to modify this scene based on the following feedback: "{user_feedback}" Please regenerate ONLY the JSON object for this single scene, incorporating the feedback. 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). Ensure the scene_number remains the same. The 'key_action' should be a concise descriptive sentence (10-20 words). """ def create_visual_regeneration_prompt(original_image_prompt, user_feedback_on_visuals, scene_data): # ... (remains the same, this prompt is for Gemini to *rewrite* an image prompt) ... # This prompt should also be updated to be DALL-E 3 friendly if it's rewriting. return f""" The previous detailed image generation prompt for a scene was: "{original_image_prompt}" The scene details are: Setting: {scene_data.get('setting_description')} Action: {scene_data.get('key_action')} Characters: {', '.join(scene_data.get('characters_involved',[]))} Mood/Emotion: {scene_data.get('emotional_beat')} Current Visual Style: {scene_data.get('visual_style_suggestion')} Current Camera: {scene_data.get('camera_angle_suggestion')} The user provided this feedback on the visuals: "{user_feedback_on_visuals}" Generate a new, refined, highly detailed, photorealistic and cinematic image generation prompt based on this feedback. The new prompt should aim to correct or enhance the visuals as per the user's request, while maintaining the core scene elements. Ensure the prompt is descriptive and suitable for generating a stunning image for a film storyboard with DALL-E 3. Focus on cinematic composition, dramatic lighting, depth of field, rich textures, and atmospheric effects. Output only the new prompt string. """