Solshine commited on
Commit
8103164
β€’
1 Parent(s): 6ad68ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -106,28 +106,22 @@ def launch_bot():
106
  # st.write("Mistral:" ) #Needs finishing
107
  # else:
108
  st.write(response)
109
-
 
 
 
 
 
 
 
 
 
 
 
 
110
  message = {"role": "assistant", "content": response}
111
  st.session_state.messages.append(message)
112
 
113
- # If assistant has most recently reaponded create audio of response
114
- # if st.session_state.messages[-1]["role"] == "assistant":
115
- audio_result = st.button("Convert to Audio πŸ”Š")
116
- if audio_result:
117
- st.session_state.messages.append({"role": "user", "content": "Convert to Audio πŸ”Š"})
118
- with st.chat_message("user"):
119
- st.write("Convert to Audio πŸ”Š")
120
- with st.popover("Open Audio"):
121
- message2 = {"role": "assistant", "content": "Converting text to speech. This may take a few minutes."}
122
- # Create temporary file for audio
123
- with tempfile.NamedTemporaryFile(suffix=".mp3") as temp_file:
124
- tts = gTTS('Add text-to-speech to your app', lang='en')
125
- tts.write_to_fp(temp_file)
126
- temp_file.seek(0) # rewind the file pointer
127
-
128
- # Play the audio file
129
- st.audio(temp_file)
130
-
131
 
132
 
133
  if __name__ == "__main__":
 
106
  # st.write("Mistral:" ) #Needs finishing
107
  # else:
108
  st.write(response)
109
+
110
+ audio_result = st.button("Convert to Audio πŸ”Š")
111
+ if audio_result:
112
+ # st.session_state.messages.append({"role": "user", "content": "Convert to Audio πŸ”Š"})
113
+ # with st.chat_message("user"):
114
+ # st.write("Convert to Audio πŸ”Š")
115
+ with st.popover("Open Audio"):
116
+ sound_file = BytesIO()
117
+ tts = gTTS(response, lang='en')
118
+ tts.write_to_fp(sound_file)
119
+
120
+ st.audio(sound_file)
121
+
122
  message = {"role": "assistant", "content": response}
123
  st.session_state.messages.append(message)
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
 
127
  if __name__ == "__main__":