Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -166,10 +166,8 @@ elif page == "Semantic Search":
|
|
| 166 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
| 167 |
|
| 168 |
# --- Voice input widget ---
|
| 169 |
-
if
|
| 170 |
-
st.session_state[
|
| 171 |
-
if 'run_semantic_search' not in st.session_state:
|
| 172 |
-
st.session_state['run_semantic_search'] = False
|
| 173 |
|
| 174 |
voice_input = components.html('''
|
| 175 |
<button id="voice-btn" style="margin-bottom:8px;">🎤 Speak your question</button>
|
|
@@ -205,23 +203,19 @@ elif page == "Semantic Search":
|
|
| 205 |
</script>
|
| 206 |
''', height=60)
|
| 207 |
|
| 208 |
-
#
|
| 209 |
if voice_input and isinstance(voice_input, str) and voice_input.strip():
|
| 210 |
if is_coding_question(voice_input):
|
| 211 |
-
st.session_state[
|
| 212 |
-
st.session_state['run_semantic_search'] = True
|
| 213 |
st.success(f"Question recognized: {voice_input}")
|
| 214 |
else:
|
| 215 |
st.warning("Please ask a relevant question.")
|
| 216 |
|
| 217 |
-
#
|
| 218 |
-
question = st.text_input("Ask a question about your code", value=st.session_state
|
| 219 |
|
| 220 |
# Run Semantic Search button
|
| 221 |
-
|
| 222 |
-
run_search = run_btn or st.session_state.get('run_semantic_search', False)
|
| 223 |
-
if run_search:
|
| 224 |
-
st.session_state['run_semantic_search'] = False # reset trigger
|
| 225 |
if not code_input.strip() or not question.strip():
|
| 226 |
st.error("Both code and question are required.")
|
| 227 |
elif not code_matches_language(code_input, programming_language):
|
|
|
|
| 166 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
| 167 |
|
| 168 |
# --- Voice input widget ---
|
| 169 |
+
if "sem_question" not in st.session_state:
|
| 170 |
+
st.session_state["sem_question"] = ""
|
|
|
|
|
|
|
| 171 |
|
| 172 |
voice_input = components.html('''
|
| 173 |
<button id="voice-btn" style="margin-bottom:8px;">🎤 Speak your question</button>
|
|
|
|
| 203 |
</script>
|
| 204 |
''', height=60)
|
| 205 |
|
| 206 |
+
# If voice input is received, update the question field directly
|
| 207 |
if voice_input and isinstance(voice_input, str) and voice_input.strip():
|
| 208 |
if is_coding_question(voice_input):
|
| 209 |
+
st.session_state["sem_question"] = voice_input
|
|
|
|
| 210 |
st.success(f"Question recognized: {voice_input}")
|
| 211 |
else:
|
| 212 |
st.warning("Please ask a relevant question.")
|
| 213 |
|
| 214 |
+
# Single input field for question (typed or spoken)
|
| 215 |
+
question = st.text_input("Ask a question about your code", value=st.session_state["sem_question"], key="sem_question")
|
| 216 |
|
| 217 |
# Run Semantic Search button
|
| 218 |
+
if st.button("Run Semantic Search"):
|
|
|
|
|
|
|
|
|
|
| 219 |
if not code_input.strip() or not question.strip():
|
| 220 |
st.error("Both code and question are required.")
|
| 221 |
elif not code_matches_language(code_input, programming_language):
|