Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Biryani Hub Menu</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f8f8f8; | |
text-align: center; | |
margin: 0; | |
padding: 20px; | |
} | |
h1 { | |
color: #ff5722; | |
} | |
.menu-container { | |
display: flex; | |
flex-wrap: wrap; | |
justify-content: center; | |
margin-top: 20px; | |
} | |
.menu-item { | |
background: white; | |
padding: 15px; | |
margin: 10px; | |
border-radius: 8px; | |
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1); | |
width: 300px; | |
text-align: left; | |
} | |
.menu-item h3 { | |
margin: 0; | |
color: #333; | |
} | |
.menu-item p { | |
margin: 5px 0; | |
color: #555; | |
} | |
.menu-item button { | |
background-color: #ff5722; | |
color: white; | |
border: none; | |
padding: 8px; | |
cursor: pointer; | |
width: 100%; | |
border-radius: 5px; | |
} | |
.menu-item button:hover { | |
background-color: #e64a19; | |
} | |
.cart-container { | |
margin-top: 20px; | |
padding: 15px; | |
background-color: white; | |
border: 1px solid #ddd; | |
border-radius: 5px; | |
width: 50%; | |
margin-left: auto; | |
margin-right: auto; | |
display: none; | |
} | |
.cart-item { | |
display: flex; | |
justify-content: space-between; | |
padding: 5px; | |
border-bottom: 1px solid #ddd; | |
} | |
.cart-item:last-child { | |
border-bottom: none; | |
} | |
.filter-buttons { | |
margin: 15px; | |
} | |
.filter-buttons button { | |
margin: 5px; | |
padding: 10px; | |
border: none; | |
cursor: pointer; | |
border-radius: 5px; | |
background-color: #007bff; | |
color: white; | |
} | |
.filter-buttons button:hover { | |
background-color: #0056b3; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Restaurant Menu</h1> | |
<!-- Buttons for filtering menu --> | |
<div class="filter-buttons"> | |
<button onclick="filterMenu('veg')">Vegetarian</button> | |
<button onclick="filterMenu('non-veg')">Non-Vegetarian</button> | |
</div> | |
<!-- Menu Display --> | |
<div class="menu-container" id="menu-list"> | |
{% for item in menu %} | |
<div class="menu-item" data-category="{{ item.category }}"> | |
<h3>{{ item.name }}</h3> | |
<p><strong>Category:</strong> {{ item.category }}</p> | |
<p><strong>Price:</strong> ${{ item.price }}</p> | |
<p><strong>Ingredients:</strong> {{ item.ingredients }}</p> | |
<button onclick="addToCart('{{ item.name }}', {{ item.price }})">Add to Cart</button> | |
</div> | |
{% endfor %} | |
</div> | |
<!-- Cart Section --> | |
<div class="cart-container" id="cart-container"> | |
<h2>Your Cart</h2> | |
<div id="cart-items"></div> | |
<button onclick="checkout()">Checkout</button> | |
</div> | |
<!-- View Cart Button --> | |
<button onclick="viewCart()">View Cart</button> | |
<script> | |
// ✅ Speech Synthesis - Welcome message | |
function speak(text, callback) { | |
const msg = new SpeechSynthesisUtterance(text); | |
msg.onend = callback; | |
window.speechSynthesis.speak(msg); | |
} | |
// ✅ Ask user Veg or Non-Veg | |
function askMenuType() { | |
speak("Welcome to Biryani Hub Menu. Would you like to see Vegetarian or Non-Vegetarian options?", function() { | |
startListening(); | |
}); | |
} | |
// ✅ Speech Recognition (User says Veg or Non-Veg) | |
function startListening() { | |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)(); | |
recognition.lang = "en-US"; | |
recognition.start(); | |
recognition.onresult = function(event) { | |
const command = event.results[0][0].transcript.toLowerCase(); | |
if (command.includes("vegetarian") || command.includes("veg")) { | |
filterMenu("veg"); | |
speak("Here are the vegetarian items."); | |
} else if (command.includes("non-vegetarian") || command.includes("non veg")) { | |
filterMenu("non-veg"); | |
speak("Here are the non-vegetarian items."); | |
} else { | |
speak("Sorry, I didn't understand. Please say Vegetarian or Non-Vegetarian.", function() { | |
startListening(); | |
}); | |
} | |
}; | |
} | |
// ✅ Function to filter menu by category | |
function filterMenu(type) { | |
const allItems = document.querySelectorAll('.menu-item'); | |
allItems.forEach(item => { | |
if (type === "veg" && item.dataset.category.toLowerCase().includes("veg")) { | |
item.style.display = "block"; | |
} else if (type === "non-veg" && item.dataset.category.toLowerCase().includes("chicken") || item.dataset.category.toLowerCase().includes("mutton") || item.dataset.category.toLowerCase().includes("fish") || item.dataset.category.toLowerCase().includes("prawn")) { | |
item.style.display = "block"; | |
} else { | |
item.style.display = "none"; | |
} | |
}); | |
} | |
// ✅ Cart Functionality | |
let cart = []; | |
function addToCart(name, price) { | |
let itemIndex = cart.findIndex(item => item.name === name); | |
if (itemIndex > -1) { | |
cart[itemIndex].quantity += 1; | |
} else { | |
cart.push({ name: name, price: price, quantity: 1 }); | |
} | |
alert(name + " added to cart!"); | |
} | |
function viewCart() { | |
const cartContainer = document.getElementById("cart-container"); | |
const cartItemsContainer = document.getElementById("cart-items"); | |
cartItemsContainer.innerHTML = ""; | |
cart.forEach(item => { | |
let div = document.createElement("div"); | |
div.classList.add("cart-item"); | |
div.innerHTML = `<span>${item.name} (x${item.quantity}) - $${item.price * item.quantity}</span>`; | |
cartItemsContainer.appendChild(div); | |
}); | |
cartContainer.style.display = "block"; | |
} | |
function checkout() { | |
if (cart.length > 0) { | |
alert("Your order has been placed successfully!"); | |
cart = []; | |
viewCart(); | |
} else { | |
alert("Your cart is empty!"); | |
} | |
} | |
// ✅ Welcome Message on Page Load | |
window.onload = askMenuType; | |
</script> | |
</body> | |
</html> | |