Spaces:
Build error
Build error
Update app.py
Browse files33 unmodified lines34353637383940414243444546474849505152535455561 unmodified line58596061626364656667686970711 unmodified line7374757677781 unmodified line808182838485868788899091929333 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']}" onclick="select('{item['Dish Name']}')" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button></div></div>"""return html_content# Function to render detailed view of a dishdef render_dish_details(dish_name):print(f"Selected dish: {dish_name}") # Debugging linemenu_data = load_menu()try:dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]return (dish["Image URL"], # Dish imagef"## {dish_name}", # Dish namedish["Description"], # Descriptionf"${dish['Price ($)']}" # Price)except IndexError:raise ValueError(f"Dish '{dish_name}' not found!")1 unmodified line# Gradio app definitiondef app():with gr.Blocks() as demo:gr.Markdown("## Menu with Suggestions")selected_dish = gr.State("") # Track the selected dish name# Menu pagemenu_html = gr.HTML(value=filter_menu("All"))# Suggestion pagesuggestion_page = gr.Column(visible=False)dish_image = gr.Image(label="Dish Image")dish_name = gr.Markdown()1 unmodified linedish_price = gr.Markdown()# Functionsdef show_suggestion(dish_name):try:img, name, desc, price = render_dish_details(dish_name)1 unmodified linegr.update(visible=False),gr.update(visible=True),img,name,desc,price,)except ValueError as e:return gr.update(value=f"<p style='color:red;'>Error: {str(e)}</p>")# Event Handlersmenu_html.change(show_suggestion,inputs=[selected_dish],33 unmodified lines34353637383940414243444546474849505152535455561 unmodified line585960616263646566676869707172737475761 unmodified line7879808182838485861 unmodified line88899091929394959697989910010110210310410510610710810911011111211311433 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']}" onclick="selectDish('{item['Dish Name']}')" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button></div></div>"""return html_content# Function to render dish details for the suggestion pagedef render_dish_details(dish_name):print(f"Dish name received: {dish_name}") # Debugging linemenu_data = load_menu()try:dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]return (dish["Image URL"],dish_name,dish["Description"],f"${dish['Price ($)']}")except IndexError:raise ValueError(f"Dish '{dish_name}' not found!")1 unmodified line# Gradio app definitiondef app():with gr.Blocks() as demo:gr.Markdown("## Menu with Dynamic Filters")selected_dish = gr.State("") # State for the selected dish name# Menu componentspreference_selector = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],value="All",label="Choose a Preference")menu_html = gr.HTML(value=filter_menu("All"))# Suggestion page componentssuggestion_page = gr.Column(visible=False)dish_image = gr.Image(label="Dish Image")dish_name = gr.Markdown()1 unmodified linedish_price = gr.Markdown()# Functionsdef update_menu(preference):return filter_menu(preference)def show_suggestion(dish_name):try:img, name, desc, price = render_dish_details(dish_name)1 unmodified linegr.update(visible=False),gr.update(visible=True),img,f"## {name}",desc,price)except ValueError as e:return (gr.update(visible=True),gr.update(visible=False),"",f"Error: {str(e)}","","")# Event Handlerspreference_selector.change(update_menu,inputs=[preference_selector],outputs=[menu_html])menu_html.change(show_suggestion,inputs=[selected_dish],
app.py+35-14