Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,25 +25,26 @@ menu_data = {
|
|
| 25 |
]
|
| 26 |
}
|
| 27 |
|
| 28 |
-
# Filter dishes
|
| 29 |
def filter_dishes(category):
|
| 30 |
if category == "ALL":
|
| 31 |
return [dish["name"] for dish in menu_data["ALL"]]
|
| 32 |
return [dish["name"] for dish in menu_data["ALL"] if dish["category"] == category]
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
def
|
| 36 |
fallback_image = "https://via.placeholder.com/300x200.png?text=Image+Not+Found"
|
| 37 |
for dish in menu_data["ALL"]:
|
| 38 |
if dish["name"] == dish_name:
|
| 39 |
return (
|
| 40 |
-
dish["image"] if dish.get("image") else fallback_image,
|
| 41 |
-
dish.get("description", "Description not available
|
| 42 |
dish.get("price", "N/A"),
|
| 43 |
dish.get("spice_level", "N/A"),
|
| 44 |
dish.get("portion_size", "N/A")
|
| 45 |
)
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
# Gradio UI
|
| 49 |
def create_ui():
|
|
@@ -57,28 +58,28 @@ def create_ui():
|
|
| 57 |
btn_vegan = gr.Button("VEGAN")
|
| 58 |
btn_halal = gr.Button("HALAL")
|
| 59 |
|
| 60 |
-
# Dish Selection Radio Buttons
|
| 61 |
gr.Markdown("### Select a Dish")
|
| 62 |
-
dish_radio = gr.Radio(label="Available Dishes", choices=filter_dishes("ALL"))
|
| 63 |
|
| 64 |
# Dish Details
|
| 65 |
gr.Markdown("### Dish Details")
|
| 66 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 67 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 68 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
#
|
| 73 |
btn_all.click(fn=lambda: filter_dishes("ALL"), outputs=dish_radio)
|
| 74 |
btn_vegan.click(fn=lambda: filter_dishes("VEGAN"), outputs=dish_radio)
|
| 75 |
btn_halal.click(fn=lambda: filter_dishes("HALAL"), outputs=dish_radio)
|
| 76 |
|
| 77 |
-
#
|
| 78 |
dish_radio.change(
|
| 79 |
-
fn=
|
| 80 |
inputs=dish_radio,
|
| 81 |
-
outputs=[dish_image, dish_description, dish_price,
|
| 82 |
)
|
| 83 |
|
| 84 |
return demo
|
|
|
|
| 25 |
]
|
| 26 |
}
|
| 27 |
|
| 28 |
+
# Filter dishes based on the category
|
| 29 |
def filter_dishes(category):
|
| 30 |
if category == "ALL":
|
| 31 |
return [dish["name"] for dish in menu_data["ALL"]]
|
| 32 |
return [dish["name"] for dish in menu_data["ALL"] if dish["category"] == category]
|
| 33 |
|
| 34 |
+
# Display details for the selected dish
|
| 35 |
+
def get_dish_details(dish_name):
|
| 36 |
fallback_image = "https://via.placeholder.com/300x200.png?text=Image+Not+Found"
|
| 37 |
for dish in menu_data["ALL"]:
|
| 38 |
if dish["name"] == dish_name:
|
| 39 |
return (
|
| 40 |
+
dish["image"] if dish.get("image") else fallback_image,
|
| 41 |
+
dish.get("description", "Description not available"),
|
| 42 |
dish.get("price", "N/A"),
|
| 43 |
dish.get("spice_level", "N/A"),
|
| 44 |
dish.get("portion_size", "N/A")
|
| 45 |
)
|
| 46 |
+
# If no dish matches
|
| 47 |
+
return fallback_image, "Dish not found", "N/A", "N/A", "N/A"
|
| 48 |
|
| 49 |
# Gradio UI
|
| 50 |
def create_ui():
|
|
|
|
| 58 |
btn_vegan = gr.Button("VEGAN")
|
| 59 |
btn_halal = gr.Button("HALAL")
|
| 60 |
|
| 61 |
+
# Dish Selection with Radio Buttons
|
| 62 |
gr.Markdown("### Select a Dish")
|
| 63 |
+
dish_radio = gr.Radio(label="Available Dishes", choices=filter_dishes("ALL"), interactive=True)
|
| 64 |
|
| 65 |
# Dish Details
|
| 66 |
gr.Markdown("### Dish Details")
|
| 67 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 68 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 69 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 70 |
+
dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
|
| 71 |
+
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 72 |
|
| 73 |
+
# Update dish list based on category
|
| 74 |
btn_all.click(fn=lambda: filter_dishes("ALL"), outputs=dish_radio)
|
| 75 |
btn_vegan.click(fn=lambda: filter_dishes("VEGAN"), outputs=dish_radio)
|
| 76 |
btn_halal.click(fn=lambda: filter_dishes("HALAL"), outputs=dish_radio)
|
| 77 |
|
| 78 |
+
# Show dish details when a dish is selected
|
| 79 |
dish_radio.change(
|
| 80 |
+
fn=get_dish_details,
|
| 81 |
inputs=dish_radio,
|
| 82 |
+
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
|
| 83 |
)
|
| 84 |
|
| 85 |
return demo
|