Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,10 +15,10 @@ def img2text(url):
|
|
15 |
text = text.replace(word, "")
|
16 |
return text.strip()
|
17 |
|
18 |
-
# Function to generate a story from text using
|
19 |
def text2story(text):
|
20 |
-
# Use the
|
21 |
-
text_generator = pipeline("
|
22 |
|
23 |
# Add a strong prompt to guide the model
|
24 |
prompt = f"Write a short, happy, and fun story for kids aged 3-10. " \
|
@@ -41,7 +41,7 @@ def text2story(text):
|
|
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
|
@@ -65,7 +65,7 @@ if uploaded_file is not None:
|
|
65 |
with open(uploaded_file.name, "wb") as file:
|
66 |
file.write(bytes_data)
|
67 |
|
68 |
-
st.image(uploaded_file, caption="Your Uploaded Image",
|
69 |
|
70 |
# Stage 1: Image to Text
|
71 |
st.text('🖼️ Processing image...')
|
@@ -84,7 +84,10 @@ if uploaded_file is not None:
|
|
84 |
|
85 |
# Play button for audio
|
86 |
if st.session_state.audio_file and st.button("🎧 Listen to the Story"):
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
# Clean up the generated audio file
|
90 |
if st.session_state.audio_file and os.path.exists(st.session_state.audio_file):
|
|
|
15 |
text = text.replace(word, "")
|
16 |
return text.strip()
|
17 |
|
18 |
+
# Function to generate a story from text using T5
|
19 |
def text2story(text):
|
20 |
+
# Use the T5 model for text generation
|
21 |
+
text_generator = pipeline("text2text-generation", model="t5-small")
|
22 |
|
23 |
# Add a strong prompt to guide the model
|
24 |
prompt = f"Write a short, happy, and fun story for kids aged 3-10. " \
|
|
|
41 |
|
42 |
# Function to convert text to audio using gTTS
|
43 |
def text2audio(story_text):
|
44 |
+
audio_file = os.path.abspath("kids_playing_audio.wav")
|
45 |
tts = gTTS(story_text, lang="en")
|
46 |
tts.save(audio_file)
|
47 |
return audio_file
|
|
|
65 |
with open(uploaded_file.name, "wb") as file:
|
66 |
file.write(bytes_data)
|
67 |
|
68 |
+
st.image(uploaded_file, caption="Your Uploaded Image", use_column_width=True)
|
69 |
|
70 |
# Stage 1: Image to Text
|
71 |
st.text('🖼️ Processing image...')
|
|
|
84 |
|
85 |
# Play button for audio
|
86 |
if st.session_state.audio_file and st.button("🎧 Listen to the Story"):
|
87 |
+
if os.path.exists(st.session_state.audio_file):
|
88 |
+
st.audio(st.session_state.audio_file, format="audio/wav")
|
89 |
+
else:
|
90 |
+
st.error("Audio file not found. Please generate the story again.")
|
91 |
|
92 |
# Clean up the generated audio file
|
93 |
if st.session_state.audio_file and os.path.exists(st.session_state.audio_file):
|