Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from io import BytesIO
|
|
| 13 |
import hashlib
|
| 14 |
from audio_recorder_streamlit import audio_recorder
|
| 15 |
from transformers import pipeline
|
| 16 |
-
|
| 17 |
|
| 18 |
|
| 19 |
|
|
@@ -23,7 +23,8 @@ st.experimental_rerun()
|
|
| 23 |
|
| 24 |
@st.cache_resource
|
| 25 |
def load_voice_model():
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
def process_audio(audio_bytes):
|
| 29 |
waveform, sample_rate = torchaudio.load(BytesIO(audio_bytes))
|
|
@@ -58,7 +59,7 @@ def get_voice_transcription(state_key):
|
|
| 58 |
st.info(f"📝 Transcribed: {transcribed_text}")
|
| 59 |
# Append (or set) new transcription
|
| 60 |
st.session_state[state_key] += (" " + transcribed_text).strip()
|
| 61 |
-
st.
|
| 62 |
except Exception as e:
|
| 63 |
st.error(f"Voice input error: {str(e)}")
|
| 64 |
return st.session_state[state_key]
|
|
@@ -122,7 +123,12 @@ def inject_custom_css():
|
|
| 122 |
transition: width 0.5s ease; }
|
| 123 |
.question-count { color: #6C63FF; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; }
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
/* Add these new styles for the info modal */
|
| 127 |
.info-modal {
|
| 128 |
position: fixed;
|
|
@@ -366,7 +372,7 @@ def main():
|
|
| 366 |
{"role": "assistant", "content": first_question}
|
| 367 |
]
|
| 368 |
st.session_state.game_state = "gameplay"
|
| 369 |
-
st.
|
| 370 |
|
| 371 |
# Gameplay screen with progress bar
|
| 372 |
elif st.session_state.game_state == "gameplay":
|
|
@@ -394,7 +400,7 @@ def main():
|
|
| 394 |
if "Final Guess:" in current_question:
|
| 395 |
st.session_state.final_guess = current_question.split("Final Guess:")[1].strip()
|
| 396 |
st.session_state.game_state = "confirm_guess"
|
| 397 |
-
st.
|
| 398 |
with st.form("answer_form"):
|
| 399 |
# --- Voice Input for Answer ---
|
| 400 |
st.markdown("#### Use Voice (English/Urdu) for Your Answer")
|
|
@@ -425,7 +431,7 @@ def main():
|
|
| 425 |
st.session_state.current_q += 1
|
| 426 |
if st.session_state.current_q >= 20:
|
| 427 |
st.session_state.game_state = "result"
|
| 428 |
-
st.
|
| 429 |
with st.expander("Need Help? Chat with AI Assistant"):
|
| 430 |
# --- Voice Input for Help Query ---
|
| 431 |
st.markdown("#### Use Voice (English/Urdu) for Help Query")
|
|
@@ -467,7 +473,7 @@ def main():
|
|
| 467 |
else:
|
| 468 |
if confirm_input == "yes":
|
| 469 |
st.session_state.game_state = "result"
|
| 470 |
-
st.
|
| 471 |
st.stop()
|
| 472 |
else:
|
| 473 |
st.session_state.conversation_history.append(
|
|
@@ -483,7 +489,7 @@ def main():
|
|
| 483 |
{"role": "assistant", "content": next_response}
|
| 484 |
)
|
| 485 |
st.session_state.current_q += 1
|
| 486 |
-
st.
|
| 487 |
|
| 488 |
elif st.session_state.game_state == "result":
|
| 489 |
if not st.session_state.final_guess:
|
|
@@ -506,7 +512,7 @@ def main():
|
|
| 506 |
unsafe_allow_html=True)
|
| 507 |
if st.button("Play Again", key="play_again"):
|
| 508 |
st.session_state.clear()
|
| 509 |
-
st.
|
| 510 |
|
| 511 |
if __name__ == "__main__":
|
| 512 |
main()
|
|
|
|
| 13 |
import hashlib
|
| 14 |
from audio_recorder_streamlit import audio_recorder
|
| 15 |
from transformers import pipeline
|
| 16 |
+
|
| 17 |
|
| 18 |
|
| 19 |
|
|
|
|
| 23 |
|
| 24 |
@st.cache_resource
|
| 25 |
def load_voice_model():
|
| 26 |
+
# Loading the Whisper model (which automatically detects both English and Urdu)
|
| 27 |
+
return pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 28 |
|
| 29 |
def process_audio(audio_bytes):
|
| 30 |
waveform, sample_rate = torchaudio.load(BytesIO(audio_bytes))
|
|
|
|
| 59 |
st.info(f"📝 Transcribed: {transcribed_text}")
|
| 60 |
# Append (or set) new transcription
|
| 61 |
st.session_state[state_key] += (" " + transcribed_text).strip()
|
| 62 |
+
st.experimental_rerun()
|
| 63 |
except Exception as e:
|
| 64 |
st.error(f"Voice input error: {str(e)}")
|
| 65 |
return st.session_state[state_key]
|
|
|
|
| 123 |
transition: width 0.5s ease; }
|
| 124 |
.question-count { color: #6C63FF; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem; }
|
| 125 |
|
| 126 |
+
body {
|
| 127 |
+
background: #000 !important;
|
| 128 |
+
color: #0f0 !important;
|
| 129 |
+
font-family: "Courier New" !important;
|
| 130 |
+
text-shadow: 0 0 5px lime;
|
| 131 |
+
}
|
| 132 |
/* Add these new styles for the info modal */
|
| 133 |
.info-modal {
|
| 134 |
position: fixed;
|
|
|
|
| 372 |
{"role": "assistant", "content": first_question}
|
| 373 |
]
|
| 374 |
st.session_state.game_state = "gameplay"
|
| 375 |
+
st.experimental_rerun()
|
| 376 |
|
| 377 |
# Gameplay screen with progress bar
|
| 378 |
elif st.session_state.game_state == "gameplay":
|
|
|
|
| 400 |
if "Final Guess:" in current_question:
|
| 401 |
st.session_state.final_guess = current_question.split("Final Guess:")[1].strip()
|
| 402 |
st.session_state.game_state = "confirm_guess"
|
| 403 |
+
st.experimental_rerun()
|
| 404 |
with st.form("answer_form"):
|
| 405 |
# --- Voice Input for Answer ---
|
| 406 |
st.markdown("#### Use Voice (English/Urdu) for Your Answer")
|
|
|
|
| 431 |
st.session_state.current_q += 1
|
| 432 |
if st.session_state.current_q >= 20:
|
| 433 |
st.session_state.game_state = "result"
|
| 434 |
+
st.experimental_rerun()
|
| 435 |
with st.expander("Need Help? Chat with AI Assistant"):
|
| 436 |
# --- Voice Input for Help Query ---
|
| 437 |
st.markdown("#### Use Voice (English/Urdu) for Help Query")
|
|
|
|
| 473 |
else:
|
| 474 |
if confirm_input == "yes":
|
| 475 |
st.session_state.game_state = "result"
|
| 476 |
+
st.experimental_rerun()
|
| 477 |
st.stop()
|
| 478 |
else:
|
| 479 |
st.session_state.conversation_history.append(
|
|
|
|
| 489 |
{"role": "assistant", "content": next_response}
|
| 490 |
)
|
| 491 |
st.session_state.current_q += 1
|
| 492 |
+
st.experimental_rerun()
|
| 493 |
|
| 494 |
elif st.session_state.game_state == "result":
|
| 495 |
if not st.session_state.final_guess:
|
|
|
|
| 512 |
unsafe_allow_html=True)
|
| 513 |
if st.button("Play Again", key="play_again"):
|
| 514 |
st.session_state.clear()
|
| 515 |
+
st.experimental_rerun()
|
| 516 |
|
| 517 |
if __name__ == "__main__":
|
| 518 |
main()
|