DSatishchandra commited on
Commit
95ee9b6
·
verified ·
1 Parent(s): 62b7c73

Update templates/menu_page.html

Browse files
Files changed (1) hide show
  1. templates/menu_page.html +79 -146
templates/menu_page.html CHANGED
@@ -7,185 +7,118 @@
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
- background-color: #fafafa;
 
11
  margin: 0;
12
  padding: 0;
 
13
  display: flex;
14
  justify-content: center;
15
  align-items: center;
16
- height: 100vh;
17
  }
18
  .container {
19
- background-color: white;
20
- padding: 30px;
21
- border-radius: 10px;
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;
 
 
 
 
 
 
 
29
  background-color: #007bff;
30
  color: white;
 
31
  border: none;
32
- padding: 20px;
33
- border-radius: 50%;
34
  cursor: pointer;
35
  }
36
- #mic-btn:hover {
37
- background-color: #0056b3;
38
- }
39
- #mic-status {
40
  font-size: 1.2rem;
41
- margin-top: 10px;
42
- color: #666;
43
  }
44
- .menu-items-container {
45
- display: grid;
46
- grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
47
- gap: 20px;
48
  margin-top: 20px;
49
- }
50
- .menu-item {
51
- background-color: #f9f9f9;
52
- padding: 20px;
53
- border-radius: 10px;
54
- box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
55
- text-align: left;
56
- }
57
- .menu-item h3 {
58
- font-size: 1.5rem;
59
  color: #333;
60
- margin-bottom: 10px;
61
- }
62
- .menu-item p {
63
- font-size: 1rem;
64
- color: #555;
65
- margin: 5px 0;
66
- }
67
- .order-btn {
68
- background-color: #28a745;
69
- color: white;
70
- padding: 10px 20px;
71
- border: none;
72
- border-radius: 5px;
73
- cursor: pointer;
74
- margin-top: 10px;
75
- }
76
- .order-btn:hover {
77
- background-color: #218838;
78
  }
79
  </style>
80
  </head>
81
  <body>
82
 
83
  <div class="container">
84
- <button id="mic-btn">🎤</button>
85
- <p id="mic-status">Press the mic button to start...</p>
86
-
87
- <div id="menu-items" class="menu-items-container">
88
- <!-- Menu items will be populated here dynamically -->
89
- </div>
90
  </div>
91
 
92
- <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script>
93
  <script>
94
- let menuItems = [];
95
- let selectedItem = "";
96
- let quantity = 0;
97
- const micBtn = document.getElementById("mic-btn");
98
- const micStatus = document.getElementById("mic-status");
99
- const menuItemsContainer = document.getElementById('menu-items');
100
-
101
- // Fetch menu items from the backend (Flask)
102
- fetch('/menu')
103
- .then(response => response.json())
104
- .then(data => {
105
- menuItems = data;
106
- renderMenuItems(menuItems);
107
- })
108
- .catch(error => console.error('Error fetching menu items:', error));
109
 
110
- // Render menu items dynamically
111
- function renderMenuItems(items) {
112
- menuItemsContainer.innerHTML = "";
113
- items.forEach(item => {
114
- const menuItemDiv = document.createElement('div');
115
- menuItemDiv.classList.add('menu-item');
116
- menuItemDiv.innerHTML = `
117
- <h3>${item.name}</h3>
118
- <p><strong>Price:</strong> $${item.price}</p>
119
- <p><strong>Ingredients:</strong> ${item.ingredients}</p>
120
- <p><strong>Category:</strong> ${item.category}</p>
121
- <button class="order-btn" data-item="${item.name}">Order</button>
122
- `;
123
- menuItemsContainer.appendChild(menuItemDiv);
124
- });
125
- }
126
-
127
- // Initialize annyang for voice commands
128
- if (annyang) {
129
- console.log("annyang initialized");
130
- let commands = {};
131
- commands['what is the menu'] = function () {
132
- micStatus.innerText = "I will tell you the menu.";
133
- let menuSpeech = "Here are the menu items: ";
134
- menuItems.forEach(item => {
135
- menuSpeech += `${item.name}, Price: $${item.price}, Ingredients: ${item.ingredients}, Category: ${item.category}. `;
136
- });
137
- speak(menuSpeech);
138
- };
139
-
140
- menuItems.forEach(item => {
141
- commands[item.name.toLowerCase()] = function () {
142
- selectedItem = item.name;
143
- micStatus.innerText = `You chose ${selectedItem}. Please say the quantity.`;
144
- speak(`You chose ${selectedItem}. Please say the quantity.`);
145
- };
146
- });
147
-
148
- annyang.addCommands(commands);
149
- annyang.start();
150
- } else {
151
- console.log("annyang is not supported on this browser.");
152
- alert("Sorry, your browser does not support speech recognition.");
153
- }
154
-
155
- micBtn.addEventListener("click", function () {
156
- micStatus.innerText = "Listening...";
157
- annyang.start();
158
  });
