commit
This commit is contained in:
57
backend/app/services/script_parser.py
Normal file
57
backend/app/services/script_parser.py
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
import json
|
||||
from app.core.ai import ai_client
|
||||
from app.schemas.script import ScriptAnalysisResponse
|
||||
|
||||
class ScriptParserService:
|
||||
async def parse_script(self, text_content: str) -> ScriptAnalysisResponse:
|
||||
prompt = f"""
|
||||
You are an expert Assistant Director and Script Supervisor.
|
||||
Analyze the following screenplay text and break it down into Scenes and Shots.
|
||||
|
||||
For each Scene, identify:
|
||||
- Scene Number (if present, or incrementing)
|
||||
- Heading (INT./EXT. LOCATION - DAY/NIGHT)
|
||||
- Brief Description of what happens
|
||||
|
||||
For each Scene, break the action down into a list of Shots (Camera setups).
|
||||
For each Shot, provide:
|
||||
- Shot Number (e.g. 1, 1A, etc)
|
||||
- Description of the action in the shot
|
||||
- Visual Notes (Camera angles, movement if implied)
|
||||
- Dialogue (if any covers this shot)
|
||||
|
||||
Output MUST be a valid JSON object matching this structure:
|
||||
{{
|
||||
"scenes": [
|
||||
{{
|
||||
"scene_number": "1",
|
||||
"heading": "INT. OFFICE - DAY",
|
||||
"description": "John sits at his desk.",
|
||||
"shots": [
|
||||
{{
|
||||
"shot_number": "1A",
|
||||
"description": "Wide shot of John at desk.",
|
||||
"visual_notes": "Static",
|
||||
"dialogue": null
|
||||
}}
|
||||
]
|
||||
}}
|
||||
]
|
||||
}}
|
||||
|
||||
SCRIPT TEXT:
|
||||
{text_content}
|
||||
"""
|
||||
|
||||
json_str = await ai_client.generate_json(prompt)
|
||||
|
||||
# Parse JSON and validate with Pydantic
|
||||
try:
|
||||
data = json.loads(json_str)
|
||||
return ScriptAnalysisResponse(**data)
|
||||
except json.JSONDecodeError:
|
||||
# Fallback or retry logic could go here
|
||||
raise ValueError("Failed to parse LLM response as JSON")
|
||||
|
||||
parser_service = ScriptParserService()
|
||||
Reference in New Issue
Block a user