smtsead commited on
Commit
c8f4b28
·
verified ·
1 Parent(s): 3928fc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -13
app.py CHANGED
@@ -36,24 +36,13 @@ def text2story(text):
36
  Returns:
37
  str: Generated story suitable for kids aged 3-10, within 100 words.
38
  """
39
- # Add a prompt to ensure the story is happy, fun, and appropriate for kids
40
- prompt = f"Write a kids story based on below scenario :{text}."
41
-
42
  # Load the text generation model
43
  story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator")
44
 
45
  # Generate the story
46
- story = story_generator(prompt, max_length=150, num_return_sequences=1)[0]["generated_text"]
47
-
48
- # Remove the prompt from the generated story
49
- story = story.replace(prompt, "").strip()
50
-
51
- # Ensure the story is within 100 words
52
- story_words = story.split()
53
- if len(story_words) > 100:
54
- story = " ".join(story_words[:100])
55
 
56
- return story
57
 
58
  # Function to convert text to audio using gTTS
59
  def text2audio(story_text):
 
36
  Returns:
37
  str: Generated story suitable for kids aged 3-10, within 100 words.
38
  """
39
+
 
 
40
  # Load the text generation model
41
  story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator")
42
 
43
  # Generate the story
44
+ story = story_generator(f"<BOS> <superhero> {text}"))
 
 
 
 
 
 
 
 
45
 
 
46
 
47
  # Function to convert text to audio using gTTS
48
  def text2audio(story_text):