Spaces:
Sleeping
Sleeping
File size: 3,188 Bytes
9e00c78 93316a5 9e00c78 93316a5 9e00c78 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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() |