64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
|
|
import json
|
|
from app.core.ai import ai_client
|
|
from app.models.shot import Shot
|
|
from app.models.scene import Scene
|
|
|
|
class FlowGeneratorService:
|
|
async def generate_flow_json(self, shot: Shot, scene: Scene) -> dict:
|
|
prompt = f"""
|
|
You are a Virtual Cinematographer creating production instructions for Google Veo (Generative Video AI).
|
|
|
|
Generate a JSON configuration payload for the following shot.
|
|
|
|
CONTEXT:
|
|
Scene Heading: {scene.slugline}
|
|
Scene Description: {scene.raw_content}
|
|
|
|
SHOT DETAILS:
|
|
Description: {shot.description}
|
|
Additional Notes: {shot.llm_context_cache}
|
|
|
|
The JSON output should strictly follow this schema:
|
|
{{
|
|
"prompt": "Detailed visual description of the video to be generated...",
|
|
"negative_prompt": "things to avoid...",
|
|
"camera_movement": "string (e.g. pan left, zoom in, static)",
|
|
"aspect_ratio": "16:9",
|
|
"duration_seconds": 5
|
|
}}
|
|
|
|
Enhance the 'prompt' field to be highly descriptive, visual, and suitable for a text-to-video model.
|
|
Include lighting, style, and composition details based on the context.
|
|
"""
|
|
|
|
json_str = await ai_client.generate_json(prompt)
|
|
|
|
try:
|
|
return json.loads(json_str)
|
|
except json.JSONDecodeError:
|
|
raise ValueError("Failed to generate valid JSON from AI response")
|
|
|
|
async def refine_flow_json(self, current_json: dict, user_feedback: str) -> dict:
|
|
prompt = f"""
|
|
You are an AI Video Assistant.
|
|
Update the following Google Veo JSON configuration based on the user's feedback.
|
|
|
|
CURRENT JSON:
|
|
{json.dumps(current_json, indent=2)}
|
|
|
|
USER FEEDBACK:
|
|
"{user_feedback}"
|
|
|
|
Return ONLY the updated JSON object. Do not wrap in markdown code blocks.
|
|
"""
|
|
|
|
json_str = await ai_client.generate_json(prompt)
|
|
|
|
try:
|
|
return json.loads(json_str)
|
|
except json.JSONDecodeError:
|
|
raise ValueError("Failed to refine JSON")
|
|
|
|
flow_generator = FlowGeneratorService()
|