smtsead commited on
Commit
e282e9c
·
verified ·
1 Parent(s): 1e96eb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -46,6 +46,10 @@ def text2story(text):
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
@@ -90,7 +94,7 @@ if uploaded_file is not None:
90
  file.write(bytes_data)
91
 
92
  # Display the uploaded image
93
- st.image(uploaded_file, caption="Your awesome picture!", use_container_width=True)
94
 
95
  # Stage 1: Image to Text
96
  st.text('✨ Turning your picture into words...')
@@ -111,10 +115,11 @@ if uploaded_file is not None:
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)
 
46
  # Remove <BOS> and <superhero> tags from the generated story
47
  story = story.replace("<BOS>", "").replace("<superhero>", "").strip()
48
 
49
+ # Remove the input text (scenario) from the generated story
50
+ if text in story:
51
+ story = story.replace(text, "").strip()
52
+
53
  return story
54
 
55
  # Function to convert text to audio using gTTS
 
94
  file.write(bytes_data)
95
 
96
  # Display the uploaded image
97
+ st.image(uploaded_file, caption="Your awesome picture!", use_column_width=True)
98
 
99
  # Stage 1: Image to Text
100
  st.text('✨ Turning your picture into words...')
 
115
 
116
  # Play button for the generated audio
117
  if st.button("🎵 **Play Audio**"):
118
+ if os.path.exists(st.session_state.audio_file):
119
+ st.audio(st.session_state.audio_file, format="audio/mp3")
120
+ else:
121
+ st.error("Audio file not found. Please try again.")
122
 
123
  # Clean up the generated audio file and uploaded image
 
 
124
  if os.path.exists(uploaded_file.name):
125
  os.remove(uploaded_file.name)