SaileshSivan commited on
Commit
3b8077c
Β·
1 Parent(s): 6443613

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -140,6 +140,7 @@ if clear_chat_button:
140
  # Clear the entire session and chat
141
  st.session_state['flowmessages'] = []
142
 
 
143
  # If the "Submit" button is clicked
144
  if submit:
145
  # Display loading message while processing
@@ -151,23 +152,28 @@ if submit:
151
  # Display conversation history
152
  for message in st.session_state['flowmessages']:
153
  if isinstance(message, AIMessage):
154
- # Display Doctor AI's response header and content
155
- doctor_ai_header = st.header("Doctor AI", divider=True)
156
- doctor_ai_content = st.write(message.content)
157
-
158
- # Add a button to play the audio
159
- if st.button("πŸ”Š Play Audio", key="audio_button"):
160
- # Text-to-speech
161
- audio_response = openai.audio.speech.create(
162
- model="tts-1",
163
- voice="nova",
164
- input=response,
165
- response_format="mp3",
166
- speed=1.0
167
- )
168
-
169
- # Play the audio
170
- st.audio(audio_response.content, format="audio/wav", start_time=0)
 
 
 
 
 
171
 
172
 
173
 
 
140
  # Clear the entire session and chat
141
  st.session_state['flowmessages'] = []
142
 
143
+ # If the "Submit" button is clicked
144
  # If the "Submit" button is clicked
145
  if submit:
146
  # Display loading message while processing
 
152
  # Display conversation history
153
  for message in st.session_state['flowmessages']:
154
  if isinstance(message, AIMessage):
155
+ st.header("Doctor AI πŸ”Š", divider=True)
156
+ st.write(message.content)
157
+ elif isinstance(message, HumanMessage):
158
+ st.header(":blue[You]", divider=True)
159
+ st.write(message.content)
160
+
161
+ # Text-to-speech
162
+ audio_response = openai.audio.speech.create(
163
+ model="tts-1",
164
+ voice="nova",
165
+ input=response,
166
+ response_format="mp3",
167
+ speed=1.0
168
+ )
169
+
170
+ # Embed audio in the webpage without saving it
171
+ st.header(':blue[Listen or Download] :loud_sound:')
172
+
173
+ # Check if the "πŸ”Š" button is clicked
174
+ if st.button("πŸ”Š Play Audio"):
175
+ st.audio(audio_response.content, format="audio/mp3", start_time=0)
176
+
177
 
178
 
179