Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,9 @@ import hashlib
|
|
14 |
from audio_recorder_streamlit import audio_recorder
|
15 |
from transformers import pipeline
|
16 |
|
|
|
|
|
|
|
17 |
######################################
|
18 |
# Voice Input Helper Functions
|
19 |
######################################
|
@@ -41,7 +44,7 @@ def get_voice_transcription(state_key):
|
|
41 |
# Use a unique key for the recorder widget
|
42 |
audio_bytes = audio_recorder(key=state_key + "_audio",
|
43 |
pause_threshold=0.8,
|
44 |
-
text="",
|
45 |
recording_color="#e8b62c",
|
46 |
neutral_color="#6aa36f")
|
47 |
if audio_bytes:
|
@@ -119,14 +122,7 @@ def inject_custom_css():
|
|
119 |
.progress-fill { height: 100%; background: linear-gradient(90deg, #6C63FF, #3B82F6);
|
120 |
transition: width 0.5s ease; }
|
121 |
.question-count { color: #6C63FF; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; }
|
122 |
-
|
123 |
-
.input-with-mic { display: flex; align-items: center; gap: 10px; }
|
124 |
-
.input-with-mic input { flex: 1; }
|
125 |
-
.mic-button { background: #6C63FF !important; color: white !important;
|
126 |
-
border-radius: 50% !important; width: 40px !important;
|
127 |
-
height: 40px !important; padding: 0 !important;
|
128 |
-
min-width: 0 !important; }
|
129 |
-
.mic-button:hover { transform: scale(1.1) !important; }
|
130 |
</style>
|
131 |
""", unsafe_allow_html=True)
|
132 |
|
@@ -271,22 +267,12 @@ def main():
|
|
271 |
with st.form("start_form"):
|
272 |
# --- Voice Input for Category ---
|
273 |
st.markdown("#### Use Voice (English/Urdu) for Category Input")
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
with col2:
|
280 |
-
st.markdown("<div style='height: 52px; display: flex; align-items: center;'>", unsafe_allow_html=True)
|
281 |
-
audio_bytes = audio_recorder(text="",
|
282 |
-
pause_threshold=0.8,
|
283 |
-
key="voice_category_audio",
|
284 |
-
recording_color="#e8b62c",
|
285 |
-
neutral_color="#6aa36f")
|
286 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
287 |
-
|
288 |
if st.form_submit_button("Start Game"):
|
289 |
-
category_input = voice_category.strip().lower()
|
290 |
if not category_input:
|
291 |
st.error("Please enter a category!")
|
292 |
elif category_input not in ["person", "place", "object"]:
|
@@ -333,22 +319,11 @@ def main():
|
|
333 |
with st.form("answer_form"):
|
334 |
# --- Voice Input for Answer ---
|
335 |
st.markdown("#### Use Voice (English/Urdu) for Your Answer")
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
key=f"answer_{st.session_state.current_q}")
|
341 |
-
with col2:
|
342 |
-
st.markdown("<div style='height: 52px; display: flex; align-items: center;'>", unsafe_allow_html=True)
|
343 |
-
audio_bytes = audio_recorder(text="",
|
344 |
-
pause_threshold=0.8,
|
345 |
-
key="voice_answer_audio",
|
346 |
-
recording_color="#e8b62c",
|
347 |
-
neutral_color="#6aa36f")
|
348 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
349 |
-
|
350 |
if st.form_submit_button("Submit"):
|
351 |
-
answer_input = voice_answer.strip().lower()
|
352 |
if answer_input not in ["yes", "no", "both"]:
|
353 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
354 |
else:
|
@@ -375,24 +350,14 @@ def main():
|
|
375 |
with st.expander("Need Help? Chat with AI Assistant"):
|
376 |
# --- Voice Input for Help Query ---
|
377 |
st.markdown("#### Use Voice (English/Urdu) for Help Query")
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
key="help_query")
|
383 |
-
with col2:
|
384 |
-
st.markdown("<div style='height: 52px; display: flex; align-items: center;'>", unsafe_allow_html=True)
|
385 |
-
audio_bytes = audio_recorder(text="",
|
386 |
-
pause_threshold=0.8,
|
387 |
-
key="voice_help_audio",
|
388 |
-
recording_color="#e8b62c",
|
389 |
-
neutral_color="#6aa36f")
|
390 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
391 |
-
|
392 |
if st.button("Send", key="send_help"):
|
393 |
-
if
|
394 |
-
help_response = ask_help_agent(
|
395 |
-
st.session_state.help_conversation.append({"query":
|
396 |
else:
|
397 |
st.error("Please enter a query!")
|
398 |
if st.session_state.help_conversation:
|
@@ -416,20 +381,8 @@ def main():
|
|
416 |
</div>
|
417 |
''', unsafe_allow_html=True)
|
418 |
with st.form("confirm_form"):
|
419 |
-
|
420 |
-
with col1:
|
421 |
-
confirm_input = st.text_input("Type your answer (yes/no/both):", key="confirm_input")
|
422 |
-
with col2:
|
423 |
-
st.markdown("<div style='height: 52px; display: flex; align-items: center;'>", unsafe_allow_html=True)
|
424 |
-
audio_bytes = audio_recorder(text="",
|
425 |
-
pause_threshold=0.8,
|
426 |
-
key="voice_confirm_audio",
|
427 |
-
recording_color="#e8b62c",
|
428 |
-
neutral_color="#6aa36f")
|
429 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
430 |
-
|
431 |
if st.form_submit_button("Submit"):
|
432 |
-
confirm_input = confirm_input.strip().lower()
|
433 |
if confirm_input not in ["yes", "no", "both"]:
|
434 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
435 |
else:
|
@@ -477,4 +430,4 @@ def main():
|
|
477 |
st.experimental_rerun()
|
478 |
|
479 |
if __name__ == "__main__":
|
480 |
-
main()
|
|
|
14 |
from audio_recorder_streamlit import audio_recorder
|
15 |
from transformers import pipeline
|
16 |
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
######################################
|
21 |
# Voice Input Helper Functions
|
22 |
######################################
|
|
|
44 |
# Use a unique key for the recorder widget
|
45 |
audio_bytes = audio_recorder(key=state_key + "_audio",
|
46 |
pause_threshold=0.8,
|
47 |
+
text="Speak to type",
|
48 |
recording_color="#e8b62c",
|
49 |
neutral_color="#6aa36f")
|
50 |
if audio_bytes:
|
|
|
122 |
.progress-fill { height: 100%; background: linear-gradient(90deg, #6C63FF, #3B82F6);
|
123 |
transition: width 0.5s ease; }
|
124 |
.question-count { color: #6C63FF; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; }
|
125 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
</style>
|
127 |
""", unsafe_allow_html=True)
|
128 |
|
|
|
267 |
with st.form("start_form"):
|
268 |
# --- Voice Input for Category ---
|
269 |
st.markdown("#### Use Voice (English/Urdu) for Category Input")
|
270 |
+
voice_category = get_voice_transcription("voice_category")
|
271 |
+
# The text input now defaults to any spoken words
|
272 |
+
category_input = st.text_input("Enter category (person/place/object):",
|
273 |
+
value=voice_category.strip(),
|
274 |
+
key="category_input").strip().lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
if st.form_submit_button("Start Game"):
|
|
|
276 |
if not category_input:
|
277 |
st.error("Please enter a category!")
|
278 |
elif category_input not in ["person", "place", "object"]:
|
|
|
319 |
with st.form("answer_form"):
|
320 |
# --- Voice Input for Answer ---
|
321 |
st.markdown("#### Use Voice (English/Urdu) for Your Answer")
|
322 |
+
voice_answer = get_voice_transcription("voice_answer")
|
323 |
+
answer_input = st.text_input("Your answer (yes/no/both):",
|
324 |
+
value=voice_answer.strip(),
|
325 |
+
key=f"answer_{st.session_state.current_q}").strip().lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
if st.form_submit_button("Submit"):
|
|
|
327 |
if answer_input not in ["yes", "no", "both"]:
|
328 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
329 |
else:
|
|
|
350 |
with st.expander("Need Help? Chat with AI Assistant"):
|
351 |
# --- Voice Input for Help Query ---
|
352 |
st.markdown("#### Use Voice (English/Urdu) for Help Query")
|
353 |
+
voice_help = get_voice_transcription("voice_help")
|
354 |
+
help_query = st.text_input("Enter your help query:",
|
355 |
+
value=voice_help.strip(),
|
356 |
+
key="help_query")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
if st.button("Send", key="send_help"):
|
358 |
+
if help_query:
|
359 |
+
help_response = ask_help_agent(help_query)
|
360 |
+
st.session_state.help_conversation.append({"query": help_query, "response": help_response})
|
361 |
else:
|
362 |
st.error("Please enter a query!")
|
363 |
if st.session_state.help_conversation:
|
|
|
381 |
</div>
|
382 |
''', unsafe_allow_html=True)
|
383 |
with st.form("confirm_form"):
|
384 |
+
confirm_input = st.text_input("Type your answer (yes/no/both):", key="confirm_input").strip().lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
if st.form_submit_button("Submit"):
|
|
|
386 |
if confirm_input not in ["yes", "no", "both"]:
|
387 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
388 |
else:
|
|
|
430 |
st.experimental_rerun()
|
431 |
|
432 |
if __name__ == "__main__":
|
433 |
+
main()
|