import gradio as gr
import pandas as pd
# Load menu from Excel file
def load_menu(file_path="menu.xlsx"):
"""
Load menu data from an Excel file.
"""
menu_df = pd.read_excel(file_path)
menu = menu_df.to_dict(orient="records")
return menu
# Initialize menu and cart
menu_data = load_menu()
cart = []
def display_menu():
"""
Function to render the menu as HTML.
"""
menu_html = ""
for item in menu_data:
menu_html += f"""
{item['Name']} - ${item['Price']}
{item['Description']}
"""
return menu_html
def add_to_cart(item_name, quantity):
"""
Add an item to the cart and return success message with cart count.
"""
quantity = int(quantity)
# Check if the item already exists in the cart
for item in cart:
if item["name"] == item_name:
item["quantity"] += quantity
break
else:
# Add new item to cart
for item in menu_data:
if item["Name"] == item_name:
cart.append({"name": item_name, "price": item["Price"], "quantity": quantity})
break
return f"{item_name} added to cart! Total items: {len(cart)}"
def view_cart():
"""
Render the cart contents and calculate the total price.
"""
if not cart:
return "Your cart is empty."
cart_html = "
Cart Summary:
"
total_price = 0
for item in cart:
cart_html += f"