File size: 699 Bytes
4bbe186
139ec19
 
4bbe186
139ec19
 
 
4bbe186
 
139ec19
 
 
 
 
 
 
4bbe186
139ec19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# In scene_planner.py
from transformers import pipeline

scene_splitter = pipeline("text-generation", model="microsoft/phi-2")

def plan_scenes(script):
    prompt = (
        "Split this story into 10-15 cartoon scenes. Each should have a JSON with 'prompt' (image description) "
        "and 'dialogue' (line of narration). Make it suitable for animation.\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]