Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -444,53 +444,37 @@ def app():
|
|
| 444 |
back_to_menu_button.click(
|
| 445 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 446 |
outputs=[menu_section, cart_section],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
)
|
| 448 |
-
def main_app():
|
| 449 |
-
return "Welcome to the menu ordering system. Interact with items to hear details."
|
| 450 |
-
|
| 451 |
-
# Add custom HTML and JavaScript for voice accessibility
|
| 452 |
-
custom_html = """
|
| 453 |
-
<script>
|
| 454 |
-
// Function to speak text
|
| 455 |
-
function speak(text) {
|
| 456 |
-
const speech = new SpeechSynthesisUtterance(text);
|
| 457 |
-
speech.lang = 'en-US'; // Set language
|
| 458 |
-
speech.pitch = 1.0; // Adjust pitch (optional)
|
| 459 |
-
speech.rate = 1.0; // Adjust rate (optional)
|
| 460 |
-
window.speechSynthesis.speak(speech);
|
| 461 |
-
}
|
| 462 |
-
|
| 463 |
-
// Event listeners for hover and click
|
| 464 |
-
document.addEventListener('DOMContentLoaded', (event) => {
|
| 465 |
-
// Add hoverable elements
|
| 466 |
-
document.querySelectorAll('.hoverable').forEach((element) => {
|
| 467 |
-
element.addEventListener('mouseenter', () => {
|
| 468 |
-
const text = element.getAttribute('aria-label') || element.innerText;
|
| 469 |
-
speak(`This is ${text}`);
|
| 470 |
-
});
|
| 471 |
-
});
|
| 472 |
-
|
| 473 |
-
// Add clickable elements
|
| 474 |
-
document.querySelectorAll('.clickable').forEach((element) => {
|
| 475 |
-
element.addEventListener('click', () => {
|
| 476 |
-
const text = element.getAttribute('aria-label') || element.innerText;
|
| 477 |
-
speak(`You clicked on ${text}`);
|
| 478 |
-
});
|
| 479 |
-
});
|
| 480 |
-
});
|
| 481 |
-
</script>
|
| 482 |
-
"""
|
| 483 |
-
|
| 484 |
-
# Define the Gradio Interface
|
| 485 |
-
demo = gr.Interface(
|
| 486 |
-
fn=main_app, # Your main app function
|
| 487 |
-
inputs=[], # Define your inputs
|
| 488 |
-
outputs="html", # Define your outputs
|
| 489 |
-
live=True # Enable live updates
|
| 490 |
-
)
|
| 491 |
-
|
| 492 |
-
# Add the custom JavaScript to the app
|
| 493 |
-
demo.custom_html = custom_html
|
| 494 |
|
| 495 |
return demo
|
| 496 |
|
|
|
|
| 444 |
back_to_menu_button.click(
|
| 445 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 446 |
outputs=[menu_section, cart_section],
|
| 447 |
+
# Inject Voice Accessibility JavaScript
|
| 448 |
+
demo.load(
|
| 449 |
+
lambda: None, # This is just to render the custom HTML
|
| 450 |
+
inputs=None,
|
| 451 |
+
outputs=None,
|
| 452 |
+
_js="""
|
| 453 |
+
<script>
|
| 454 |
+
function speak(text) {
|
| 455 |
+
const speech = new SpeechSynthesisUtterance(text);
|
| 456 |
+
speech.lang = 'en-US';
|
| 457 |
+
window.speechSynthesis.speak(speech);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 461 |
+
document.querySelectorAll('.hoverable').forEach(element => {
|
| 462 |
+
element.addEventListener('mouseenter', () => {
|
| 463 |
+
const text = element.getAttribute('aria-label') || element.innerText;
|
| 464 |
+
speak(`This is ${text}`);
|
| 465 |
+
});
|
| 466 |
+
});
|
| 467 |
+
|
| 468 |
+
document.querySelectorAll('.clickable').forEach(element => {
|
| 469 |
+
element.addEventListener('click', () => {
|
| 470 |
+
const text = element.getAttribute('aria-label') || element.innerText;
|
| 471 |
+
speak(`You clicked on ${text}`);
|
| 472 |
+
});
|
| 473 |
+
});
|
| 474 |
+
});
|
| 475 |
+
</script>
|
| 476 |
+
"""
|
| 477 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
return demo
|
| 480 |
|