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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -194,12 +194,10 @@ elif page == "Semantic 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,10 +212,15 @@ elif page == "Semantic Search":
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:
 
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
  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: