Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Menu Page</title> | |
| <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script> <!-- for voice commands --> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>Welcome to the Menu</h1> | |
| <div id="menu-items"> | |
| {% for item in menu_items %} | |
| <div class="menu-item"> | |
| <h3>{{ item.name }}</h3> | |
| <p>Price: ${{ item.price }}</p> | |
| <p>Ingredients: {{ item.ingredients }}</p> | |
| <p>Category: {{ item.category }}</p> | |
| <button class="order-btn" data-item="{{ item.name }}">Order</button> | |
| </div> | |
| {% endfor %} | |
| </div> | |
| <div id="mic-container"> | |
| <button id="mic-btn">🎤</button> | |
| <p id="mic-status">Press the mic button to start...</p> | |
| </div> | |
| </div> | |
| <script> | |
| let menuItems = []; | |
| let selectedItem = ""; | |
| let quantity = 0; | |
| // Fetch menu items from the backend | |
| {% for item in menu_items %} | |
| menuItems.push("{{ item.name }}"); | |
| {% endfor %} | |
| // Setup voice interaction | |
| if (annyang) { | |
| // Add a voice command to handle menu items ordering | |
| var commands = {}; | |
| menuItems.forEach(item => { | |
| commands[item.toLowerCase()] = function() { | |
| selectedItem = item; | |
| document.getElementById("mic-status").innerText = "You chose " + item + ". Please say the quantity."; | |
| }; | |
| }); | |
| // Start voice recognition | |
| annyang.addCommands(commands); | |
| annyang.start(); | |
| } | |
| // Handle mic button click to start voice recognition | |
| document.getElementById("mic-btn").addEventListener("click", function() { | |
| document.getElementById("mic-status").innerText = "Listening..."; | |
| annyang.start(); | |
| }); | |
| // Handle order button click | |
| document.querySelectorAll('.order-btn').forEach(button => { | |
| button.addEventListener('click', function() { | |
| selectedItem = button.getAttribute('data-item'); | |
| document.getElementById("mic-status").innerText = `You chose ${selectedItem}. Please say the quantity.`; | |
| }); | |
| }); | |
| // Wait for quantity confirmation via voice and then submit | |
| function placeOrder() { | |
| let orderDetails = { | |
| item: selectedItem, | |
| quantity: quantity | |
| }; | |
| fetch('/order', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify(orderDetails), | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.success) { | |
| document.getElementById("mic-status").innerText = "Order placed successfully!"; | |
| } else { | |
| document.getElementById("mic-status").innerText = "Error placing order."; | |
| } | |
| }); | |
| } | |
| // Listen for quantity after food item selection | |
| if (annyang) { | |
| annyang.addCommands({ | |
| 'quantity *number': function(number) { | |
| quantity = parseInt(number); | |
| document.getElementById("mic-status").innerText = `You want ${quantity} of ${selectedItem}. Please confirm your order.`; | |
| placeOrder(); | |
| } | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> | |