DSatishchandra commited on
Commit
d75fa59
·
verified ·
1 Parent(s): 8025512

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +33 -93
templates/menu_page.html CHANGED
@@ -22,15 +22,7 @@
22
  box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1);
23
  text-align: center;
24
  width: 80%;
25
- max-width: 900px;
26
- }
27
- h1 {
28
- color: #333;
29
- font-size: 2.5rem;
30
- margin-bottom: 20px;
31
- }
32
- #mic-container {
33
- margin-top: 30px;
34
  }
35
  #mic-btn {
36
  font-size: 3rem;
@@ -49,55 +41,13 @@
49
  margin-top: 10px;
50
  color: #666;
51
  }
52
- .menu-items-container {
53
- display: grid;
54
- grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
55
- gap: 20px;
56
- margin-top: 20px;
57
- }
58
- .menu-item {
59
- background-color: #f9f9f9;
60
- padding: 20px;
61
- border-radius: 10px;
62
- box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
63
- text-align: left;
64
- }
65
- .menu-item h3 {
66
- font-size: 1.8rem;
67
- color: #333;
68
- margin-bottom: 10px;
69
- }
70
- .menu-item p {
71
- font-size: 1rem;
72
- color: #555;
73
- margin: 5px 0;
74
- }
75
- .order-btn {
76
- background-color: #28a745;
77
- color: white;
78
- padding: 10px 20px;
79
- border: none;
80
- border-radius: 5px;
81
- cursor: pointer;
82
- margin-top: 10px;
83
- }
84
- .order-btn:hover {
85
- background-color: #218838;
86
- }
87
  </style>
88
  </head>
89
  <body>
90
 
91
  <div class="container">
92
- <h1>Welcome to the Menu</h1>
93
- <div id="menu-items" class="menu-items-container">
94
- <!-- Menu items will be populated here dynamically -->
95
- </div>
96
-
97
- <div id="mic-container">
98
- <button id="mic-btn">🎤</button>
99
- <p id="mic-status">Press the mic button to start...</p>
100
- </div>
101
  </div>
102
 
103
  <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script>
@@ -105,27 +55,15 @@
105
  let menuItems = [];
106
  let selectedItem = "";
107
  let quantity = 0;
108
- let step = 0;
109
 
110
- const menuItemsContainer = document.getElementById('menu-items');
 
111
 
112
  // Fetch menu items from the backend (Flask)
113
  fetch('/menu') // Endpoint that returns the menu data as JSON
114
  .then(response => response.json())
115
  .then(data => {
116
- menuItems = data; // Store fetched data
117
- menuItems.forEach(item => {
118
- const menuItemDiv = document.createElement('div');
119
- menuItemDiv.classList.add('menu-item');
120
- menuItemDiv.innerHTML = `
121
- <h3>${item.name}</h3>
122
- <p><strong>Price:</strong> $${item.price}</p>
123
- <p><strong>Ingredients:</strong> ${item.ingredients}</p>
124
- <p><strong>Category:</strong> ${item.category}</p>
125
- <button class="order-btn" data-item="${item.name}">Order</button>
126
- `;
127
- menuItemsContainer.appendChild(menuItemDiv); // Add item to the container
128
- });
129
  })
130
  .catch(error => console.error('Error fetching menu items:', error));
131
 
@@ -135,39 +73,32 @@
135
 
136
  let commands = {};
137
 
138
- // Command to start the process
139
- commands['go to menu'] = function () {
140
- console.log("User said: Go to Menu");
141
- step = 1;
142
- document.getElementById("mic-status").innerText = "Please say 'Appetizer' or 'Main Course' to choose the category.";
 
 
 
143
  };
144
 
145
- // Command to choose a category
146
- menuItems.forEach(item => {
147
- commands[item.category.toLowerCase()] = function () {
148
- console.log("User chose category:", item.category);
149
- step = 2;
150
- document.getElementById("mic-status").innerText = `You chose ${item.category}. Please say the item you want to order, like 'Samosa' or 'Veg Biryani'.`;
151
- };
152
- });
153
-
154
- // Command to select an item
155
  menuItems.forEach(item => {
156
  commands[item.name.toLowerCase()] = function () {
157
- console.log("User selected item:", item.name);
158
  selectedItem = item.name;
159
- step = 3;
160
- document.getElementById("mic-status").innerText = `You chose ${selectedItem}. Please say the quantity (e.g., 'One', 'Two').`;
161
  };
162
  });
163
 
164
  // Command to set the quantity
