Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
# Load menu data | |
menu_data = pd.read_excel("menu.xlsx") | |
# Function to handle pop-up and cart updates | |
cart = [] | |
def show_item_details(item_name): | |
item = menu_data[menu_data["Dish Name"] == item_name].iloc[0] | |
return ( | |
item["Image URL"], | |
item["Dish Name"], | |
item["Price ($)"], | |
item["Description"], | |
) | |
def add_to_cart(item_name, quantity, spice_level, extras, special_instructions): | |
item = menu_data[menu_data["Dish Name"] == item_name].iloc[0] | |
cart.append( | |
{ | |
"name": item_name, | |
"price": item["Price ($)"], | |
"quantity": quantity, | |
"spice_level": spice_level, | |
"extras": extras, | |
"special_instructions": special_instructions, | |
} | |
) | |
return f"Added {item_name} to cart." | |
def get_cart(): | |
return pd.DataFrame(cart) | |
def clear_cart(): | |
global cart | |
cart = [] | |
return "Cart cleared." | |
# Gradio UI | |
def app(): | |
with gr.Blocks() as demo: | |
gr.Markdown("### Dynamic Menu with Preferences") | |
# Menu Section | |
with gr.Row(): | |
preference = gr.Radio( | |
["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], | |
label="Choose a Preference", | |
) | |
# Display Menu Items | |
with gr.Row(): | |
menu_output = gr.Column() | |
# Pop-up Modal | |
with gr.Modal() as popup: | |
popup_image = gr.Image() | |
popup_name = gr.Textbox(label="Dish Name", interactive=False) | |
popup_price = gr.Textbox(label="Price ($)", interactive=False) | |
popup_description = gr.Textbox(label="Description", interactive=False) | |
spice_level = gr.Radio( | |
[ | |
"American Mild", | |
"American Medium", | |
"American Spicy", | |
"Indian Mild", | |
"Indian Medium", | |
"Indian Spicy", | |
], | |
label="Choose a Spice Level", | |
) | |
extras = gr.CheckboxGroup( | |
["Extra Raita 4oz", "Extra Raita 8oz", "Extra Onion", "Extra Lemon"], | |
label="Extras", | |
) | |
special_instructions = gr.Textbox(label="Special Instructions") | |
quantity = gr.Slider(1, 10, value=1, step=1, label="Quantity") | |
add_button = gr.Button("Add to Cart") | |
# Cart Section | |
with gr.Row(): | |
cart_output = gr.Dataframe(headers=["Item", "Quantity", "Price"], value=[]) | |
checkout_button = gr.Button("Checkout") | |
clear_button = gr.Button("Clear Cart") | |
# Handlers | |
preference.change(filter_menu, inputs=[preference], outputs=[menu_output]) | |
add_button.click( | |
add_to_cart, | |
inputs=[ | |
popup_name, | |
quantity, | |
spice_level, | |
extras, | |
special_instructions, | |
], | |
outputs=[cart_output], | |
) | |
clear_button.click(clear_cart, outputs=[cart_output]) | |
return demo | |
if __name__ == "__main__": | |
app().launch() | |