Aranwer commited on
Commit
07d1fd0
·
verified ·
1 Parent(s): 22bb3d6

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +16 -1
src/streamlit_app.py CHANGED
@@ -5,6 +5,7 @@ import scipy.io.wavfile
5
  import os
6
  import requests
7
  import numpy as np
 
8
 
9
  # Set API Keys
10
  os.environ["MISTRAL_API_KEY"] = "cNjUx79Hl0A2AeiAMf6yi7o7ah4APoZy"
@@ -94,7 +95,6 @@ def handle_answer(user_input):
94
  st.warning("Please answer 'yes' or 'no' (or ہاں / نہیں).")
95
  return
96
 
97
- # Handle guess confirmation
98
  if gs["current_question"] and "is this correct?" in gs["current_question"].lower():
99
  if norm_ans == "yes":
100
  st.success("🎉 YAY! I guessed it!")
@@ -134,11 +134,25 @@ if st.button("Start Game"):
134
  start_game()
135
 
136
  language = st.selectbox("Select Language for Audio Input", ["English", "Urdu"])
 
 
137
  audio_input = st.file_uploader("🎤 Upload your Answer (WAV format)", type=["wav"])
138
  if audio_input:
139
  transcribed = transcribe_audio(audio_input.read(), language)
140
  st.text_area("Transcribed Answer", value=transcribed, key="text_input")
141
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  manual_input = st.text_input("Or type your answer here (yes/no/ہاں/نہیں):")
143
 
144
  if st.button("Submit Answer"):
@@ -148,6 +162,7 @@ if st.button("Submit Answer"):
148
  else:
149
  handle_answer(answer_text)
150
 
 
151
  if st.checkbox("Enable Consult Mode"):
152
  st.session_state.game_state["consult_mode"] = True
153
  if st.button("🔍 Get Hint"):
 
5
  import os
6
  import requests
7
  import numpy as np
8
+ from streamlit_audio_recorder import st_audiorec # Make sure this is in requirements.txt
9
 
10
  # Set API Keys
11
  os.environ["MISTRAL_API_KEY"] = "cNjUx79Hl0A2AeiAMf6yi7o7ah4APoZy"
 
95
  st.warning("Please answer 'yes' or 'no' (or ہاں / نہیں).")
96
  return
97
 
 
98
  if gs["current_question"] and "is this correct?" in gs["current_question"].lower():
99
  if norm_ans == "yes":
100
  st.success("🎉 YAY! I guessed it!")
 
134
  start_game()
135
 
136
  language = st.selectbox("Select Language for Audio Input", ["English", "Urdu"])
137
+
138
+ # Uploaded Audio File
139
  audio_input = st.file_uploader("🎤 Upload your Answer (WAV format)", type=["wav"])
140
  if audio_input:
141
  transcribed = transcribe_audio(audio_input.read(), language)
142
  st.text_area("Transcribed Answer", value=transcribed, key="text_input")
143
 
144
+ # Audio Recorder UI
145
+ st.markdown("### 🎙️ Or Record Your Answer")
146
+ audio_bytes = st_audiorec()
147
+
148
+ if audio_bytes is not None:
149
+ st.success("✅ Recording complete!")
150
+ if st.button("Transcribe Recorded Audio"):
151
+ transcribed = transcribe_audio(audio_bytes, language)
152
+ st.session_state.text_input = transcribed # Store for answer processing
153
+ st.text_area("Transcribed Answer", value=transcribed, key="text_input")
154
+
155
+ # Manual Input
156
  manual_input = st.text_input("Or type your answer here (yes/no/ہاں/نہیں):")
157
 
158
  if st.button("Submit Answer"):
 
162
  else:
163
  handle_answer(answer_text)
164
 
165
+ # Hint mode
166
  if st.checkbox("Enable Consult Mode"):
167
  st.session_state.game_state["consult_mode"] = True
168
  if st.button("🔍 Get Hint"):