import gradio as gr from utils.excel_operations import read_excel from utils.state_management import state def menu_page(): def get_filtered_menu(): user = state.get("user") if not user: return "Please log in first!" preferences = user["Preferences"] allergies = user["Allergies"].split(",") menu = read_excel("data/menu.xlsx") filtered_menu = [ item for item in menu if preferences in item["Category"] and not any(allergen in allergies for allergen in item["Allergens"]) ] return filtered_menu def add_to_cart(item, spice_level): cart = state.get("cart", []) cart.append({"Item": item, "Spice Level": spice_level}) state["cart"] = cart return "Added to cart!" menu_items = get_filtered_menu() with gr.Group(): gr.Markdown("### Menu") if isinstance(menu_items, str): gr.Label(menu_items) # Display message if menu_items is a string (e.g., "Please log in first!") else: for item in menu_items: with gr.Row(): # Use gr.Row to display menu items gr.Image(item["Image"], label=item["Name"]) gr.Text(f"{item['Price']} ₹") spice_level = gr.Radio(["Mild 🌶️", "Medium 🌶️🌶️", "High 🌶️🌶️🌶️"], label="Spice Level") add_button = gr.Button("Add to Cart") add_button.click(add_to_cart, inputs=[item["Name"], spice_level], outputs=gr.Label("Status"))