Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -14,22 +14,21 @@ openai_api_key = os.environ.get("OPENAI_API_KEY")
|
|
14 |
|
15 |
llm = OpenAI(temperature=0.9)
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
words = text.split()
|
21 |
|
22 |
for word in words:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
current_chunk = word
|
28 |
|
29 |
-
if
|
30 |
-
|
31 |
|
32 |
-
return
|
33 |
|
34 |
def join_wav_files(input_files, output_file):
|
35 |
# Open the first input file to get its parameters
|
@@ -53,7 +52,9 @@ def generate_story(text):
|
|
53 |
template="""
|
54 |
You are a fun and seasoned storyteller.
|
55 |
Generate a short story for a 5 years old audience about {text}.
|
56 |
-
|
|
|
|
|
57 |
)
|
58 |
story = LLMChain(llm=llm, prompt=prompt)
|
59 |
story_result = story.run(text=text)
|
@@ -64,8 +65,8 @@ def generate_story(text):
|
|
64 |
—
|
65 |
""")
|
66 |
input_waves = []
|
67 |
-
|
68 |
-
text_chunks =
|
69 |
for chunk in text_chunks:
|
70 |
print(chunk)
|
71 |
result = eleven.predict(
|
|
|
14 |
|
15 |
llm = OpenAI(temperature=0.9)
|
16 |
|
17 |
+
def split_text_into_sentences(text):
|
18 |
+
sentences = []
|
19 |
+
current_sentence = ''
|
20 |
words = text.split()
|
21 |
|
22 |
for word in words:
|
23 |
+
current_sentence += ' ' + word
|
24 |
+
if word.endswith('.'):
|
25 |
+
sentences.append(current_sentence.strip())
|
26 |
+
current_sentence = ''
|
|
|
27 |
|
28 |
+
if current_sentence:
|
29 |
+
sentences.append(current_sentence.strip())
|
30 |
|
31 |
+
return sentences
|
32 |
|
33 |
def join_wav_files(input_files, output_file):
|
34 |
# Open the first input file to get its parameters
|
|
|
52 |
template="""
|
53 |
You are a fun and seasoned storyteller.
|
54 |
Generate a short story for a 5 years old audience about {text}.
|
55 |
+
Use short sentences. The story is not too long, but not too short either.
|
56 |
+
Always finish your story with "The End".
|
57 |
+
"""
|
58 |
)
|
59 |
story = LLMChain(llm=llm, prompt=prompt)
|
60 |
story_result = story.run(text=text)
|
|
|
65 |
—
|
66 |
""")
|
67 |
input_waves = []
|
68 |
+
|
69 |
+
text_chunks = split_text_into_sentences(story_result)
|
70 |
for chunk in text_chunks:
|
71 |
print(chunk)
|
72 |
result = eleven.predict(
|