Spaces:
Build error
Build error
Update app.py
Browse files123445677891014 unmodified lines25262728282930319 unmodified lines41424344444546464748492 unmodified lines52535455555657575859601 unmodified line62636465656667686 unmodified lines757677787879808182828384854 unmodified lines909192939394959613 unmodified lines110111112113113114115116import gradio as grimport pandas as pd
# Load menu data from Excel# Function to load menu data from Exceldef load_menu(): try: return pd.read_excel("menu.xlsx") # Ensure menu.xlsx is in the same directory return pd.read_excel("menu.xlsx") # Ensure menu.xlsx exists in the same directory except Exception as e: raise ValueError(f"Error loading menu file: {e}")
14 unmodified lines for _, item in filtered_data.iterrows(): html_content += f""" <div class="menu-item"> <img src="{item['Image URL']}" alt="{item['Dish Name']}"> <img src="{item['Image URL']}" alt="{item['Dish Name']}" class="dish-image"> <h3>{item['Dish Name']}</h3> <p>{item['Description']}</p> <p><strong>${item['Price ($)']}</strong></p>9 unmodified lines dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0] return ( dish["Image URL"], dish["Dish Name"], dish_name, dish["Description"], dish["Price ($)"], f"${dish['Price ($)']}", dish["Ingredients"] ) except IndexError:2 unmodified lines# Main Gradio appdef app(): with gr.Blocks(css="style.css") as demo: gr.Markdown("## Dynamic Menu with Modal Suggestion Page") gr.Markdown("## Dynamic Menu with Modal Window")
# Menu section # Home page menu preference_selector = gr.Radio( choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], value="All",1 unmodified line ) menu_output = gr.HTML(value=filter_menu("All"))
# Modal window (suggestion page, hidden by default) # Modal (hidden by default) modal = gr.Column(visible=False, elem_classes=["popup"]) modal_image = gr.Image(label="Dish Image") modal_name = gr.Markdown()6 unmodified lines add_to_cart_button = gr.Button("Add to Cart") close_modal_button = gr.Button("Close")
# Cart section # Cart cart_state = gr.State([]) cart_output = gr.HTML(value="Your cart is empty.")
# Event handlers # Handlers def update_menu(preference): return filter_menu(preference)
4 unmodified lines img, f"### {name}", f"**Description:** {desc}\n\n**Ingredients:** {ingredients}", f"**Price:** ${price}" price )
def close_modal():13 unmodified lines ) return cart, cart_html
# Event wiring # Events preference_selector.change(update_menu, inputs=[preference_selector], outputs=[menu_output]) menu_output.change(show_modal, inputs=[menu_output], outputs=[modal, modal_image, modal_name, modal_description, modal_price]) close_modal_button.click(close_modal, outputs=[modal])app.py+12-12