Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +104 -77
templates/menu_page.html
CHANGED
|
@@ -7,28 +7,26 @@
|
|
| 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:
|
| 26 |
-
max-width:
|
| 27 |
}
|
| 28 |
h1 {
|
| 29 |
color: #333;
|
| 30 |
-
font-size: 2rem;
|
| 31 |
-
margin-bottom: 20px;
|
| 32 |
}
|
| 33 |
.mic-button {
|
| 34 |
width: 80px;
|
|
@@ -45,15 +43,8 @@
|
|
| 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 |
.menu-items-container {
|
| 55 |
margin-top: 30px;
|
| 56 |
-
padding-top: 20px;
|
| 57 |
display: grid;
|
| 58 |
grid-template-columns: 1fr 1fr;
|
| 59 |
gap: 20px;
|
|
@@ -65,10 +56,6 @@
|
|
| 65 |
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
|
| 66 |
text-align: left;
|
| 67 |
}
|
| 68 |
-
.menu-item h3 {
|
| 69 |
-
font-size: 1.5rem;
|
| 70 |
-
color: #333;
|
| 71 |
-
}
|
| 72 |
</style>
|
| 73 |
</head>
|
| 74 |
<body>
|
|
@@ -77,28 +64,19 @@
|
|
| 77 |
<h1>AI Dining Assistant</h1>
|
| 78 |
<button class="mic-button" id="mic-button">🎤</button>
|
| 79 |
<div class="status" id="status">Press the mic button to start...</div>
|
| 80 |
-
<div class="response" id="response">Response will appear here...</div>
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
{% for item in menu_items %}
|
| 85 |
-
<div class="menu-item" id="menu-item-{{ loop.index }}">
|
| 86 |
-
<h3>{{ item.Name }}</h3>
|
| 87 |
-
<p><strong>Price:</strong> ${{ item.Price__c }}</p>
|
| 88 |
-
<p><strong>Ingredients:</strong> {{ item.Ingredients__c }}</p>
|
| 89 |
-
<p><strong>Category:</strong> {{ item.Category__c }}</p>
|
| 90 |
-
<button class="order-btn" data-item="{{ item.Name }}">Order</button>
|
| 91 |
-
</div>
|
| 92 |
-
{% endfor %}
|
| 93 |
</div>
|
| 94 |
</div>
|
| 95 |
|
| 96 |
<script>
|
| 97 |
const micButton = document.getElementById('mic-button');
|
| 98 |
const status = document.getElementById('status');
|
| 99 |
-
const
|
| 100 |
-
const menuItemsContainer = document.querySelector('.menu-items-container');
|
| 101 |
let isListening = false;
|
|
|
|
|
|
|
| 102 |
|
| 103 |
micButton.addEventListener('click', () => {
|
| 104 |
if (!isListening) {
|
|
@@ -107,18 +85,18 @@
|
|
| 107 |
}
|
| 108 |
});
|
| 109 |
|
| 110 |
-
//
|
| 111 |
function greetUser() {
|
| 112 |
const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
|
| 113 |
speechSynthesis.speak(utterance);
|
| 114 |
utterance.onend = () => {
|
| 115 |
status.textContent = "Listening for your name...";
|
| 116 |
-
|
| 117 |
};
|
| 118 |
}
|
| 119 |
|
| 120 |
-
// Start listening for
|
| 121 |
-
async function
|
| 122 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 123 |
const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
|
| 124 |
const audioChunks = [];
|
|
@@ -128,35 +106,83 @@
|
|
| 128 |
const formData = new FormData();
|
| 129 |
formData.append("audio", audioBlob);
|
| 130 |
|
| 131 |
-
status.textContent = "Processing your
|
| 132 |
-
|
| 133 |
try {
|
| 134 |
-
|
| 135 |
-
const
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
});
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
}
|
| 156 |
-
};
|
| 157 |
} catch (error) {
|
| 158 |
-
|
| 159 |
-
status.textContent = "Press the mic button to restart.";
|
| 160 |
isListening = false;
|
| 161 |
}
|
| 162 |
};
|
|
@@ -164,27 +190,28 @@
|
|
| 164 |
setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
|
| 165 |
}
|
| 166 |
|
| 167 |
-
//
|
| 168 |
-
function
|
| 169 |
-
const
|
| 170 |
-
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
});
|
| 182 |
}
|
| 183 |
-
|
| 184 |
-
// Trigger the speech for menu items when the page loads
|
| 185 |
-
window.onload = function() {
|
| 186 |
-
speakMenuItems();
|
| 187 |
-
};
|
| 188 |
</script>
|
| 189 |
|
| 190 |
</body>
|
|
|
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: Arial, sans-serif;
|
|
|
|
| 10 |
background-color: #f4f4f9;
|
| 11 |
+
text-align: center;
|
| 12 |
margin: 0;
|
| 13 |
padding: 0;
|
|
|
|
| 14 |
display: flex;
|
| 15 |
justify-content: center;
|
| 16 |
align-items: center;
|
| 17 |
+
height: 100vh;
|
| 18 |
}
|
| 19 |
.container {
|
| 20 |
text-align: center;
|
| 21 |
background-color: #fff;
|
|
|
|
| 22 |
padding: 40px;
|
| 23 |
+
border-radius: 10px;
|
| 24 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 25 |
+
width: 80%;
|
| 26 |
+
max-width: 600px;
|
| 27 |
}
|
| 28 |
h1 {
|
| 29 |
color: #333;
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
.mic-button {
|
| 32 |
width: 80px;
|
|
|
|
| 43 |
font-size: 1.2rem;
|
| 44 |
color: #555;
|
| 45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
.menu-items-container {
|
| 47 |
margin-top: 30px;
|
|
|
|
| 48 |
display: grid;
|
| 49 |
grid-template-columns: 1fr 1fr;
|
| 50 |
gap: 20px;
|
|
|
|
| 56 |
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
|
| 57 |
text-align: left;
|
| 58 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
</style>
|
| 60 |
</head>
|
| 61 |
<body>
|
|
|
|
| 64 |
<h1>AI Dining Assistant</h1>
|
| 65 |
<button class="mic-button" id="mic-button">🎤</button>
|
| 66 |
<div class="status" id="status">Press the mic button to start...</div>
|
|
|
|
| 67 |
|
| 68 |
+
<div class="menu-items-container" id="menu-items">
|
| 69 |
+
<!-- Menu items will be populated here dynamically -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
|
| 73 |
<script>
|
| 74 |
const micButton = document.getElementById('mic-button');
|
| 75 |
const status = document.getElementById('status');
|
| 76 |
+
const menuItemsContainer = document.getElementById('menu-items');
|
|
|
|
| 77 |
let isListening = false;
|
| 78 |
+
let selectedItem = '';
|
| 79 |
+
let quantity = 0;
|
| 80 |
|
| 81 |
micButton.addEventListener('click', () => {
|
| 82 |
if (!isListening) {
|
|
|
|
| 85 |
}
|
| 86 |
});
|
| 87 |
|
| 88 |
+
// Greet user
|
| 89 |
function greetUser() {
|
| 90 |
const utterance = new SpeechSynthesisUtterance("Hi, welcome to Biryani Hub! Can I know your name so I can greet you personally?");
|
| 91 |
speechSynthesis.speak(utterance);
|
| 92 |
utterance.onend = () => {
|
| 93 |
status.textContent = "Listening for your name...";
|
| 94 |
+
startListeningForName();
|
| 95 |
};
|
| 96 |
}
|
| 97 |
|
| 98 |
+
// Start listening for user input (name)
|
| 99 |
+
async function startListeningForName() {
|
| 100 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 101 |
const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
|
| 102 |
const audioChunks = [];
|
|
|
|
| 106 |
const formData = new FormData();
|
| 107 |
formData.append("audio", audioBlob);
|
| 108 |
|
| 109 |
+
status.textContent = "Processing your name... Please wait.";
|
|
|
|
| 110 |
try {
|
| 111 |
+
const result = await fetch("/process-audio", { method: "POST", body: formData });
|
| 112 |
+
const data = await result.json();
|
| 113 |
+
selectedItem = data.name;
|
| 114 |
+
status.textContent = `Hello ${selectedItem}! How can I help you today?`;
|
| 115 |
+
suggestFood();
|
| 116 |
+
} catch (error) {
|
| 117 |
+
status.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
|
| 118 |
+
isListening = false;
|
| 119 |
+
}
|
| 120 |
+
};
|
| 121 |
+
mediaRecorder.start();
|
| 122 |
+
setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// Suggest food items to the user
|
| 126 |
+
function suggestFood() {
|
| 127 |
+
fetch('/menu') // GET request to fetch menu items from the server
|
| 128 |
+
.then(response => response.json())
|
| 129 |
+
.then(data => {
|
| 130 |
+
menuItemsContainer.innerHTML = "";
|
| 131 |
+
data.forEach(item => {
|
| 132 |
+
const menuItemDiv = document.createElement('div');
|
| 133 |
+
menuItemDiv.classList.add('menu-item');
|
| 134 |
+
menuItemDiv.innerHTML = `
|
| 135 |
+
<h3>${item.Name}</h3>
|
| 136 |
+
<p><strong>Price:</strong> $${item.Price__c}</p>
|
| 137 |
+
<p><strong>Ingredients:</strong> ${item.Ingredients__c}</p>
|
| 138 |
+
<p><strong>Category:</strong> ${item.Category__c}</p>
|
| 139 |
+
<button class="order-btn" data-item="${item.Name}" onclick="takeOrder('${item.Name}')">Order</button>
|
| 140 |
+
`;
|
| 141 |
+
menuItemsContainer.appendChild(menuItemDiv);
|
| 142 |
});
|
| 143 |
+
speakMenuItems(data);
|
| 144 |
+
});
|
| 145 |
+
}
|
| 146 |
|
| 147 |
+
// Read out the menu items
|
| 148 |
+
function speakMenuItems(items) {
|
| 149 |
+
const utterance = new SpeechSynthesisUtterance("Here are the menu items:");
|
| 150 |
+
speechSynthesis.speak(utterance);
|
| 151 |
+
items.forEach(item => {
|
| 152 |
+
const itemUtterance = new SpeechSynthesisUtterance(`${item.Name}, Price: $${item.Price__c}, Ingredients: ${item.Ingredients__c}`);
|
| 153 |
+
speechSynthesis.speak(itemUtterance);
|
| 154 |
+
});
|
| 155 |
+
}
|
| 156 |
|
| 157 |
+
// Handle user order
|
| 158 |
+
function takeOrder(item) {
|
| 159 |
+
selectedItem = item;
|
| 160 |
+
const utterance = new SpeechSynthesisUtterance(`You selected ${item}. How many would you like?`);
|
| 161 |
+
speechSynthesis.speak(utterance);
|
| 162 |
+
status.textContent = `You selected ${item}. How many would you like?`;
|
| 163 |
+
startListeningForQuantity();
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
// Start listening for quantity
|
| 167 |
+
async function startListeningForQuantity() {
|
| 168 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 169 |
+
const mediaRecorder = new MediaRecorder(stream, { mimeType: "audio/webm;codecs=opus" });
|
| 170 |
+
const audioChunks = [];
|
| 171 |
+
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
|
| 172 |
+
mediaRecorder.onstop = async () => {
|
| 173 |
+
const audioBlob = new Blob(audioChunks, { type: "audio/webm" });
|
| 174 |
+
const formData = new FormData();
|
| 175 |
+
formData.append("audio", audioBlob);
|
| 176 |
|
| 177 |
+
status.textContent = "Processing your quantity... Please wait.";
|
| 178 |
+
try {
|
| 179 |
+
const result = await fetch("/process-audio", { method: "POST", body: formData });
|
| 180 |
+
const data = await result.json();
|
| 181 |
+
quantity = parseInt(data.quantity);
|
| 182 |
+
status.textContent = `You want ${quantity} of ${selectedItem}. Please confirm your order.`;
|
| 183 |
+
confirmOrder();
|
|
|
|
|
|
|
| 184 |
} catch (error) {
|
| 185 |
+
status.textContent = "Sorry, I couldn’t understand that. Could you please repeat?";
|
|
|
|
| 186 |
isListening = false;
|
| 187 |
}
|
| 188 |
};
|
|
|
|
| 190 |
setTimeout(() => mediaRecorder.stop(), 5000); // Stop recording after 5 seconds
|
| 191 |
}
|
| 192 |
|
| 193 |
+
// Confirm the order and send it to the backend
|
| 194 |
+
function confirmOrder() {
|
| 195 |
+
const orderDetails = {
|
| 196 |
+
item: selectedItem,
|
| 197 |
+
quantity: quantity
|
| 198 |
+
};
|
| 199 |
|
| 200 |
+
fetch('/order', {
|
| 201 |
+
method: 'POST',
|
| 202 |
+
headers: {
|
| 203 |
+
'Content-Type': 'application/json'
|
| 204 |
+
},
|
| 205 |
+
body: JSON.stringify(orderDetails)
|
| 206 |
+
})
|
| 207 |
+
.then(response => response.json())
|
| 208 |
+
.then(data => {
|
| 209 |
+
status.textContent = `Order placed for ${quantity} of ${selectedItem}.`;
|
| 210 |
+
})
|
| 211 |
+
.catch(error => {
|
| 212 |
+
status.textContent = "Error placing order.";
|
| 213 |
});
|
| 214 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
</script>
|
| 216 |
|
| 217 |
</body>
|