Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
import difflib
|
3 |
import requests
|
4 |
import datetime
|
5 |
-
from
|
6 |
|
7 |
# --- CONFIG ---
|
8 |
GROQ_API_KEY = st.secrets.get('GROQ_API_KEY', 'YOUR_GROQ_API_KEY')
|
@@ -163,76 +163,24 @@ elif page == "Semantic Search":
|
|
163 |
st.caption("Example questions:")
|
164 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
165 |
|
166 |
-
# --- Single input with mic button
|
167 |
-
st.
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
height: 38px;
|
178 |
-
font-size: 16px;
|
179 |
-
box-sizing: border-box;
|
180 |
-
border: 1px solid #ccc;
|
181 |
-
border-radius: 4px;
|
182 |
-
}
|
183 |
-
.mic-btn {
|
184 |
-
position: absolute;
|
185 |
-
right: 5px;
|
186 |
-
top: 4px;
|
187 |
-
border: none;
|
188 |
-
background: none;
|
189 |
-
font-size: 22px;
|
190 |
-
cursor: pointer;
|
191 |
-
outline: none;
|
192 |
-
}
|
193 |
-
</style>
|
194 |
-
<div class="input-mic-container">
|
195 |
-
<input id="questionInput" class="input-mic" type="text" placeholder="Ask a question about your code" />
|
196 |
-
<button class="mic-btn" id="micBtn" title="Speak your question">π€</button>
|
197 |
-
</div>
|
198 |
-
<script>
|
199 |
-
const input = document.getElementById('questionInput');
|
200 |
-
const micBtn = document.getElementById('micBtn');
|
201 |
-
let recognition;
|
202 |
-
if ('webkitSpeechRecognition' in window) {
|
203 |
-
recognition = new webkitSpeechRecognition();
|
204 |
-
recognition.lang = 'en-US';
|
205 |
-
recognition.continuous = false;
|
206 |
-
recognition.interimResults = false;
|
207 |
-
micBtn.onclick = function(e) {
|
208 |
-
e.preventDefault();
|
209 |
-
recognition.start();
|
210 |
-
micBtn.textContent = 'ποΈ';
|
211 |
-
};
|
212 |
-
recognition.onresult = function(event) {
|
213 |
-
const transcript = event.results[0][0].transcript;
|
214 |
-
input.value = transcript;
|
215 |
-
window.dispatchEvent(new CustomEvent("streamlit_js_eval_result", {detail: transcript}));
|
216 |
-
micBtn.textContent = 'π€';
|
217 |
-
};
|
218 |
-
recognition.onerror = function() {
|
219 |
-
micBtn.textContent = 'π€';
|
220 |
-
};
|
221 |
-
recognition.onend = function() {
|
222 |
-
micBtn.textContent = 'π€';
|
223 |
-
};
|
224 |
-
} else {
|
225 |
-
micBtn.disabled = true;
|
226 |
-
micBtn.title = 'Voice not supported';
|
227 |
-
}
|
228 |
-
input.onchange = function() {
|
229 |
-
window.dispatchEvent(new CustomEvent("streamlit_js_eval_result", {detail: input.value}));
|
230 |
-
}
|
231 |
-
</script>
|
232 |
-
""", unsafe_allow_html=True)
|
233 |
|
234 |
-
#
|
235 |
-
question =
|
|
|
|
|
|
|
|
|
236 |
|
237 |
if st.button("Run Semantic Search"):
|
238 |
if not code_input.strip() or not question.strip():
|
|
|
2 |
import difflib
|
3 |
import requests
|
4 |
import datetime
|
5 |
+
from st_mic_recorder import mic_recorder
|
6 |
|
7 |
# --- CONFIG ---
|
8 |
GROQ_API_KEY = st.secrets.get('GROQ_API_KEY', 'YOUR_GROQ_API_KEY')
|
|
|
163 |
st.caption("Example questions:")
|
164 |
st.write(", ".join(EXAMPLE_QUESTIONS))
|
165 |
|
166 |
+
# --- Single input with mic button ---
|
167 |
+
st.write("You can type or use the mic to ask your question:")
|
168 |
+
|
169 |
+
# Use mic_recorder for voice input (returns text or None)
|
170 |
+
question_voice = mic_recorder(
|
171 |
+
start_prompt="π€ Speak your question",
|
172 |
+
stop_prompt="Stop",
|
173 |
+
just_once=True,
|
174 |
+
use_container_width=True,
|
175 |
+
key="mic"
|
176 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
+
# Use a single input field for both typing and voice
|
179 |
+
question = st.text_input(
|
180 |
+
"Ask a question about your code",
|
181 |
+
value=question_voice if question_voice else "",
|
182 |
+
key="sem_question"
|
183 |
+
)
|
184 |
|
185 |
if st.button("Run Semantic Search"):
|
186 |
if not code_input.strip() or not question.strip():
|