Spaces:
Build error
Build error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161117118119120import gradio as grimport pandas as pd
# Load menu data from Exceldef load_menu(): menu_file = "menu.xlsx" # Ensure this file exists in the same directory try: return pd.read_excel(menu_file) except Exception as e: raise ValueError(f"Error loading menu file: {e}")
# Main menu viewdef render_menu(preference): menu_data = load_menu()
if preference == "Halal/Non-Veg": filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] elif preference == "Vegetarian": filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)] elif preference == "Guilt-Free": filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)] else: filtered_data = menu_data
# Generate menu as a list of tuples (dish_name, button_label) return [{"label": f"{row['Dish Name']} - ${row['Price ($)']}", "value": row['Dish Name']} for _, row in filtered_data.iterrows()]
# Dish details viewdef render_dish_details(dish_name): menu_data = load_menu() dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0] return ( dish["Image URL"], dish_name, dish["Description"], dish["Price ($)"] )
# Add to cart functiondef add_to_cart(dish_name, spice_level, extras, quantity, special_instructions, cart): cart.append({ "name": dish_name, "spice_level": spice_level, "extras": extras, "quantity": quantity, "instructions": special_instructions }) return cart, f"Added {dish_name} to cart!"
# Gradio appdef app(): with gr.Blocks() as demo: cart_state = gr.State([])
# Menu page menu_dropdown = gr.Dropdown( label="Select a dish to view details", choices=[], interactive=True, ) menu_output = gr.Dropdown(interactive=True)
# Dish details view detailed_view = gr.Column(visible=False) dish_image = gr.Image() dish_name = gr.Markdown() dish_description = gr.Markdown() dish_price = gr.Markdown() spice_level = gr.Radio( choices=["Mild", "Medium", "Spicy"], label="Choose Spice Level", ) extras = gr.CheckboxGroup( choices=["Extra Raita", "Extra Salan", "Extra Fried Onion"], label="Choose Extras", ) quantity = gr.Number(label="Quantity", value=1, interactive=True) special_instructions = gr.Textbox( label="Special Instructions", placeholder="Add any special instructions here", ) add_button = gr.Button("Add to Cart") back_button = gr.Button("Back to Menu") cart_view = gr.HTML(value="Your cart is empty.")
# Show the menu def update_menu(preference): return render_menu(preference)
# Show dish details def show_dish_details(dish_name): img, name, desc, price = render_dish_details(dish_name) return ( gr.update(visible=False), gr.update(visible=True), img, f"## {name}", desc, f"**Price:** ${price}", )
# Add to cart def handle_add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart): updated_cart, message = add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart) cart_html = "<br>".join( [f"{item['quantity']}x {item['name']} - {item['spice_level']}" for item in updated_cart] ) return updated_cart, cart_html
# Update menu based on preference menu_dropdown.change( update_menu, inputs=["All"], outputs=[menu_view()], )
# Show dish details when an item is selected# Show dish details when an item is selected menu_dropdown.change( show_dish_details, inputs=[menu_dropdown],app.py+117-1