Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
|
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS # Using gTTS for text-to-speech
|
5 |
import os
|
|
|
6 |
|
7 |
# function part
|
8 |
# img2text
|
@@ -15,13 +16,15 @@ def img2text(url):
|
|
15 |
|
16 |
# text2story
|
17 |
def text2story(text):
|
18 |
-
# Use
|
19 |
-
story_generator = pipeline("text-generation", model="
|
20 |
-
# Add a prompt to guide the story generation
|
21 |
-
prompt = f"Write a fun and realistic story for kids based on this: {text}.
|
22 |
story = story_generator(prompt, max_length=95, num_return_sequences=1)[0]["generated_text"]
|
23 |
# Remove the prompt from the generated story
|
24 |
-
story = story.replace(prompt, "").strip()
|
|
|
|
|
25 |
return story[:95] # Limit to 95 words
|
26 |
|
27 |
# text2audio
|
|
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS # Using gTTS for text-to-speech
|
5 |
import os
|
6 |
+
import re # For removing unwanted words
|
7 |
|
8 |
# function part
|
9 |
# img2text
|
|
|
16 |
|
17 |
# text2story
|
18 |
def text2story(text):
|
19 |
+
# Use facebook/bart-large-cnn for text generation
|
20 |
+
story_generator = pipeline("text-generation", model="facebook/bart-large-cnn")
|
21 |
+
# Add a more explicit prompt to guide the story generation
|
22 |
+
prompt = f"Write a fun and realistic story for kids based on this: {text}. The story should be under 95 words and suitable for children aged 3-10. Avoid using the word 'illustration'."
|
23 |
story = story_generator(prompt, max_length=95, num_return_sequences=1)[0]["generated_text"]
|
24 |
# Remove the prompt from the generated story
|
25 |
+
story = story.replace(prompt, "").strip()
|
26 |
+
# Remove the word "illustration" (case-insensitive) using regex
|
27 |
+
story = re.sub(r"\billustration\b", "", story, flags=re.IGNORECASE)
|
28 |
return story[:95] # Limit to 95 words
|
29 |
|
30 |
# text2audio
|