Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,6 +43,9 @@ def text2story(text):
|
|
43 |
prompt = f"<BOS> <superhero> {text}"
|
44 |
story = story_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
45 |
|
|
|
|
|
|
|
46 |
return story
|
47 |
|
48 |
# Function to convert text to audio using gTTS
|
@@ -101,12 +104,17 @@ if uploaded_file is not None:
|
|
101 |
|
102 |
# Stage 3: Story to Audio
|
103 |
st.text('π§ Turning your story into audio...')
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
106 |
# Play button for the generated audio
|
107 |
if st.button("π΅ **Play Audio**"):
|
108 |
-
st.audio(audio_file, format="audio/mp3")
|
109 |
|
110 |
# Clean up the generated audio file and uploaded image
|
111 |
-
os.
|
112 |
-
|
|
|
|
|
|
43 |
prompt = f"<BOS> <superhero> {text}"
|
44 |
story = story_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
45 |
|
46 |
+
# Remove <BOS> and <superhero> tags from the generated story
|
47 |
+
story = story.replace("<BOS>", "").replace("<superhero>", "").strip()
|
48 |
+
|
49 |
return story
|
50 |
|
51 |
# Function to convert text to audio using gTTS
|
|
|
104 |
|
105 |
# Stage 3: Story to Audio
|
106 |
st.text('π§ Turning your story into audio...')
|
107 |
+
|
108 |
+
# Use session state to avoid regenerating audio on button click
|
109 |
+
if 'audio_file' not in st.session_state:
|
110 |
+
st.session_state.audio_file = text2audio(story)
|
111 |
+
|
112 |
# Play button for the generated audio
|
113 |
if st.button("π΅ **Play Audio**"):
|
114 |
+
st.audio(st.session_state.audio_file, format="audio/mp3")
|
115 |
|
116 |
# Clean up the generated audio file and uploaded image
|
117 |
+
if os.path.exists(st.session_state.audio_file):
|
118 |
+
os.remove(st.session_state.audio_file)
|
119 |
+
if os.path.exists(uploaded_file.name):
|
120 |
+
os.remove(uploaded_file.name)
|