import gradio as gr import pandas as pd # Load menu data from Excel file def load_menu(file_path="menu.xlsx"): menu_df = pd.read_excel(file_path) menu_df.columns = menu_df.columns.str.strip().str.lower() column_mapping = { "name": next((col for col in menu_df.columns if "name" in col), None), "price": next((col for col in menu_df.columns if "price" in col), None), "description": next((col for col in menu_df.columns if "description" in col), None), "image": next((col for col in menu_df.columns if "image" in col), None), } missing_columns = [key for key, col in column_mapping.items() if col is None] if missing_columns: raise ValueError(f"Excel file is missing one or more required columns: {missing_columns}") menu = [] for _, row in menu_df.iterrows(): menu.append({ "name": row[column_mapping["name"]], "price": row[column_mapping["price"]], "description": row[column_mapping["description"]], "image": row[column_mapping["image"]], }) return menu # Initialize menu and cart menu_data = load_menu("menu.xlsx") cart = {} # Function to add an item to the cart def add_to_cart(item_name): if item_name in cart: cart[item_name]["quantity"] += 1 else: for item in menu_data: if item["name"] == item_name: cart[item_name] = { "name": item["name"], "price": item["price"], "quantity": 1 } break return update_menu_display(), update_cart_summary_bar() # Function to remove an item from the cart def remove_from_cart(item_name): if item_name in cart: cart[item_name]["quantity"] -= 1 if cart[item_name]["quantity"] == 0: del cart[item_name] return update_menu_display(), update_cart_summary_bar() # Function to update the menu display dynamically def update_menu_display(): menu_html = "" for item in menu_data: if item["name"] in cart: # Show quantity controls if the item is in the cart menu_html += f"""
{item['description']}
{item['description']}