Spaces:
Sleeping
Sleeping
Update app.py
Browse files123457 unmodified lines131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201import gradio as grfrom cart_tab import add_to_cart, display_cartmenu_data = [{"name": "Veg Burger", "category": "VEGAN",7 unmodified lines{"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.","price": "$10.99"},{"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.","price": "$15.99"},{"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.","price": "$7.99"},{"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.","price": "$11.99"},{"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.","price": "$9.99"},{"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.","price": "$2.99"},{"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.","price": "$13.99"},{"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.","price": "$6.99"},{"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.","price": "$5.99"},{"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.","price": "$9.99"},{"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.","price": "$8.99"},{"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.","price": "$14.99"},{"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.","price": "$9.99"},{"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.","price": "$12.99"},{"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.","price": "$3.99"},{"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.","price": "$9.99"},{"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.","price": "$7.99"}]# Spice levels and extrasspice_levels = ["American Mild", "American Medium", "American Spicy","Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]extras = [{"name": "Extra Raitha 4oz", "price": "$1.00"},{"name": "Extra Raitha 8oz", "price": "$2.00"},{"name": "Extra Onion", "price": "$1.00"},{"name": "Extra Onion & Lemon", "price": "$2.00"}]# Global cart variablecart = []def add_to_cart(item_name, spice_level=None, extras=None):"""Add selected item to cart."""cart.append({"item_name": item_name, "spice_level": spice_level, "extras": extras or []})return f"{item_name} added to cart!"def display_cart():"""Return the current cart contents."""if not cart:return "Your cart is empty."cart_content = "<h3>Your Cart:</h3><ul>"for item in cart:extras = ', '.join(item['extras']) if item['extras'] else "No extras"cart_content += f"<li>{item['item_name']} - Spice: {item['spice_level'] or 'Default'} - Extras: {extras}</li>"cart_content += "</ul>"return cart_content# JavaScript for popup modalpopup_js = """<script>function showPopup(name, description, price, image) {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.innerHTML = `<img src="${image}" alt="${name}" style="width: 100%; height: 250px; border-radius: 10px; margin-bottom: 10px;"><h3 style="margin-top: 10px;">${name}</h3><p>${description}</p><p style="font-weight: bold;">Price: ${price}</p><h4 style="margin-top: 20px;">Choose a Spice Level</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["American Mild", "American Medium", "American Spicy", "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"].map(spice => `<label style="margin-right: 10px;"><input type="radio" name="spice" value="${spice}"> ${spice}</label>`).join("")}</div><h4 style="margin-top: 20px;">Choose Extras</h4><div style="display: flex; flex-wrap: wrap; gap: 10px;">${["Extra Raitha 4oz + $1.00", "Extra Raitha 8oz + $2.00", "Extra Onion + $1.00", "Extra Onion & Lemon + $2.00"].map(extra => `<label style="margin-right: 10px;"><input type="checkbox" name="extras" value="${extra}"> ${extra}</label>`).join("")}</div><button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="margin-top: 20px; margin-left: 10px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>`;popup.style.display = "block";overlay.style.display = "block";}function closePopup() {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.style.display = "none";overlay.style.display = "none";}</script>"""# HTML for popup modalpopup_html = """<div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div><div id="custom-popup"style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50%; max-width: 400px; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000; text-align: center;"></div>"""def display_dishes(category):"""Render dishes dynamically based on the selected category."""html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"for dish in menu_data:if category == "ALL" or dish["category"] == category:html_content += f"""<div style='flex: 1 1 calc(30% - 20px); display: flex; flex-direction: column; align-items: center;justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px;background-color: #f9f9f9; box-shadow: 0 4px 8px rgba(0,0,0,0.1);'><img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'><h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p><button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;border-radius: 5px; cursor: pointer;'onclick="addToCart('{dish['name']}')">Add to Cart</button></div>"""html_content += "</div>"return html_content# Main Gradio Appwith gr.Blocks() as demo:gr.HTML("<h1 style='text-align: center;'>π Welcome to the Biryani Hub π</h1>")with gr.Tabs():12345677 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import gradio as gr# Global variables for cart and menu datacart = []menu_data = [{"name": "Veg Burger", "category": "VEGAN",7 unmodified lines{"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.","price": "$10.99"}]# Function to add an item to the cartdef add_to_cart(item_name):cart.append({"item_name": item_name})return f"{item_name} added to cart!"# Function to display the current cartdef display_cart():if not cart:return "Your cart is empty."cart_content = "<h3>Your Cart:</h3><ul>"for item in cart:cart_content += f"<li>{item['item_name']}</li>"cart_content += "</ul>"return cart_content# Function to generate dish cardsdef display_dishes(category):html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"for dish in menu_data:if category == "ALL" or dish["category"] == category:html_content += f"""<div style='flex: 1 1 calc(30% - 20px); display: flex; flex-direction: column; align-items: center;justify-content: space-between; padding: 20px; border: 1px solid #ddd; border-radius: 10px;background-color: #f9f9f9; box-shadow: 0 4px 8px rgba(0,0,0,0.1);'><img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'><h3 style='margin: 10px 0; font-size: 18px;'>{dish['name']}</h3><p style='margin: 5px 0; font-size: 14px; color: #555;'>{dish['description']}</p><p style='margin: 10px 0; font-size: 16px; font-weight: bold;'>Price: {dish['price']}</p><button style='padding: 10px 20px; background-color: #28a745; color: white; border: none;border-radius: 5px; cursor: pointer;'onclick="showPopup('{dish['name']}', '{dish['description']}', '{dish['price']}', '{dish['image']}')">Add to Cart</button></div>"""html_content += "</div>"return html_content# Popup JavaScript for handling the modalpopup_js = """<script>function showPopup(name, description, price, image) {const popup = document.getElementById("custom-popup");const overlay = document.getElementById("overlay");popup.innerHTML = `<img src="${image}" alt="${name}" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;"><h3>${name}</h3><p>${description}</p><p style="font-weight: bold;">Price: ${price}</p><button onclick="addToCart('${name}')" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">Add to Cart</button><button onclick="closePopup()" style="padding: 10px 20px; background-color: #dc3545; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">Close</button>`;popup.style.display = "block";overlay.style.display = "block";}function closePopup() {document.getElementById("custom-popup").style.display = "none";document.getElementById("overlay").style.display = "none";}function addToCart(name) {google.colab.kernel.invokeFunction('notebook.add_to_cart', [name], {});closePopup();}</script>"""# Popup HTML structurepopup_html = """<div id="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; z-index: 999;"></div><div id="custom-popup"style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; max-width: 90%; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 6px rgba(0,0,0,0.1); display: none; z-index: 1000;"></div>"""# Main Gradio Appwith gr.Blocks() as demo:gr.HTML(popup_html) # Add popup containergr.HTML(popup_js) # Add popup JavaScriptgr.HTML("<h1 style='text-align: center;'>π Welcome to the Biryani Hub π</h1>")with gr.Tabs():
app.py+52-145