Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Extended menu data with dish details | |
| menu_data = [ | |
| {"name": "Veg Burger", "category": "VEGAN", | |
| "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg", | |
| "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.", | |
| "spice_level": "Medium", "portion_size": "Regular"}, | |
| {"name": "Chicken Biryani", "category": "HALAL", | |
| "image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg", | |
| "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.", | |
| "spice_level": "High", "portion_size": "Large"}, | |
| {"name": "Paneer Butter Masala", "category": "VEGAN", | |
| "image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg", | |
| "description": "Paneer cooked in a rich and creamy tomato-based gravy.", | |
| "spice_level": "Mild", "portion_size": "Medium"}, | |
| ] | |
| spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"] | |
| portion_options = ["π§ Small", "π½ Medium", "π Large"] | |
| def display_dishes(category): | |
| filtered_dishes = [dish for dish in menu_data if category == "ALL" or dish["category"] == category] | |
| html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>" | |
| for dish in filtered_dishes: | |
| html_content += f""" | |
| <div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd; | |
| padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;' | |
| onclick='selectDish("{dish['name']}")'> | |
| <img src='{dish['image']}' alt='{dish['name']}' | |
| style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'> | |
| <h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4> | |
| </div> | |
| """ | |
| html_content += "</div>" | |
| return html_content | |
| def get_dish_details(dish_name): | |
| for dish in menu_data: | |
| if dish["name"] == dish_name: | |
| return dish["image"], dish["name"], dish["description"], "πΆ Medium", "π½ Medium" | |
| return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "N/A", "N/A" | |
| def place_order(dish_name, spice_level, portion_size): | |
| return f"β Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size." | |
| with gr.Blocks() as demo: | |
| gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>") | |
| gr.HTML(""" | |
| <script> | |
| function selectDish(dishName) { | |
| let input = document.querySelector('input[aria-label="selected_dish_name"]'); | |
| if (input) { | |
| input.value = dishName; | |
| input.dispatchEvent(new Event('input', { bubbles: true })); | |
| } | |
| } | |
| </script> | |
| """) | |
| gr.Markdown("### Select a Category") | |
| with gr.Row(): | |
| btn_all = gr.Button("ALL") | |
| btn_vegan = gr.Button("VEGAN") | |
| btn_halal = gr.Button("HALAL") | |
| gr.Markdown("### Available Dishes") | |
| dish_display = gr.HTML(value=display_dishes("ALL")) | |
| popup = gr.Group(visible=False) | |
| with popup: | |
| with gr.Row(): | |
| dish_image = gr.Image(label="Dish Image", height=200, width=200) | |
| with gr.Column(): | |
| dish_name = gr.Textbox(label="Dish Name", interactive=False) | |
| dish_description = gr.Textbox(label="Description", interactive=False) | |
| spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="πΆ Medium") | |
| portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π½ Medium") | |
| close_popup = gr.Button("Close") | |
| place_order_btn = gr.Button("Place Order") | |
| order_status = gr.Textbox(label="Order Status", interactive=False) | |
| def update_dishes(category): | |
| return gr.update(value=display_dishes(category)) | |
| btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_display) | |
| btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display) | |
| btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display) | |
| selected_dish_name = gr.Textbox(visible=False) | |
| selected_dish_name.change( | |
| fn=lambda dish_name: (*get_dish_details(dish_name), gr.update(visible=True)), | |
| inputs=selected_dish_name, | |
| outputs=[dish_image, dish_name, dish_description, popup], | |
| ) | |
| close_popup.click(fn=lambda: gr.update(visible=False), outputs=popup) | |
| place_order_btn.click(fn=place_order, inputs=[dish_name, spice_dropdown, portion_dropdown], outputs=order_status) | |
| demo.launch() | |