smtsead commited on
Commit
18423bf
·
verified ·
1 Parent(s): a107515

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -30,11 +30,16 @@ def text2story(text):
30
  Returns:
31
  str: Generated story suitable for kids aged 3-10.
32
  """
33
- # Prompt to ensure the story is happy and suitable for kids
34
- prompt = f"Write a short, happy, and fun story for kids aged 3-10. The story should be about: {text}. Make it cheerful, imaginative, and suitable for young children. Avoid any scary or sad elements. The story should be under 95 words."
35
 
36
  text_generator = pipeline("text2text-generation", model="t5-small")
37
- story = text_generator(prompt, max_length=100)[0]['generated_text']
 
 
 
 
 
38
  return story
39
 
40
  # Function to convert text to audio using gTTS
 
30
  Returns:
31
  str: Generated story suitable for kids aged 3-10.
32
  """
33
+ # Adjusted prompt to ensure the model generates a story
34
+ prompt = f"Write a short, happy, and fun story for kids aged 3-10 about: {text}. Make it cheerful, imaginative, and suitable for young children. Avoid any scary or sad elements. The story should be under 95 words."
35
 
36
  text_generator = pipeline("text2text-generation", model="t5-small")
37
+ story = text_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
38
+
39
+ # Remove any repetition of the prompt in the output
40
+ if prompt in story:
41
+ story = story.replace(prompt, "").strip()
42
+
43
  return story
44
 
45
  # Function to convert text to audio using gTTS