ziyadsuper2017 commited on
Commit
4af010e
·
verified ·
1 Parent(s): 248fc3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -214,9 +214,11 @@ async def run_webrtc():
214
  audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=None)
215
  audio_data = [frame.to_ndarray() for frame in audio_frames]
216
  st.session_state.audio_data = convert_frames_to_wav(audio_data)
 
 
217
 
218
- if st.button("Send Recording"):
219
- send_message(audio_data=st.session_state.audio_data)
220
 
221
  # --- Other Buttons ---
222
  st.button("Clear Conversation", on_click=clear_conversation)
@@ -227,20 +229,17 @@ st.session_state.uploaded_files = uploaded_files
227
  # --- JavaScript for Ctrl+Enter ---
228
  st.markdown(
229
  """
230
- <script>
231
- document.addEventListener('DOMContentLoaded', (event) => {
232
- document.querySelector('.stTextArea textarea').addEventListener('keydown', function(e) {
233
- if (e.key === 'Enter' && e.ctrlKey) {
234
- document.querySelector('.stButton > button').click();
235
- e.preventDefault();
236
- }
237
- });
238
- });
239
- </script>
240
  """,
241
  unsafe_allow_html=True
242
  )
243
 
244
  # --- Run WebRTC and display chat history ---
245
- asyncio.new_event_loop().run_until_complete(run_webrtc())
246
  display_chat_history()
 
214
  audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=None)
215
  audio_data = [frame.to_ndarray() for frame in audio_frames]
216
  st.session_state.audio_data = convert_frames_to_wav(audio_data)
217
+ else:
218
+ st.session_state.is_recording = False
219
 
220
+ if st.button("Send Recording"):
221
+ send_message(audio_data=st.session_state.audio_data)
222
 
223
  # --- Other Buttons ---
224
  st.button("Clear Conversation", on_click=clear_conversation)
 
229
  # --- JavaScript for Ctrl+Enter ---
230
  st.markdown(
231
  """
232
+ <script>
233
+ document.addEventListener("keydown", function(event) {
234
+ if (event.ctrlKey && event.key === 'Enter') {
235
+ document.querySelector('button[type="primary"]').click();
236
+ }
237
+ });
238
+ </script>
 
 
 
239
  """,
240
  unsafe_allow_html=True
241
  )
242
 
243
  # --- Run WebRTC and display chat history ---
244
+ asyncio.run(run_webrtc())
245
  display_chat_history()