fffiloni commited on
Commit
7402605
β€’
1 Parent(s): 5e57e56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
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 split_text(text, max_length):
18
- chunks = []
19
- current_chunk = ''
20
  words = text.split()
21
 
22
  for word in words:
23
- if len(current_chunk) + len(word) <= max_length:
24
- current_chunk += ' ' + word
25
- else:
26
- chunks.append(current_chunk.strip())
27
- current_chunk = word
28
 
29
- if current_chunk:
30
- chunks.append(current_chunk.strip())
31
 
32
- return chunks
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
- max_length = 250
68
- text_chunks = split_text(story_result, max_length)
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(