Dynamic_Menu1 / app.py
Rammohan0504's picture
Update app.py
ff4e9fe verified
raw
history blame
8.97 kB
import gradio as gr
# Menu data
menu_data = [
{"name": "Veg Burger", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato."},
{"name": "Chicken Biryani", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces."},
{"name": "Paneer Butter Masala", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/paneer_butter_masala.jpg",
"description": "Paneer cooked in a rich and creamy tomato-based gravy."},
{"name": "Beef Steak", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/beef_steak.jpg",
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables."},
{"name": "Mushroom Soup", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mushroom_soup.jpg",
"description": "Creamy mushroom soup with fresh herbs."},
{"name": "Tandoori Chicken", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/tandoori_chicken.jpg",
"description": "Grilled chicken marinated in yogurt and spices, cooked in a tandoor."},
{"name": "Grilled Veggies", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/grilled_veggies.jpg",
"description": "A healthy mix of grilled seasonal vegetables with olive oil."},
{"name": "Butter Naan", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/butter_naan.jpg",
"description": "Soft and buttery flatbread, perfect to pair with any curry."},
{"name": "Fish Curry", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/fish_curry.jpg",
"description": "Fresh fish cooked in a spicy and tangy curry."},
{"name": "Vegetable Salad", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/vegetable_salad.jpg",
"description": "A mix of fresh greens, tomatoes, cucumbers, and a light dressing."},
{"name": "Veg Spring Rolls", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_spring_rolls.jpg",
"description": "Crispy spring rolls filled with fresh vegetables."},
{"name": "Chicken Kebab", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_kebab.jpg",
"description": "Juicy chicken kebabs grilled to perfection with a mix of spices."},
{"name": "Dal Makhani", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/dal_makhani.jpg",
"description": "Rich and creamy black lentils slow-cooked with spices."},
{"name": "Lamb Curry", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/lamb_curry.jpg",
"description": "Tender lamb pieces cooked in a flavorful curry sauce."},
{"name": "Mixed Veg Curry", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/mixed_veg_curry.jpg",
"description": "A medley of fresh vegetables cooked in a lightly spiced curry."},
{"name": "Chicken Wings", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_wings.jpg",
"description": "Crispy chicken wings tossed in a tangy sauce."},
{"name": "Aloo Paratha", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/aloo_paratha.jpg",
"description": "Indian flatbread stuffed with spiced mashed potatoes."},
{"name": "Egg Curry", "category": "HALAL",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/egg_curry.jpg",
"description": "Boiled eggs cooked in a spiced tomato gravy."},
{"name": "Chickpea Salad", "category": "VEGAN",
"image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chickpea_salad.jpg",
"description": "A refreshing salad made with chickpeas, fresh vegetables, and herbs."}
]
# Function to generate row-style dish cards
def display_dishes(category):
filtered_dishes = [dish for dish in menu_data if category == "ALL" or dish["category"] == category]
html_content = "<div style='display: flex; flex-wrap: wrap; gap: 15px; justify-content: center;'>"
for dish in filtered_dishes:
html_content += f"""
<div style='width: 220px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
background-color: #f9f9f9; text-align: center; cursor: pointer;'
onclick="showPopup(event, '{dish['image']}', '{dish['name']}', '{dish['description']}')">
<img src='{dish['image']}' alt='{dish['name']}'
style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
<h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
<p style='color: #666; font-size: 14px;'>{dish['description']}</p>
</div>
"""
html_content += "</div>"
return html_content
# Main Gradio App
with gr.Blocks() as demo:
gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Restaurant Menu 🍛</h1>")
# Category Buttons
with gr.Row():
btn_all = gr.Button("ALL")
btn_vegan = gr.Button("VEGAN")
btn_halal = gr.Button("HALAL")
# Dish display area
dish_display = gr.HTML(value=display_dishes("ALL"))
# Pop-up HTML and JavaScript
gr.HTML("""
<div id="popup" style="display: none; position: fixed; justify-content:center; align-items:center; transform: translate(-50%, 50%);
background-color: white; padding: 20px; border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
<h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
<p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
<button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
</div>
<script>
// Show the pop-up at the cursor's position
function showPopup(event, image, title, description) {
const popup = document.getElementById('popup');
const popupImage = document.getElementById('popup-image');
const popupTitle = document.getElementById('popup-title');
const popupDescription = document.getElementById('popup-description');
// Update the pop-up content
popupImage.src = image;
popupTitle.textContent = title;
popupDescription.textContent = description;
// Set the pop-up position based on cursor location
const popupWidth = 300; // Width of the pop-up
const xOffset = 10; // Offset to avoid overlapping cursor
const yOffset = 20; // Offset to place pop-up below the cursor
let xPos = event.pageX + xOffset;
let yPos = event.pageY + yOffset;
// Prevent the pop-up from going off the screen
if (xPos + popupWidth > window.innerWidth) {
xPos = window.innerWidth - popupWidth - xOffset;
}
if (yPos + popup.offsetHeight > window.innerHeight) {
yPos = window.innerHeight - popup.offsetHeight - yOffset;
}
popup.style.left = `${xPos}px`;
popup.style.top = `${yPos}px`;
popup.style.display = 'block';
}
// Close the pop-up
function closePopup() {
const popup = document.getElementById('popup');
popup.style.display = 'none';
}
</script>
""")
# Button actions for filtering
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
demo.launch()