lokesh341 commited on
Commit
c065c92
·
verified ·
1 Parent(s): 24a1541

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +123 -21
templates/menu_page.html CHANGED
@@ -3,16 +3,14 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Menu - Biryani Hub</title>
7
  <style>
8
- /* General Body Styling */
9
  body {
10
  font-family: Arial, sans-serif;
11
  background-color: #f8f8f8;
12
  margin: 0;
13
  padding: 0;
14
  }
15
- /* Container for the menu */
16
  .menu-container {
17
  max-width: 1200px;
18
  margin: 0 auto;
@@ -67,54 +65,158 @@
67
  <div class="menu-container">
68
  <h1>Welcome to the Menu</h1>
69
 
70
- {% for item in menu_items %}
71
- <div class="menu-item">
72
- <div class="details">
73
- <h3>{{ item.name }}</h3>
74
- <p><strong>Ingredients:</strong> {{ item.ingredients }}</p>
75
- <p><strong>Category:</strong> {{ item.category }}</p>
76
- <p class="price">Price: ${{ item.price }}</p>
77
- </div>
78
- <button class="order-btn">Order</button>
79
  </div>
80
- {% endfor %}
81
 
82
- <!-- Button for triggering voice recognition -->
83
  <button id="listen-btn">Say "Order" to order an item</button>
 
 
 
 
 
84
  </div>
85
 
86
  <script>
87
  const listenButton = document.getElementById("listen-btn");
 
 
 
 
 
88
  const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
89
  recognition.lang = "en-US";
90
  recognition.interimResults = false;
 
 
91
  function speak(text) {
92
  const msg = new SpeechSynthesisUtterance(text);
93
  window.speechSynthesis.speak(msg);
94
  }
 
95
  listenButton.addEventListener("click", () => {
96
- speak("Please say the item you want to order.");
97
- recognition.start();
 
 
 
98
  });
 
99
  recognition.onresult = (event) => {
100
  const command = event.results[0][0].transcript.toLowerCase();
101
  console.log("User said:", command);
102
  // Add logic to recognize specific items or trigger actions based on the command
103
  if (command.includes("order")) {
104
- // For example, navigate or process an order (customize as needed)
105
- speak("Your order has been placed.");
 
 
 
 
106
  }
107
  };
 
108
  recognition.onerror = (event) => {
109
  console.error("Speech recognition error:", event.error);
110
  speak("Sorry, I couldn't understand that. Please try again.");
111
  };
112
- // Voice reading of menu items on page load
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  window.onload = function() {
114
- const menuItems = document.querySelectorAll('.menu-item h3');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  let itemsText = "The menu includes: ";
116
  menuItems.forEach(item => {
117
- itemsText += item.textContent + ", ";
118
  });
119
  speak(itemsText); // Speak all the item names
120
  }
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Biryani Hub Menu</title>
7
  <style>
 
8
  body {
9
  font-family: Arial, sans-serif;
10
  background-color: #f8f8f8;
11
  margin: 0;
12
  padding: 0;
13
  }
 
14
  .menu-container {
15
  max-width: 1200px;
16
  margin: 0 auto;
 
65
  <div class="menu-container">
66
  <h1>Welcome to the Menu</h1>
67
 
68
+ <!-- Dynamic Menu Item List -->
69
+ <div id="menu-items">
70
+ <!-- Menu items will be populated here from the backend -->
 
 
 
 
 
 
71
  </div>
 
72
 
 
73
  <button id="listen-btn">Say "Order" to order an item</button>
74
+ <div id="cart-summary" style="display:none;">
75
+ <h2>Your Cart:</h2>
76
+ <div id="cart-details"></div>
77
+ <button id="place-order-btn">Place Final Order</button>
78
+ </div>
79
  </div>
80
 
81
  <script>
82
  const listenButton = document.getElementById("listen-btn");
83
+ const placeOrderButton = document.getElementById("place-order-btn");
84
+ const cartSummary = document.getElementById("cart-summary");
85
+ const cartDetails = document.getElementById("cart-details");
86
+ let isListening = false;
87
+ let cart = []; // Global cart variable to store items
88
  const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
89
  recognition.lang = "en-US";
90
  recognition.interimResults = false;
91
+
92
+ // Function to speak text
93
  function speak(text) {
94
  const msg = new SpeechSynthesisUtterance(text);
95
  window.speechSynthesis.speak(msg);
96
  }
97
+
98
  listenButton.addEventListener("click", () => {
99
+ if (!isListening) {
100
+ isListening = true;
101
+ speak("Please say the item you want to order.");
102
+ recognition.start();
103
+ }
104
  });
105
+
106
  recognition.onresult = (event) => {
107
  const command = event.results[0][0].transcript.toLowerCase();
108
  console.log("User said:", command);
109
  // Add logic to recognize specific items or trigger actions based on the command
110
  if (command.includes("order")) {
111
+ // Process ordering logic here (e.g., find item in menu and add to cart)
112
+ processOrder();
113
+ } else if (command.includes("cart details")) {
114
+ showCartDetails();
115
+ } else {
116
+ speak("Sorry, I couldn't understand that. Please try again.");
117
  }
118
  };
119
+
120
  recognition.onerror = (event) => {
121
  console.error("Speech recognition error:", event.error);
122
  speak("Sorry, I couldn't understand that. Please try again.");
123
  };
124
+
125
+ // Function to process order
126
+ function processOrder() {
127
+ speak("Which item would you like to order?");
128
+ recognition.start();
129
+ recognition.onresult = (event) => {
130
+ const itemName = event.results[0][0].transcript.toLowerCase();
131
+ const item = findItem(itemName);
132
+ if (item) {
133
+ speak(`You selected ${item.name}. How many would you like?`);
134
+ recognition.start();
135
+ recognition.onresult = (event) => {
136
+ const quantity = parseInt(event.results[0][0].transcript);
137
+ if (quantity) {
138
+ addToCart(item, quantity);
139
+ speak(`${quantity} ${item.name} added to your cart.`);
140
+ askMoreItems();
141
+ } else {
142
+ speak("Please say a valid quantity.");
143
+ }
144
+ };
145
+ } else {
146
+ speak("Sorry, I couldn't find that item. Please try again.");
147
+ }
148
+ };
149
+ }
150
+
151
+ // Function to ask if the user wants to order more items
152
+ function askMoreItems() {
153
+ speak("Would you like to order more items?");
154
+ recognition.start();
155
+ recognition.onresult = (event) => {
156
+ const response = event.results[0][0].transcript.toLowerCase();
157
+ if (response.includes("yes")) {
158
+ processOrder();
159
+ } else {
160
+ showCartDetails();
161
+ }
162
+ };
163
+ }
164
+
165
+ // Function to show cart details
166
+ function showCartDetails() {
167
+ if (cart.length > 0) {
168
+ let cartHtml = "";
169
+ cart.forEach(item => {
170
+ cartHtml += `<p>${item.quantity} x ${item.name} - ₹${item.price * item.quantity}</p>`;
171
+ });
172
+ cartDetails.innerHTML = cartHtml;
173
+ cartSummary.style.display = "block";
174
+ speak(`Your cart contains ${cart.length} items.`);
175
+ } else {
176
+ speak("Your cart is empty.");
177
+ }
178
+ }
179
+
180
+ // Function to add an item to the cart
181
+ function addToCart(item, quantity) {
182
+ cart.push({ name: item.name, price: item.price, quantity: quantity });
183
+ }
184
+
185
+ // Function to find item in the menu
186
+ function findItem(itemName) {
187
+ const menu = [
188
+ { name: "Chicken Biryani", price: 250 },
189
+ { name: "Veg Biryani", price: 200 },
190
+ { name: "Mutton Biryani", price: 300 }
191
+ ];
192
+ return menu.find(item => item.name.toLowerCase() === itemName.toLowerCase());
193
+ }
194
+
195
+ // Function to populate the menu dynamically and speak it on load
196
  window.onload = function() {
197
+ const menuItems = [
198
+ { name: "Chicken Biryani", price: 250 },
199
+ { name: "Veg Biryani", price: 200 },
200
+ { name: "Mutton Biryani", price: 300 }
201
+ ];
202
+ let menuContent = "";
203
+ menuItems.forEach(item => {
204
+ menuContent += `
205
+ <div class="menu-item">
206
+ <div class="details">
207
+ <h3>${item.name}</h3>
208
+ <p class="price">Price: ₹${item.price}</p>
209
+ </div>
210
+ <button class="order-btn" onclick="addToCart(${item.name}, 1)">Order</button>
211
+ </div>
212
+ `;
213
+ });
214
+ document.getElementById('menu-items').innerHTML = menuContent;
215
+
216
+ // Voice reading of menu items
217
  let itemsText = "The menu includes: ";
218
  menuItems.forEach(item => {
219
+ itemsText += item.name + ", ";
220
  });
221
  speak(itemsText); // Speak all the item names
222
  }