Spaces:
Sleeping
Sleeping
Update templates/menu_page.html
Browse files- templates/menu_page.html +47 -38
templates/menu_page.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
<style>
|
8 |
body { font-family: Arial, sans-serif; background-color: #f8f8f8; margin: 0; padding: 0; }
|
9 |
.menu-container { max-width: 1200px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; margin-top: 20px; }
|
@@ -19,8 +19,9 @@
|
|
19 |
</style>
|
20 |
</head>
|
21 |
<body>
|
|
|
22 |
<div class="menu-container">
|
23 |
-
<h1>Welcome to the
|
24 |
<div id="menu-items"></div>
|
25 |
<button onclick="viewCart()">View Cart</button>
|
26 |
</div>
|
@@ -46,12 +47,12 @@
|
|
46 |
|
47 |
const cart = [];
|
48 |
|
49 |
-
// Speech recognition to interact with the user
|
50 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
51 |
recognition.lang = 'en-US';
|
52 |
recognition.interimResults = false;
|
53 |
recognition.maxAlternatives = 1;
|
54 |
|
|
|
55 |
function speak(text, callback) {
|
56 |
const msg = new SpeechSynthesisUtterance(text);
|
57 |
msg.onend = callback;
|
@@ -59,35 +60,16 @@
|
|
59 |
}
|
60 |
|
61 |
function askForVegOrNonVeg() {
|
62 |
-
speak("Would you prefer
|
63 |
recognition.start();
|
64 |
});
|
65 |
}
|
66 |
|
67 |
-
|
68 |
-
const command = event.results[0][0].transcript.toLowerCase();
|
69 |
-
console.log("User said:", command);
|
70 |
-
if (command.includes('veg')) {
|
71 |
-
showMenu('veg');
|
72 |
-
speak("Here are the vegetarian items.", () => askForItemsToAdd());
|
73 |
-
} else if (command.includes('non-veg')) {
|
74 |
-
showMenu('nonVeg');
|
75 |
-
speak("Here are the non-vegetarian items.", () => askForItemsToAdd());
|
76 |
-
} else {
|
77 |
-
speak("Please say either veg or non-veg.", () => {
|
78 |
-
recognition.start();
|
79 |
-
});
|
80 |
-
}
|
81 |
-
};
|
82 |
-
|
83 |
-
recognition.onerror = (event) => {
|
84 |
-
console.error("Speech recognition error:", event.error);
|
85 |
-
speak("Sorry, I couldn't understand that. Please try again.", () => recognition.start());
|
86 |
-
};
|
87 |
-
|
88 |
function showMenu(type) {
|
89 |
const menuContainer = document.getElementById('menu-items');
|
90 |
menuContainer.innerHTML = ''; // Clear previous menu items
|
|
|
91 |
menuItems[type].forEach(item => {
|
92 |
const div = document.createElement('div');
|
93 |
div.classList.add('menu-item');
|
@@ -98,7 +80,6 @@
|
|
98 |
<p>${item.description}</p>
|
99 |
<p><strong>Ingredients:</strong> ${item.ingredients}</p>
|
100 |
<p><strong>Price:</strong> $${item.price}</p>
|
101 |
-
<p><strong>Quantity:</strong> <input type="number" id="quantity-${item.name}" value="1" min="1" /></p>
|
102 |
<button onclick="addToCart('${item.name}')">Add to Cart</button>
|
103 |
</div>
|
104 |
</div>`;
|
@@ -106,20 +87,21 @@
|
|
106 |
});
|
107 |
}
|
108 |
|
109 |
-
|
110 |
-
speak("Please say the name of the item you'd like to add to the cart.", () => {
|
111 |
-
recognition.start();
|
112 |
-
});
|
113 |
-
}
|
114 |
-
|
115 |
function addToCart(itemName) {
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
|
|
|
123 |
function viewCart() {
|
124 |
const cartContainer = document.getElementById('cart-container');
|
125 |
const cartItemsContainer = document.getElementById('cart-items');
|
@@ -133,10 +115,37 @@
|
|
133 |
cartContainer.style.display = 'block';
|
134 |
}
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
window.onload = () => {
|
137 |
speak("Welcome to the Biryani Hub menu.", () => askForVegOrNonVeg());
|
138 |
};
|
139 |
</script>
|
140 |
</body>
|
141 |
</html>
|
142 |
-
|
|
|
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 { font-family: Arial, sans-serif; background-color: #f8f8f8; margin: 0; padding: 0; }
|
9 |
.menu-container { max-width: 1200px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; margin-top: 20px; }
|
|
|
19 |
</style>
|
20 |
</head>
|
21 |
<body>
|
22 |
+
|
23 |
<div class="menu-container">
|
24 |
+
<h1>Welcome to the Menu</h1>
|
25 |
<div id="menu-items"></div>
|
26 |
<button onclick="viewCart()">View Cart</button>
|
27 |
</div>
|
|
|
47 |
|
48 |
const cart = [];
|
49 |
|
|
|
50 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
51 |
recognition.lang = 'en-US';
|
52 |
recognition.interimResults = false;
|
53 |
recognition.maxAlternatives = 1;
|
54 |
|
55 |
+
// Greeting the user
|
56 |
function speak(text, callback) {
|
57 |
const msg = new SpeechSynthesisUtterance(text);
|
58 |
msg.onend = callback;
|
|
|
60 |
}
|
61 |
|
62 |
function askForVegOrNonVeg() {
|
63 |
+
speak("Would you prefer vegetarian or non-vegetarian?", () => {
|
64 |
recognition.start();
|
65 |
});
|
66 |
}
|
67 |
|
68 |
+
// Function to display menu based on user's choice (veg/non-veg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
function showMenu(type) {
|
70 |
const menuContainer = document.getElementById('menu-items');
|
71 |
menuContainer.innerHTML = ''; // Clear previous menu items
|
72 |
+
|
73 |
menuItems[type].forEach(item => {
|
74 |
const div = document.createElement('div');
|
75 |
div.classList.add('menu-item');
|
|
|
80 |
<p>${item.description}</p>
|
81 |
<p><strong>Ingredients:</strong> ${item.ingredients}</p>
|
82 |
<p><strong>Price:</strong> $${item.price}</p>
|
|
|
83 |
<button onclick="addToCart('${item.name}')">Add to Cart</button>
|
84 |
</div>
|
85 |
</div>`;
|
|
|
87 |
});
|
88 |
}
|
89 |
|
90 |
+
// Function to add items to the cart
|
|
|
|
|
|
|
|
|
|
|
91 |
function addToCart(itemName) {
|
92 |
+
let quantity = prompt(`How many ${itemName} would you like to add?`, 1);
|
93 |
+
if (quantity && !isNaN(quantity) && quantity > 0) {
|
94 |
+
quantity = parseInt(quantity);
|
95 |
+
const item = menuItems.veg.concat(menuItems.nonVeg).find(item => item.name === itemName);
|
96 |
+
const cartItem = { ...item, quantity };
|
97 |
+
cart.push(cartItem);
|
98 |
+
speak(`${quantity} of ${itemName} added to your cart.`);
|
99 |
+
} else {
|
100 |
+
speak("Please enter a valid quantity.");
|
101 |
+
}
|
102 |
}
|
103 |
|
104 |
+
// Function to view cart
|
105 |
function viewCart() {
|
106 |
const cartContainer = document.getElementById('cart-container');
|
107 |
const cartItemsContainer = document.getElementById('cart-items');
|
|
|
115 |
cartContainer.style.display = 'block';
|
116 |
}
|
117 |
|
118 |
+
// Speech recognition for handling the customer’s choice
|
119 |
+
recognition.onresult = (event) => {
|
120 |
+
const command = event.results[0][0].transcript.toLowerCase();
|
121 |
+
if (command.includes('vegetarian')) {
|
122 |
+
showMenu('veg');
|
123 |
+
speak("Here are the vegetarian items.", () => askForItemsToAdd());
|
124 |
+
} else if (command.includes('non-vegetarian')) {
|
125 |
+
showMenu('nonVeg');
|
126 |
+
speak("Here are the non-vegetarian items.", () => askForItemsToAdd());
|
127 |
+
} else {
|
128 |
+
speak("Please say vegetarian or non-vegetarian.", () => {
|
129 |
+
recognition.start();
|
130 |
+
});
|
131 |
+
}
|
132 |
+
};
|
133 |
+
|
134 |
+
recognition.onerror = (event) => {
|
135 |
+
console.error("Speech recognition error:", event.error);
|
136 |
+
speak("Sorry, I couldn't understand that. Please try again.", () => recognition.start());
|
137 |
+
};
|
138 |
+
|
139 |
+
function askForItemsToAdd() {
|
140 |
+
speak("Please say the name of the item you'd like to add to the cart.", () => {
|
141 |
+
recognition.start();
|
142 |
+
});
|
143 |
+
}
|
144 |
+
|
145 |
+
// Initiating the process as soon as the page loads
|
146 |
window.onload = () => {
|
147 |
speak("Welcome to the Biryani Hub menu.", () => askForVegOrNonVeg());
|
148 |
};
|
149 |
</script>
|
150 |
</body>
|
151 |
</html>
|
|