Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,10 +29,13 @@ def filter_dishes(category):
|
|
| 29 |
return []
|
| 30 |
|
| 31 |
# Function to show dish details
|
| 32 |
-
def show_dish_details(
|
|
|
|
|
|
|
|
|
|
| 33 |
for dish in menu_data["All"]:
|
| 34 |
-
if dish["name"] ==
|
| 35 |
-
return
|
| 36 |
return None, "Dish not found", "N/A", "N/A", "N/A"
|
| 37 |
|
| 38 |
# Main Gradio UI
|
|
@@ -40,18 +43,18 @@ def create_ui():
|
|
| 40 |
with gr.Blocks() as demo:
|
| 41 |
# Heading
|
| 42 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 43 |
-
|
| 44 |
# Category Selection Buttons
|
| 45 |
gr.Markdown("### Select a Category")
|
| 46 |
with gr.Row():
|
| 47 |
all_button = gr.Button("ALL")
|
| 48 |
vegan_button = gr.Button("VEGAN")
|
| 49 |
halal_button = gr.Button("HALAL")
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
gr.Markdown("### Select a Dish")
|
| 53 |
-
|
| 54 |
-
|
| 55 |
# Dish Details
|
| 56 |
gr.Markdown("### Dish Details")
|
| 57 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
|
@@ -61,13 +64,13 @@ def create_ui():
|
|
| 61 |
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 62 |
|
| 63 |
# Event: Update dish list based on category buttons
|
| 64 |
-
all_button.click(fn=lambda: filter_dishes("ALL"), outputs=
|
| 65 |
-
vegan_button.click(fn=lambda: filter_dishes("VEGAN"), outputs=
|
| 66 |
-
halal_button.click(fn=lambda: filter_dishes("HALAL"), outputs=
|
| 67 |
|
| 68 |
# Event: Show dish details when a dish is selected
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
return demo
|
| 73 |
|
|
|
|
| 29 |
return []
|
| 30 |
|
| 31 |
# Function to show dish details
|
| 32 |
+
def show_dish_details(selected_dishes):
|
| 33 |
+
if not selected_dishes:
|
| 34 |
+
return None, "", "", "", "" # Clear the details if no dish is selected
|
| 35 |
+
selected_dish_name = selected_dishes[-1] # Show details for the last selected dish
|
| 36 |
for dish in menu_data["All"]:
|
| 37 |
+
if dish["name"] == selected_dish_name:
|
| 38 |
+
return dish["image"], dish["description"], dish["price"], dish["spice_level"], dish["portion_size"]
|
| 39 |
return None, "Dish not found", "N/A", "N/A", "N/A"
|
| 40 |
|
| 41 |
# Main Gradio UI
|
|
|
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
# Heading
|
| 45 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 46 |
+
|
| 47 |
# Category Selection Buttons
|
| 48 |
gr.Markdown("### Select a Category")
|
| 49 |
with gr.Row():
|
| 50 |
all_button = gr.Button("ALL")
|
| 51 |
vegan_button = gr.Button("VEGAN")
|
| 52 |
halal_button = gr.Button("HALAL")
|
| 53 |
+
|
| 54 |
+
# Checkbox Group for Available Dishes
|
| 55 |
gr.Markdown("### Select a Dish")
|
| 56 |
+
dish_list = gr.CheckboxGroup(label="Available Dishes", choices=filter_dishes("ALL"), interactive=True)
|
| 57 |
+
|
| 58 |
# Dish Details
|
| 59 |
gr.Markdown("### Dish Details")
|
| 60 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
|
|
|
| 64 |
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 65 |
|
| 66 |
# Event: Update dish list based on category buttons
|
| 67 |
+
all_button.click(fn=lambda: filter_dishes("ALL"), outputs=dish_list)
|
| 68 |
+
vegan_button.click(fn=lambda: filter_dishes("VEGAN"), outputs=dish_list)
|
| 69 |
+
halal_button.click(fn=lambda: filter_dishes("HALAL"), outputs=dish_list)
|
| 70 |
|
| 71 |
# Event: Show dish details when a dish is selected
|
| 72 |
+
dish_list.change(fn=show_dish_details, inputs=dish_list,
|
| 73 |
+
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 74 |
|
| 75 |
return demo
|
| 76 |
|