Naz786 commited on
Commit
b3d40f9
·
verified ·
1 Parent(s): 5b01e25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -194,10 +194,12 @@ elif page == "Semantic Search":
194
 
195
  recognition.onresult = (event) => {
196
  const transcript = event.results[0][0].transcript;
197
- // Update URL query parameter with recognized text
198
- const url = new URL(window.location);
199
- url.searchParams.set('voice_input', transcript);
200
- window.history.replaceState(null, '', url);
 
 
201
  micBtn.textContent = '🎤';
202
  };
203
 
@@ -212,15 +214,10 @@ elif page == "Semantic Search":
212
  scrolling=False,
213
  )
214
 
215
- # Check if voice input is passed via query params
216
- query_params = st.experimental_get_query_params()
217
- if "voice_input" in query_params:
218
- voice_text = query_params["voice_input"][0]
219
- if voice_text != st.session_state.voice_question:
220
- st.session_state.voice_question = voice_text
221
- st.session_state.auto_run_search = True
222
- # Clear the query param to avoid repeated triggers
223
- st.experimental_set_query_params()
224
 
225
  # Automatically run semantic search if flag is set
226
  if st.session_state.auto_run_search:
 
194
 
195
  recognition.onresult = (event) => {
196
  const transcript = event.results[0][0].transcript;
197
+ // Send transcript to Streamlit by updating the input field
198
+ const inputBox = window.parent.document.querySelector('input[data-key="question_input"]');
199
+ if (inputBox) {
200
+ inputBox.value = transcript;
201
+ inputBox.dispatchEvent(new Event('input', { bubbles: true }));
202
+ }
203
  micBtn.textContent = '🎤';
204
  };
205
 
 
214
  scrolling=False,
215
  )
216
 
217
+ # Update session state voice_question if question input changed manually or by voice
218
+ if question != st.session_state.voice_question:
219
+ st.session_state.voice_question = question
220
+ st.session_state.auto_run_search = True
 
 
 
 
 
221
 
222
  # Automatically run semantic search if flag is set
223
  if st.session_state.auto_run_search: