Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ def get_help_agent():
|
|
11 |
# Using BlenderBot 400M Distill as the public conversational model (used elsewhere)
|
12 |
return pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
13 |
|
14 |
-
# Custom CSS for professional look (fixed text color)
|
15 |
def inject_custom_css():
|
16 |
st.markdown("""
|
17 |
<style>
|
@@ -91,7 +91,41 @@ def inject_custom_css():
|
|
91 |
border-radius: 5px;
|
92 |
margin: 10px 0;
|
93 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
""", unsafe_allow_html=True)
|
96 |
|
97 |
# Confetti animation
|
@@ -222,12 +256,30 @@ def main():
|
|
222 |
<li><strong>Place</strong> - city, country, landmark, geographical location</li>
|
223 |
<li><strong>Object</strong> - everyday item, tool, vehicle, etc.</li>
|
224 |
</ul>
|
225 |
-
<p>Type your category below to begin:</p>
|
226 |
</div>
|
227 |
""", unsafe_allow_html=True)
|
228 |
|
229 |
with st.form("start_form"):
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
if st.form_submit_button("Start Game"):
|
232 |
if not category_input:
|
233 |
st.error("Please enter a category!")
|
@@ -260,8 +312,27 @@ def main():
|
|
260 |
unsafe_allow_html=True)
|
261 |
|
262 |
with st.form("answer_form"):
|
263 |
-
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
if st.form_submit_button("Submit"):
|
266 |
if answer_input not in ["yes", "no", "both"]:
|
267 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
@@ -315,7 +386,25 @@ def main():
|
|
315 |
unsafe_allow_html=True)
|
316 |
|
317 |
with st.form("confirm_form"):
|
318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
if st.form_submit_button("Submit"):
|
320 |
if confirm_input not in ["yes", "no", "both"]:
|
321 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
@@ -370,4 +459,4 @@ def main():
|
|
370 |
st.experimental_rerun()
|
371 |
|
372 |
if __name__ == "__main__":
|
373 |
-
main()
|
|
|
11 |
# Using BlenderBot 400M Distill as the public conversational model (used elsewhere)
|
12 |
return pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
13 |
|
14 |
+
# Custom CSS for professional look (fixed text color) with speech recognition
|
15 |
def inject_custom_css():
|
16 |
st.markdown("""
|
17 |
<style>
|
|
|
91 |
border-radius: 5px;
|
92 |
margin: 10px 0;
|
93 |
}
|
94 |
+
|
95 |
+
.mic-btn {
|
96 |
+
margin-top: 29px;
|
97 |
+
border: none;
|
98 |
+
background: none;
|
99 |
+
cursor: pointer;
|
100 |
+
font-size: 1.5em;
|
101 |
+
padding: 0;
|
102 |
+
}
|
103 |
</style>
|
104 |
+
<script>
|
105 |
+
function startSpeechRecognition(inputId) {
|
106 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
107 |
+
recognition.lang = 'en-US';
|
108 |
+
recognition.interimResults = false;
|
109 |
+
recognition.maxAlternatives = 1;
|
110 |
+
|
111 |
+
recognition.onresult = function(event) {
|
112 |
+
const transcript = event.results[0][0].transcript.toLowerCase();
|
113 |
+
const inputElement = document.getElementById(inputId);
|
114 |
+
if (inputElement) {
|
115 |
+
inputElement.value = transcript;
|
116 |
+
// Trigger Streamlit's input change detection
|
117 |
+
const event = new Event('input', { bubbles: true });
|
118 |
+
inputElement.dispatchEvent(event);
|
119 |
+
}
|
120 |
+
};
|
121 |
+
|
122 |
+
recognition.onerror = function(event) {
|
123 |
+
console.error('Speech recognition error', event.error);
|
124 |
+
};
|
125 |
+
|
126 |
+
recognition.start();
|
127 |
+
}
|
128 |
+
</script>
|
129 |
""", unsafe_allow_html=True)
|
130 |
|
131 |
# Confetti animation
|
|
|
256 |
<li><strong>Place</strong> - city, country, landmark, geographical location</li>
|
257 |
<li><strong>Object</strong> - everyday item, tool, vehicle, etc.</li>
|
258 |
</ul>
|
259 |
+
<p>Type or speak your category below to begin:</p>
|
260 |
</div>
|
261 |
""", unsafe_allow_html=True)
|
262 |
|
263 |
with st.form("start_form"):
|
264 |
+
# Create columns for input and microphone button
|
265 |
+
col1, col2 = st.columns([4, 1])
|
266 |
+
with col1:
|
267 |
+
category_input = st.text_input(
|
268 |
+
"Enter category (person/place/object):",
|
269 |
+
key="category_input"
|
270 |
+
).strip().lower()
|
271 |
+
|
272 |
+
with col2:
|
273 |
+
st.markdown(
|
274 |
+
"""
|
275 |
+
<button type="button" onclick="startSpeechRecognition('text_input-category_input')"
|
276 |
+
class="mic-btn">
|
277 |
+
🎤
|
278 |
+
</button>
|
279 |
+
""",
|
280 |
+
unsafe_allow_html=True
|
281 |
+
)
|
282 |
+
|
283 |
if st.form_submit_button("Start Game"):
|
284 |
if not category_input:
|
285 |
st.error("Please enter a category!")
|
|
|
312 |
unsafe_allow_html=True)
|
313 |
|
314 |
with st.form("answer_form"):
|
315 |
+
answer_key = f"answer_{st.session_state.current_q}"
|
316 |
+
|
317 |
+
# Create columns for input and microphone button
|
318 |
+
col1, col2 = st.columns([4, 1])
|
319 |
+
with col1:
|
320 |
+
answer_input = st.text_input(
|
321 |
+
"Your answer (yes/no/both) - speak or type:",
|
322 |
+
key=answer_key
|
323 |
+
).strip().lower()
|
324 |
+
|
325 |
+
with col2:
|
326 |
+
st.markdown(
|
327 |
+
f"""
|
328 |
+
<button type="button" onclick="startSpeechRecognition('text_input-{answer_key}')"
|
329 |
+
class="mic-btn">
|
330 |
+
🎤
|
331 |
+
</button>
|
332 |
+
""",
|
333 |
+
unsafe_allow_html=True
|
334 |
+
)
|
335 |
+
|
336 |
if st.form_submit_button("Submit"):
|
337 |
if answer_input not in ["yes", "no", "both"]:
|
338 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
|
|
386 |
unsafe_allow_html=True)
|
387 |
|
388 |
with st.form("confirm_form"):
|
389 |
+
# Create columns for input and microphone button
|
390 |
+
col1, col2 = st.columns([4, 1])
|
391 |
+
with col1:
|
392 |
+
confirm_input = st.text_input(
|
393 |
+
"Type or speak your answer (yes/no/both):",
|
394 |
+
key="confirm_input"
|
395 |
+
).strip().lower()
|
396 |
+
|
397 |
+
with col2:
|
398 |
+
st.markdown(
|
399 |
+
"""
|
400 |
+
<button type="button" onclick="startSpeechRecognition('text_input-confirm_input')"
|
401 |
+
class="mic-btn">
|
402 |
+
🎤
|
403 |
+
</button>
|
404 |
+
""",
|
405 |
+
unsafe_allow_html=True
|
406 |
+
)
|
407 |
+
|
408 |
if st.form_submit_button("Submit"):
|
409 |
if confirm_input not in ["yes", "no", "both"]:
|
410 |
st.error("Please answer with 'yes', 'no', or 'both'!")
|
|
|
459 |
st.experimental_rerun()
|
460 |
|
461 |
if __name__ == "__main__":
|
462 |
+
main()
|