165
  annyang.addCommands({
166
  'quantity *number': function (number) {
167
- console.log("User said quantity:", number); // Debugging
168
  quantity = parseInt(number);
169
- step = 4;
170
- document.getElementById("mic-status").innerText = `You want ${quantity} of ${selectedItem}. Please confirm your order.`;
171
  confirmOrder();
172
  }
173
  });
@@ -181,11 +112,18 @@
181
  }
182
 
183
  // Handle mic button click to start voice recognition
184
- document.getElementById("mic-btn").addEventListener("click", function () {
185
- document.getElementById("mic-status").innerText = "Listening...";
186
  annyang.start();
187
  });
188
 
 
 
 
 
 
 
 
189
  // Function to confirm the order and place it
190
  function confirmOrder() {
191
  let orderDetails = {
@@ -204,9 +142,11 @@
204
  .then(response => response.json())
205
  .then(data => {
206
  if (data.success) {
207
- document.getElementById("mic-status").innerText = "Order placed successfully!";
 
208
  } else {
209
- document.getElementById("mic-status").innerText = "Error placing order.";
 
210
  }
211
  });
212
  }
 
22
  box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1);
23
  text-align: center;
24
  width: 80%;
25
+ max-width: 600px;
 
 
 
 
 
 
 
 
26
  }
27
  #mic-btn {
28
  font-size: 3rem;
 
41
  margin-top: 10px;
42
  color: #666;
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  </style>
45
  </head>
46
  <body>
47
 
48
  <div class="container">
49
+ <button id="mic-btn">🎤</button>
50
+ <p id="mic-status">Press the mic button to start...</p>
 
 
 
 
 
 
 
51
  </div>
52
 
53
  <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script>
 
55
  let menuItems = [];
56
  let selectedItem = "";
57
  let quantity = 0;
 
58
 
59
+ const micBtn = document.getElementById("mic-btn");
60
+ const micStatus = document.getElementById("mic-status");
61
 
62
  // Fetch menu items from the backend (Flask)
63
  fetch('/menu') // Endpoint that returns the menu data as JSON
64
  .then(response => response.json())
65
  .then(data => {
66
+ menuItems = data; // Store fetched menu items in the array
 
 
 
 
 
 
 
 
 
 
 
 
67
  })
68
  .catch(error => console.error('Error fetching menu items:', error));
69
 
 
73
 
74
  let commands = {};
75
 
76
+ // Command to say menu items and order details
77
+ commands['what is the menu'] = function () {
78
+ micStatus.innerText = "I will tell you the menu.";
79
+ let menuSpeech = "Here are the menu items: ";
80
+ menuItems.forEach(item => {
81
+ menuSpeech += `${item.name}, Price: $${item.price}, Ingredients: ${item.ingredients}, Category: ${item.category}. `;
82
+ });
83
+ speak(menuSpeech);
84
  };
85
 
86
+ // Command to choose an item
 
 
 
 
 
 
 
 
 
87
  menuItems.forEach(item => {
88
  commands[item.name.toLowerCase()] = function () {
 
89
  selectedItem = item.name;
90
+ micStatus.innerText = `You chose ${selectedItem}. Please say the quantity.`;
91
+ speak(`You chose ${selectedItem}. Please say the quantity.`);
92
  };
93
  });
94
 
95
  // Command to set the quantity
96
  annyang.addCommands({
97
  'quantity *number': function (number) {
98
+ console.log("User said quantity:", number);
99
  quantity = parseInt(number);
100
+ micStatus.innerText = `You want ${quantity} of ${selectedItem}. Please confirm your order.`;
101
+ speak(`You want ${quantity} of ${selectedItem}. Please confirm your order.`);
102
  confirmOrder();
103
  }
104
  });
 
112
  }
113
 
114
  // Handle mic button click to start voice recognition
115
+ micBtn.addEventListener("click", function () {
116
+ micStatus.innerText = "Listening...";
117
  annyang.start();
118
  });
119
 
120
+ // Function to speak the text
121
+ function speak(text) {
122
+ const msg = new SpeechSynthesisUtterance(text);
123
+ msg.rate = 1; // Speed of speech
124
+ window.speechSynthesis.speak(msg);
125
+ }
126
+
127
  // Function to confirm the order and place it
128
  function confirmOrder() {
129
  let orderDetails = {
 
142
  .then(response => response.json())
143
  .then(data => {
144
  if (data.success) {
145
+ micStatus.innerText = "Order placed successfully!";
146
+ speak("Order placed successfully!");
147
  } else {
148
+ micStatus.innerText = "Error placing order.";
149
+ speak("Error placing order.");
150
  }
151
  });
152
  }