Spaces:
Running
Running
| 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] |