Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -174,53 +174,7 @@ elif page == "Semantic Search":
|
|
174 |
st.caption("Example questions:")
|
175 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
176 |
|
177 |
-
#
|
178 |
-
if "sem_question" not in st.session_state:
|
179 |
-
st.session_state["sem_question"] = ""
|
180 |
-
|
181 |
-
voice_input = components.html('''
|
182 |
-
<button id="voice-btn" style="margin-bottom:8px;">🎤 Speak your question</button>
|
183 |
-
<span id="voice-status" style="margin-left:8px;"></span>
|
184 |
-
<script>
|
185 |
-
const btn = document.getElementById('voice-btn');
|
186 |
-
const status = document.getElementById('voice-status');
|
187 |
-
let recognition;
|
188 |
-
if ('webkitSpeechRecognition' in window) {
|
189 |
-
recognition = new webkitSpeechRecognition();
|
190 |
-
recognition.lang = 'en-US';
|
191 |
-
recognition.continuous = false;
|
192 |
-
recognition.interimResults = false;
|
193 |
-
btn.onclick = function() {
|
194 |
-
recognition.start();
|
195 |
-
status.textContent = 'Listening...';
|
196 |
-
};
|
197 |
-
recognition.onresult = function(event) {
|
198 |
-
const transcript = event.results[0][0].transcript;
|
199 |
-
window.parent.postMessage({isStreamlitMessage: true, type: 'streamlit:setComponentValue', value: transcript}, '*');
|
200 |
-
status.textContent = 'Heard: ' + transcript;
|
201 |
-
};
|
202 |
-
recognition.onerror = function() {
|
203 |
-
status.textContent = 'Voice error';
|
204 |
-
};
|
205 |
-
recognition.onend = function() {
|
206 |
-
if (status.textContent === 'Listening...') status.textContent = '';
|
207 |
-
};
|
208 |
-
} else {
|
209 |
-
btn.disabled = true;
|
210 |
-
status.textContent = 'Voice not supported';
|
211 |
-
}
|
212 |
-
</script>
|
213 |
-
''', height=60)
|
214 |
-
|
215 |
-
# If voice input is received, update the question field directly in session state
|
216 |
-
if voice_input and isinstance(voice_input, str) and voice_input.strip():
|
217 |
-
if is_coding_question(voice_input):
|
218 |
-
st.session_state["sem_question"] = voice_input
|
219 |
-
st.success(f"Question recognized: {voice_input}")
|
220 |
-
else:
|
221 |
-
st.warning("Please ask a relevant question.")
|
222 |
-
|
223 |
-
# Single input field for question (typed or spoken)
|
224 |
question = st.text_input("Ask a question about your code", key="sem_question")
|
225 |
|
226 |
# Run Semantic Search button
|
|
|
174 |
st.caption("Example questions:")
|
175 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
176 |
|
177 |
+
# Single input field for question (typed only)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
question = st.text_input("Ask a question about your code", key="sem_question")
|
179 |
|
180 |
# Run Semantic Search button
|