Spaces:
Sleeping
Sleeping
File size: 1,596 Bytes
2791a10 decf4fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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"))
|