Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +80 -102
templates/menu_page.html
CHANGED
|
@@ -3,126 +3,104 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Menu
|
| 7 |
-
<style>
|
| 8 |
-
|
| 9 |
-
body {
|
| 10 |
-
font-family: Arial, sans-serif;
|
| 11 |
-
background-color: #f8f8f8;
|
| 12 |
-
margin: 0;
|
| 13 |
-
padding: 0;
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
/* Container for the menu */
|
| 17 |
-
.menu-container {
|
| 18 |
-
max-width: 1200px;
|
| 19 |
-
margin: 0 auto;
|
| 20 |
-
padding: 20px;
|
| 21 |
-
background-color: #fff;
|
| 22 |
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
| 23 |
-
border-radius: 8px;
|
| 24 |
-
margin-top: 50px;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
h1 {
|
| 28 |
-
text-align: center;
|
| 29 |
-
font-size: 2.5rem;
|
| 30 |
-
color: #333;
|
| 31 |
-
margin-bottom: 30px;
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
.menu-item {
|
| 35 |
-
border-bottom: 1px solid #eee;
|
| 36 |
-
padding: 15px 0;
|
| 37 |
-
display: flex;
|
| 38 |
-
justify-content: space-between;
|
| 39 |
-
align-items: center;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
.order-btn {
|
| 43 |
-
padding: 10px 20px;
|
| 44 |
-
background-color: #4CAF50;
|
| 45 |
-
color: white;
|
| 46 |
-
border: none;
|
| 47 |
-
border-radius: 5px;
|
| 48 |
-
cursor: pointer;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
.order-btn:hover {
|
| 52 |
-
background-color: #45a049;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
#listen-btn {
|
| 56 |
-
padding: 10px 20px;
|
| 57 |
-
background-color: #4CAF50;
|
| 58 |
-
color: white;
|
| 59 |
-
border: none;
|
| 60 |
-
border-radius: 5px;
|
| 61 |
-
cursor: pointer;
|
| 62 |
-
font-size: 1.2rem;
|
| 63 |
-
display: block;
|
| 64 |
-
margin: 30px auto;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
#listen-btn:hover {
|
| 68 |
-
background-color: #45a049;
|
| 69 |
-
}
|
| 70 |
-
</style>
|
| 71 |
</head>
|
| 72 |
<body>
|
| 73 |
-
|
| 74 |
-
<div class="menu-container">
|
| 75 |
<h1>Welcome to the Menu</h1>
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
<div class="details">
|
| 80 |
<h3>{{ item.name }}</h3>
|
| 81 |
-
<p
|
| 82 |
-
<p
|
| 83 |
-
<p
|
|
|
|
| 84 |
</div>
|
| 85 |
-
|
| 86 |
</div>
|
| 87 |
-
{% endfor %}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script>
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
}
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 108 |
});
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
</script>
|
| 126 |
-
|
| 127 |
</body>
|
| 128 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Menu Page</title>
|
| 7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script> <!-- for voice commands -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
+
<div class="container">
|
|
|
|
| 12 |
<h1>Welcome to the Menu</h1>
|
| 13 |
+
<div id="menu-items">
|
| 14 |
+
{% for item in menu_items %}
|
| 15 |
+
<div class="menu-item">
|
|
|
|
| 16 |
<h3>{{ item.name }}</h3>
|
| 17 |
+
<p>Price: ${{ item.price }}</p>
|
| 18 |
+
<p>Ingredients: {{ item.ingredients }}</p>
|
| 19 |
+
<p>Category: {{ item.category }}</p>
|
| 20 |
+
<button class="order-btn" data-item="{{ item.name }}">Order</button>
|
| 21 |
</div>
|
| 22 |
+
{% endfor %}
|
| 23 |
</div>
|
|
|
|
| 24 |
|
| 25 |
+
<div id="mic-container">
|
| 26 |
+
<button id="mic-btn">🎤</button>
|
| 27 |
+
<p id="mic-status">Press the mic button to start...</p>
|
| 28 |
+
</div>
|
| 29 |
</div>
|
| 30 |
|
| 31 |
<script>
|
| 32 |
+
let menuItems = [];
|
| 33 |
+
let selectedItem = "";
|
| 34 |
+
let quantity = 0;
|
| 35 |
|
| 36 |
+
// Fetch menu items from the backend
|
| 37 |
+
{% for item in menu_items %}
|
| 38 |
+
menuItems.push("{{ item.name }}");
|
| 39 |
+
{% endfor %}
|
| 40 |
|
| 41 |
+
// Setup voice interaction
|
| 42 |
+
if (annyang) {
|
| 43 |
+
// Add a voice command to handle menu items ordering
|
| 44 |
+
var commands = {};
|
| 45 |
+
menuItems.forEach(item => {
|
| 46 |
+
commands[item.toLowerCase()] = function() {
|
| 47 |
+
selectedItem = item;
|
| 48 |
+
document.getElementById("mic-status").innerText = "You chose " + item + ". Please say the quantity.";
|
| 49 |
+
};
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// Start voice recognition
|
| 53 |
+
annyang.addCommands(commands);
|
| 54 |
+
annyang.start();
|
| 55 |
}
|
| 56 |
|
| 57 |
+
// Handle mic button click to start voice recognition
|
| 58 |
+
document.getElementById("mic-btn").addEventListener("click", function() {
|
| 59 |
+
document.getElementById("mic-status").innerText = "Listening...";
|
| 60 |
+
annyang.start();
|
| 61 |
});
|
| 62 |
|
| 63 |
+
// Handle order button click
|
| 64 |
+
document.querySelectorAll('.order-btn').forEach(button => {
|
| 65 |
+
button.addEventListener('click', function() {
|
| 66 |
+
selectedItem = button.getAttribute('data-item');
|
| 67 |
+
document.getElementById("mic-status").innerText = `You chose ${selectedItem}. Please say the quantity.`;
|
| 68 |
+
});
|
| 69 |
+
});
|
| 70 |
|
| 71 |
+
// Wait for quantity confirmation via voice and then submit
|
| 72 |
+
function placeOrder() {
|
| 73 |
+
let orderDetails = {
|
| 74 |
+
item: selectedItem,
|
| 75 |
+
quantity: quantity
|
| 76 |
+
};
|
| 77 |
+
fetch('/order', {
|
| 78 |
+
method: 'POST',
|
| 79 |
+
headers: {
|
| 80 |
+
'Content-Type': 'application/json',
|
| 81 |
+
},
|
| 82 |
+
body: JSON.stringify(orderDetails),
|
| 83 |
+
})
|
| 84 |
+
.then(response => response.json())
|
| 85 |
+
.then(data => {
|
| 86 |
+
if (data.success) {
|
| 87 |
+
document.getElementById("mic-status").innerText = "Order placed successfully!";
|
| 88 |
+
} else {
|
| 89 |
+
document.getElementById("mic-status").innerText = "Error placing order.";
|
| 90 |
+
}
|
| 91 |
+
});
|
| 92 |
+
}
|
| 93 |
|
| 94 |
+
// Listen for quantity after food item selection
|
| 95 |
+
if (annyang) {
|
| 96 |
+
annyang.addCommands({
|
| 97 |
+
'quantity *number': function(number) {
|
| 98 |
+
quantity = parseInt(number);
|
| 99 |
+
document.getElementById("mic-status").innerText = `You want ${quantity} of ${selectedItem}. Please confirm your order.`;
|
| 100 |
+
placeOrder();
|
| 101 |
+
}
|
| 102 |
+
});
|
| 103 |
+
}
|
| 104 |
</script>
|
|
|
|
| 105 |
</body>
|
| 106 |
</html>
|