Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
# Menu data with
|
| 4 |
menu_data = {
|
| 5 |
"All": [
|
| 6 |
{"name": "Veg Burger", "category": "Vegan", "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
@@ -18,7 +18,7 @@ menu_data = {
|
|
| 18 |
]
|
| 19 |
}
|
| 20 |
|
| 21 |
-
# Function to
|
| 22 |
def filter_dishes(category):
|
| 23 |
if category == "ALL":
|
| 24 |
return [dish["name"] for dish in menu_data["All"]]
|
|
@@ -28,53 +28,53 @@ def filter_dishes(category):
|
|
| 28 |
return [dish["name"] for dish in menu_data["All"] if dish["category"] == "Halal"]
|
| 29 |
return []
|
| 30 |
|
| 31 |
-
# Function to
|
| 32 |
def show_dish_details(dish_name):
|
| 33 |
for dish in menu_data["All"]:
|
| 34 |
if dish["name"] == dish_name:
|
| 35 |
-
return (
|
| 36 |
-
dish["image"],
|
| 37 |
-
dish["description"],
|
| 38 |
-
dish["price"],
|
| 39 |
-
dish["spice_level"],
|
| 40 |
-
dish["portion_size"]
|
| 41 |
-
)
|
| 42 |
return None, "Dish not found", "N/A", "N/A", "N/A"
|
| 43 |
|
| 44 |
-
# Gradio UI
|
| 45 |
def create_ui():
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
# Heading
|
| 48 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 49 |
-
|
| 50 |
# Category Selection Buttons
|
| 51 |
with gr.Row():
|
| 52 |
all_button = gr.Button("ALL")
|
| 53 |
vegan_button = gr.Button("VEGAN")
|
| 54 |
halal_button = gr.Button("HALAL")
|
| 55 |
-
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 61 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 62 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 63 |
dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
|
| 64 |
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 65 |
|
| 66 |
-
# Update
|
| 67 |
-
all_button.click(fn=lambda: filter_dishes("ALL"), outputs=
|
| 68 |
-
vegan_button.click(fn=lambda: filter_dishes("VEGAN"), outputs=
|
| 69 |
-
halal_button.click(fn=lambda: filter_dishes("HALAL"), outputs=
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
-
fn=show_dish_details,
|
| 74 |
-
inputs=dish_dropdown,
|
| 75 |
-
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
|
| 76 |
-
)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
return demo
|
| 79 |
|
| 80 |
# Launch the Gradio app
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Menu data with all details
|
| 4 |
menu_data = {
|
| 5 |
"All": [
|
| 6 |
{"name": "Veg Burger", "category": "Vegan", "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
|
|
| 18 |
]
|
| 19 |
}
|
| 20 |
|
| 21 |
+
# Function to filter dishes based on category
|
| 22 |
def filter_dishes(category):
|
| 23 |
if category == "ALL":
|
| 24 |
return [dish["name"] for dish in menu_data["All"]]
|
|
|
|
| 28 |
return [dish["name"] for dish in menu_data["All"] if dish["category"] == "Halal"]
|
| 29 |
return []
|
| 30 |
|
| 31 |
+
# Function to show dish details
|
| 32 |
def show_dish_details(dish_name):
|
| 33 |
for dish in menu_data["All"]:
|
| 34 |
if dish["name"] == dish_name:
|
| 35 |
+
return (dish["image"], dish["description"], dish["price"], dish["spice_level"], dish["portion_size"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return None, "Dish not found", "N/A", "N/A", "N/A"
|
| 37 |
|
| 38 |
+
# Main Gradio UI
|
| 39 |
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 |
with gr.Row():
|
| 46 |
all_button = gr.Button("ALL")
|
| 47 |
vegan_button = gr.Button("VEGAN")
|
| 48 |
halal_button = gr.Button("HALAL")
|
| 49 |
+
|
| 50 |
+
# Section 1: Menu 1 - Dish Names by Category
|
| 51 |
+
gr.Markdown("### Select Items by Category")
|
| 52 |
+
dish_list = gr.CheckboxGroup(label="Available Dishes", choices=filter_dishes("ALL"), interactive=True)
|
| 53 |
+
|
| 54 |
+
# Section 2: Menu 2 - Selected Items
|
| 55 |
+
gr.Markdown("### Selected Items")
|
| 56 |
+
selected_dishes = gr.Dropdown(label="Select a Dish to View Details", choices=[], interactive=True)
|
| 57 |
+
|
| 58 |
+
# Section 3: Dish Details
|
| 59 |
+
gr.Markdown("### Dish Details")
|
| 60 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 61 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 62 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 63 |
dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
|
| 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: Update selected_dishes dropdown when items are selected in dish_list
|
| 72 |
+
dish_list.change(fn=lambda x: x if x else [], inputs=dish_list, outputs=selected_dishes)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
# Event: Show dish details when a dish is selected from selected_dishes
|
| 75 |
+
selected_dishes.change(fn=show_dish_details, inputs=selected_dishes,
|
| 76 |
+
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 77 |
+
|
| 78 |
return demo
|
| 79 |
|
| 80 |
# Launch the Gradio app
|