replacebg / scene_planner.py
Munaf1987's picture
Upload 7 files
139ec19 verified
raw
history blame
740 Bytes
from transformers import pipeline
scene_splitter = pipeline("text2text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
def plan_scenes(script):
prompt = (
"Split the following story into 10-15 scenes. For each scene, return a JSON with 'prompt' "
"(scene image description) and 'dialogue' (narration to speak). Make the prompt cartoon-friendly.\nStory:\n" + script
)
response = scene_splitter(prompt, max_new_tokens=1024, do_sample=False)[0]['generated_text']
try:
import json
scenes = json.loads(response)
except:
scenes = [
{"prompt": line.strip(), "dialogue": line.strip()} for line in script.split(".") if line.strip()
]
return scenes[:15]