Spaces:
Build error
Build error
Update app.py
Browse files10 unmodified lines1112131414151716171815 unmodified lines343536394037383940412 unmodified lines44454647495051525354554849505152535455565758597 unmodified lines6768696970707172727374757615 unmodified lines92939494959697982 unmodified lines10110210310410310410510610710810911011111211311411511611711811912012112212312412518 unmodified lines1441451461291471481491501511521531541551561578 unmodified lines16616716814416917017117210 unmodified lines
# Function to filter menu items based on preferencedef filter_menu(preference): # Load menu data menu_data = load_menu()
# Define filter conditions 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":15 unmodified lines </div> <div style="flex-shrink: 0; text-align: center;"> <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;"> <button value="{item['Dish Name']}" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="return '{item['Dish Name']}'">Add</button> <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" value="{item['Dish Name']}">Add</button> </div> </div> """2 unmodified lines# Function to render detailed view of a dishdef render_dish_details(dish_name): menu_data = load_menu() try: dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0] return ( dish["Image URL"], f"## {dish_name}", dish["Description"], f"**Price:** ${dish['Price ($)']}" ) dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0] return ( dish["Image URL"], # Image of the dish f"## {dish_name}", # Dish name dish["Description"], # Description f"**Price:** ${dish['Price ($)']}" # Price ) except IndexError: raise ValueError(f"Dish '{dish_name}' not found!")
# Gradio app definitiondef app():7 unmodified lines label="Choose a Preference", )
# Output area for menu items menu_output = gr.HTML(value=filter_menu("All")) # Main menu output area menu_output = gr.HTML(value=filter_menu("All"), visible=True)
# Detailed view # Detailed view components detailed_view = gr.Column(visible=False) dish_image = gr.Image() dish_name = gr.Markdown()15 unmodified lines add_to_bag_button = gr.Button("Add to Bag") back_button = gr.Button("Back to Menu")
# Cart # Cart state and display cart_state = gr.State([]) cart_output = gr.HTML(value="Your cart is empty.")
2 unmodified lines return filter_menu(preference)
def show_dish_details(dish_name): try: img, name, desc, price = render_dish_details(dish_name) return gr.update(visible=False), gr.update(visible=True), img, name, desc, price img, name, desc, price = render_dish_details(dish_name) return ( gr.update(visible=False), # Hide menu gr.update(visible=True), # Show detailed view img, name, desc, price, ) except ValueError as e: return ( gr.update(visible=True), gr.update(visible=False), "", "Error: Dish not found.", "", "", )
def add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart): cart.append({18 unmodified lines menu_output.change( show_dish_details, inputs=[menu_output], outputs=[menu_output, detailed_view, dish_image, dish_name, dish_description, dish_price], outputs=[ menu_output, detailed_view, dish_image, dish_name, dish_description, dish_price, ], )
add_to_bag_button.click(8 unmodified lines )
# Layout with gr.Row(): with gr.Row(visible=True): menu_output
with detailed_view:app.py+44-19