smtsead commited on
Commit
1e96eb3
Β·
verified Β·
1 Parent(s): 2bdfc3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
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
- audio_file = text2audio(story)
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.remove(audio_file)
112
- os.remove(uploaded_file.name)
 
 
 
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)