Spaces:
Running
Running
Update scene_planner.py
Browse files- scene_planner.py +5 -7
scene_planner.py
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
scene_splitter = pipeline("
|
| 4 |
|
| 5 |
def plan_scenes(script):
|
| 6 |
prompt = (
|
| 7 |
-
"Split
|
| 8 |
-
"
|
| 9 |
)
|
| 10 |
-
|
| 11 |
response = scene_splitter(prompt, max_new_tokens=1024, do_sample=False)[0]['generated_text']
|
| 12 |
|
| 13 |
try:
|
| 14 |
import json
|
| 15 |
scenes = json.loads(response)
|
| 16 |
except:
|
| 17 |
-
scenes = [
|
| 18 |
-
{"prompt": line.strip(), "dialogue": line.strip()} for line in script.split(".") if line.strip()
|
| 19 |
-
]
|
| 20 |
return scenes[:15]
|
|
|
|
| 1 |
+
# In scene_planner.py
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
scene_splitter = pipeline("text-generation", model="microsoft/phi-2")
|
| 5 |
|
| 6 |
def plan_scenes(script):
|
| 7 |
prompt = (
|
| 8 |
+
"Split this story into 10-15 cartoon scenes. Each should have a JSON with 'prompt' (image description) "
|
| 9 |
+
"and 'dialogue' (line of narration). Make it suitable for animation.\nStory:\n" + script
|
| 10 |
)
|
|
|
|
| 11 |
response = scene_splitter(prompt, max_new_tokens=1024, do_sample=False)[0]['generated_text']
|
| 12 |
|
| 13 |
try:
|
| 14 |
import json
|
| 15 |
scenes = json.loads(response)
|
| 16 |
except:
|
| 17 |
+
scenes = [{"prompt": line.strip(), "dialogue": line.strip()} for line in script.split('.') if line.strip()]
|
|
|
|
|
|
|
| 18 |
return scenes[:15]
|