159
 
160
- function speak(text) {
161
- const msg = new SpeechSynthesisUtterance(text);
162
- msg.rate = 1;
163
- window.speechSynthesis.speak(msg);
 
 
 
 
164
  }
165
 
166
- // Function to confirm the order and place it
167
- function confirmOrder() {
168
- let orderDetails = {
169
- item: selectedItem,
170
- quantity: quantity
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  };
172
- fetch('/order', {
173
- method: 'POST',
174
- headers: {
175
- 'Content-Type': 'application/json',
176
- },
177
- body: JSON.stringify(orderDetails),
178
- })
179
- .then(response => response.json())
180
- .then(data => {
181
- if (data.success) {
182
- micStatus.innerText = "Order placed successfully!";
183
- speak("Order placed successfully!");
184
- } else {
185
- micStatus.innerText = "Error placing order.";
186
- speak("Error placing order.");
187
- }
188
- });
189
  }
190
  </script>
191
 
 
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
+ text-align: center;
11
+ background-color: #f4f4f9;
12
  margin: 0;
13
  padding: 0;
14
+ height: 100vh;
15
  display: flex;
16
  justify-content: center;
17
  align-items: center;
 
18
  }
19
  .container {
 
 
 
 
20
  text-align: center;
21
+ background-color: #fff;
22
+ border-radius: 10px;
23
+ padding: 40px;
24
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
25
+ width: 90%;
26
+ max-width: 500px;
27
  }
28
+ h1 {
29
+ color: #333;
30
+ font-size: 2rem;
31
+ margin-bottom: 20px;
32
+ }
33
+ .mic-button {
34
+ width: 80px;
35
+ height: 80px;
36
+ border-radius: 50%;
37
  background-color: #007bff;
38
  color: white;
39
+ font-size: 40px;
40
  border: none;
 
 
41
  cursor: pointer;
42
  }
43
+ .status {
44
+ margin-top: 20px;
 
 
45
  font-size: 1.2rem;
46
+ color: #555;
 
47
  }
48
+ .response {
 
 
 
49
  margin-top: 20px;
50
+ font-size: 1.2rem;
 
 
 
 
 
 
 
 
 
51
  color: #333;
52
+ display: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
  </style>
55
  </head>
56
  <body>
57
 
58
  <div class="container">
59
+ <h1>AI Dining Assistant</h1>
60
+ <button class="mic-button" id="mic-button">🎤</button>
61
+ <div class="status" id="status">Press the mic button to start...</div>
62
+ <div class="response" id="response">Response will appear here...</div>
 
 
63
  </div>
64
 
 
65
  <script>
66
+ const micButton = document.getElementById('mic-button');
67
+ const status = document.getElementById('status');
68
+ const response = document.getElementById('response');
69
+ let isListening = false;
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ micButton.addEventListener('click', () => {
72
+ if (!isListening) {
73
+ isListening = true;
74
+ greetUser();
75
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  });
77
 
78
+ // Greeting the user and asking for their name
79
+ function greetUser() {
80
+ const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
81
+ speechSynthesis.speak(utterance);
82
+ utterance.onend = () => {
83
+ status.textContent = "Listening for your name...";
84
+ startListening();
85
+ };
86
  }
87
 
88
+ // Start listening for the user's response
89
+ async function startListening() {
90
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
91
+ const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
92
+ const audioChunks = [];
93
+ mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
94
+ mediaRecorder.onstop = async () => {
95
+ const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
96
+ const formData = new FormData();
97
+ formData.append("audio", audioBlob);
98
+ status.textContent = "Processing your preference... Please wait.";
99
+ try {
100
+ const result = await fetch("/process-audio", { method: "POST", body: formData });
101
+ const data = await result.json();
102
+ response.textContent = data.response;
103
+ response.style.display = "block";
104
+ const utterance = new SpeechSynthesisUtterance(data.response);
105
+ speechSynthesis.speak(utterance);
106
+ utterance.onend = () => {
107
+ if (!data.response.includes("Goodbye") && !data.response.includes("final order")) {
108
+ startListening(); // Continue listening
109
+ } else {
110
+ status.textContent = "Conversation ended.";
111
+ isListening = false;
112
+ }
113
+ };
114
+ } catch (error) {
115
+ response.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
116
+ status.textContent = "Press the mic button to restart.";
117
+ isListening = false;
118
+ }
119
  };
120
+ mediaRecorder.start();
121
+ setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
  </script>
124