import gradio as gr
# Global variables for cart and menu data
cart = []
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.",
"price": "$8.99"},
{"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.",
"price": "$12.99"},
{"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 cart
def add_to_cart(item_name):
cart.append({"item_name": item_name})
return {"data": f"{item_name} added to cart!"}
# Function to display the current cart
def display_cart():
if not cart:
return "Your cart is empty."
cart_content = "
Your Cart:
"
for item in cart:
cart_content += f"
{item['item_name']}
"
cart_content += "
"
return cart_content
# Function to generate dish cards
def display_dishes(category):
html_content = "
"
for dish in menu_data:
if category == "ALL" or dish["category"] == category:
html_content += f"""
{dish['name']}
{dish['description']}
Price: {dish['price']}
"""
html_content += "
"
return html_content
# Popup JavaScript for handling the modal
popup_js = """
"""
# Popup HTML structure
popup_html = """
"""
# Main Gradio App
with gr.Blocks() as demo:
gr.HTML(popup_html) # Add popup container
gr.HTML(popup_js) # Add popup JavaScript
gr.HTML("
🍛 Welcome to the Biryani Hub 🍛
")
with gr.Tabs():
# Menu Tab
with gr.Tab("Menu"):
with gr.Row():
btn_all = gr.Button("ALL")
btn_vegan = gr.Button("VEGAN")
btn_halal = gr.Button("HALAL")
dish_display = gr.HTML(value=display_dishes("ALL"))
btn_all.click(
lambda: display_dishes("ALL"),
outputs=dish_display
)
btn_vegan.click(
lambda: display_dishes("VEGAN"),
outputs=dish_display
)
btn_halal.click(
lambda: display_dishes("HALAL"),
outputs=dish_display
)
# Cart Tab
with gr.Tab("Cart"):
cart_display = gr.HTML(value=display_cart())
refresh_cart_btn = gr.Button("Refresh Cart")
refresh_cart_btn.click(
lambda: display_cart(),
outputs=cart_display
)
# Register the add_to_cart function
demo.add_to_cart = add_to_cart
demo.launch()