Spaces:
Sleeping
Sleeping
full text experience including ending the story
Browse files- README.md +1 -1
- data/stories.db +0 -0
- helpers/__init__.py +1 -4
- homeros.py +16 -3
- main.py +4 -4
README.md
CHANGED
@@ -71,8 +71,8 @@ It puts the user in charge of a how the story is going to develop.
|
|
71 |
- [x] Story object setup, schema, logic
|
72 |
- [x] Set up flow management
|
73 |
- [x] Add SQlite DB and save stories
|
|
|
74 |
- [ ] Do the evaluator (if it's time to end)
|
75 |
-
- [ ] GPT-4 story generation in a gradio interface
|
76 |
- [ ] Inerchange text output for play.ht voice generation
|
77 |
- [ ] Interchange text input for whisper
|
78 |
- [ ] Dockerfile and deploy (including magic word for access control)
|
|
|
71 |
- [x] Story object setup, schema, logic
|
72 |
- [x] Set up flow management
|
73 |
- [x] Add SQlite DB and save stories
|
74 |
+
- [x] GPT-4 story generation in a gradio interface
|
75 |
- [ ] Do the evaluator (if it's time to end)
|
|
|
76 |
- [ ] Inerchange text output for play.ht voice generation
|
77 |
- [ ] Interchange text input for whisper
|
78 |
- [ ] Dockerfile and deploy (including magic word for access control)
|
data/stories.db
CHANGED
Binary files a/data/stories.db and b/data/stories.db differ
|
|
helpers/__init__.py
CHANGED
@@ -10,9 +10,6 @@ def gen_unique_id():
|
|
10 |
def check_magic_word(w):
|
11 |
return magic_w in w
|
12 |
|
13 |
-
def its_time_to_end(story):
|
14 |
-
return False
|
15 |
-
|
16 |
def get_fixed_msg(msg_type):
|
17 |
|
18 |
fixed_sayings = {
|
@@ -24,7 +21,7 @@ def get_fixed_msg(msg_type):
|
|
24 |
"ask_ending": ["What kind of ending would you like? A happy one? A tragic one? Something else?"],
|
25 |
"ask_style": ["What kind of storytelling style do you wnat? Funny? Poetic?"],
|
26 |
"its_the_end": ["And this is the end of our story. Thank you for listening."],
|
27 |
-
"no_more_story": ["I'm sorry, this story has ended."]
|
28 |
}
|
29 |
|
30 |
if msg_type in fixed_sayings:
|
|
|
10 |
def check_magic_word(w):
|
11 |
return magic_w in w
|
12 |
|
|
|
|
|
|
|
13 |
def get_fixed_msg(msg_type):
|
14 |
|
15 |
fixed_sayings = {
|
|
|
21 |
"ask_ending": ["What kind of ending would you like? A happy one? A tragic one? Something else?"],
|
22 |
"ask_style": ["What kind of storytelling style do you wnat? Funny? Poetic?"],
|
23 |
"its_the_end": ["And this is the end of our story. Thank you for listening."],
|
24 |
+
"no_more_story": ["I'm sorry, this story has ended. Reload the page to do another story."]
|
25 |
}
|
26 |
|
27 |
if msg_type in fixed_sayings:
|
homeros.py
CHANGED
@@ -7,6 +7,7 @@ from helpers import gen_unique_id
|
|
7 |
import prompts
|
8 |
from adaptors.llm import answer
|
9 |
|
|
|
10 |
|
11 |
'''
|
12 |
initiates a new story and saves in DB
|
@@ -69,18 +70,18 @@ def continue_story(user_input, story_data):
|
|
69 |
'''
|
70 |
generates the last part of the story and changes status to "finished"
|
71 |
'''
|
72 |
-
def finish_story(story_data):
|
73 |
story = get_story(story_data["uuid"])
|
74 |
chunks = json.loads(story.chunks)
|
75 |
messages = json.loads(story.messages)
|
76 |
|
77 |
-
user_input = "
|
78 |
|
79 |
messages.append({
|
80 |
"role":"user",
|
81 |
"content": user_input
|
82 |
})
|
83 |
-
next_chunk_text = create_next_chunk_text(story)
|
84 |
next_chunk_audio = create_next_chunk_audio(next_chunk_text)
|
85 |
chunks.append({
|
86 |
"text" : next_chunk_text,
|
@@ -127,6 +128,18 @@ def create_next_chunk_text(user_input, story):
|
|
127 |
return next_chunk
|
128 |
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
'''
|
131 |
turns next story chunk into audio and returns a URL
|
132 |
'''
|
|
|
7 |
import prompts
|
8 |
from adaptors.llm import answer
|
9 |
|
10 |
+
MAX_STORY_LEN = 2 #after how many chunks we force the story to end
|
11 |
|
12 |
'''
|
13 |
initiates a new story and saves in DB
|
|
|
70 |
'''
|
71 |
generates the last part of the story and changes status to "finished"
|
72 |
'''
|
73 |
+
def finish_story(user_input, story_data):
|
74 |
story = get_story(story_data["uuid"])
|
75 |
chunks = json.loads(story.chunks)
|
76 |
messages = json.loads(story.messages)
|
77 |
|
78 |
+
user_input = user_input + "\n\nPlease finish the story now."
|
79 |
|
80 |
messages.append({
|
81 |
"role":"user",
|
82 |
"content": user_input
|
83 |
})
|
84 |
+
next_chunk_text = create_next_chunk_text(user_input, story)
|
85 |
next_chunk_audio = create_next_chunk_audio(next_chunk_text)
|
86 |
chunks.append({
|
87 |
"text" : next_chunk_text,
|
|
|
128 |
return next_chunk
|
129 |
|
130 |
|
131 |
+
'''
|
132 |
+
evaluates the story up until now and returns a dict with the result of the evaluation
|
133 |
+
'''
|
134 |
+
def evaluate_story(story):
|
135 |
+
evaluation = {}
|
136 |
+
story_len = len(story["chunks"])
|
137 |
+
logger.debug(story_len)
|
138 |
+
evaluation["is_time_to_end"] = story_len > MAX_STORY_LEN
|
139 |
+
|
140 |
+
return evaluation
|
141 |
+
|
142 |
+
|
143 |
'''
|
144 |
turns next story chunk into audio and returns a URL
|
145 |
'''
|
main.py
CHANGED
@@ -6,7 +6,7 @@ from dotenv import load_dotenv
|
|
6 |
load_dotenv()
|
7 |
import helpers
|
8 |
|
9 |
-
from homeros import init_story, start_story, continue_story, finish_story, define_metadata
|
10 |
|
11 |
'''
|
12 |
Here we manage the flow and state of the story
|
@@ -71,9 +71,9 @@ def do_homeros(user_input, story):
|
|
71 |
|
72 |
# we are in the middle of the story - evaluate if time to end, or continue
|
73 |
elif story["status"] == "ongoing":
|
74 |
-
if
|
75 |
logger.debug("status: activating story finish")
|
76 |
-
story = finish_story(story)
|
77 |
story["status"] = "finished"
|
78 |
else:
|
79 |
story = continue_story(user_input, story)
|
@@ -82,7 +82,7 @@ def do_homeros(user_input, story):
|
|
82 |
next_message = story["chunks"][-1]["text"]
|
83 |
|
84 |
# story has ended, but the user still inputting. tell them it's over
|
85 |
-
elif story["status"] == "
|
86 |
next_message = helpers.get_fixed_msg("no_more_story")
|
87 |
story["status"] = "finished"
|
88 |
|
|
|
6 |
load_dotenv()
|
7 |
import helpers
|
8 |
|
9 |
+
from homeros import init_story, start_story, continue_story, finish_story, define_metadata, evaluate_story
|
10 |
|
11 |
'''
|
12 |
Here we manage the flow and state of the story
|
|
|
71 |
|
72 |
# we are in the middle of the story - evaluate if time to end, or continue
|
73 |
elif story["status"] == "ongoing":
|
74 |
+
if evaluate_story(story)["is_time_to_end"]:
|
75 |
logger.debug("status: activating story finish")
|
76 |
+
story = finish_story(user_input, story)
|
77 |
story["status"] = "finished"
|
78 |
else:
|
79 |
story = continue_story(user_input, story)
|
|
|
82 |
next_message = story["chunks"][-1]["text"]
|
83 |
|
84 |
# story has ended, but the user still inputting. tell them it's over
|
85 |
+
elif story["status"] == "finished":
|
86 |
next_message = helpers.get_fixed_msg("no_more_story")
|
87 |
story["status"] = "finished"
|
88 |
|