smtsead commited on
Commit
9984bc1
·
verified ·
1 Parent(s): 02c1ec5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -24,30 +24,24 @@ def text2story(text):
24
  prompt = f"Write a short, happy, and fun story for kids aged 3-10. " \
25
  f"The story should be about: {text}. " \
26
  "Make it cheerful, imaginative, and suitable for young children. " \
27
- "Avoid any scary or sad elements. The story must be exactly 95 words."
28
 
29
  # Generate the story
30
- story = text_generator(prompt, max_length=150, num_return_sequences=1)[0]["generated_text"]
31
 
32
  # Clean up the output to remove the prompt
33
  story = story.replace(prompt, "").strip()
34
 
35
- # Ensure the story is exactly 95 words
36
  words = story.split()
37
  if len(words) > 95:
38
  story = " ".join(words[:95])
39
- elif len(words) < 95:
40
- # If the story is too short, pad it with a happy ending
41
- story = " ".join(words) + " They all laughed and played together, making it the best day ever!"
42
- words = story.split()
43
- if len(words) > 95:
44
- story = " ".join(words[:95])
45
 
46
  return story
47
 
48
  # Function to convert text to audio using gTTS
49
  def text2audio(story_text):
50
- audio_file = "kids_playing_audio.wav" # Use the correct file name
51
  tts = gTTS(story_text, lang="en")
52
  tts.save(audio_file)
53
  return audio_file
 
24
  prompt = f"Write a short, happy, and fun story for kids aged 3-10. " \
25
  f"The story should be about: {text}. " \
26
  "Make it cheerful, imaginative, and suitable for young children. " \
27
+ "Avoid any scary or sad elements. The story should be under 95 words."
28
 
29
  # Generate the story
30
+ story = text_generator(prompt, max_length=95, num_return_sequences=1)[0]["generated_text"]
31
 
32
  # Clean up the output to remove the prompt
33
  story = story.replace(prompt, "").strip()
34
 
35
+ # Ensure the story is under 95 words
36
  words = story.split()
37
  if len(words) > 95:
38
  story = " ".join(words[:95])
 
 
 
 
 
 
39
 
40
  return story
41
 
42
  # Function to convert text to audio using gTTS
43
  def text2audio(story_text):
44
+ audio_file = "kids_playing_audio.wav"
45
  tts = gTTS(story_text, lang="en")
46
  tts.save(audio_file)
47
  return audio_file