Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,22 +2,10 @@ import gradio as gr
|
|
| 2 |
|
| 3 |
# Menu data
|
| 4 |
menu_data = [
|
| 5 |
-
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
{"name": "Chicken Biryani", "category": "HALAL",
|
| 10 |
-
"image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
|
| 11 |
-
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 12 |
-
"price": "$12.99", "spice_level": "High", "portion_size": "Large"},
|
| 13 |
-
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 14 |
-
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
|
| 15 |
-
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 16 |
-
"price": "$10.99", "spice_level": "Mild", "portion_size": "Medium"},
|
| 17 |
-
{"name": "Beef Steak", "category": "HALAL",
|
| 18 |
-
"image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
|
| 19 |
-
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 20 |
-
"price": "$14.99", "spice_level": "Medium", "portion_size": "Large"}
|
| 21 |
]
|
| 22 |
|
| 23 |
# Function to filter dishes based on category
|
|
@@ -26,22 +14,7 @@ def filter_dishes(category):
|
|
| 26 |
return [dish["name"] for dish in menu_data]
|
| 27 |
return [dish["name"] for dish in menu_data if dish["category"] == category]
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
def get_dish_details(dish_name):
|
| 31 |
-
fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
|
| 32 |
-
fallback_text = "Information not available"
|
| 33 |
-
for dish in menu_data:
|
| 34 |
-
if dish["name"] == dish_name:
|
| 35 |
-
return (
|
| 36 |
-
dish.get("image", fallback_image),
|
| 37 |
-
dish.get("description", fallback_text),
|
| 38 |
-
dish.get("price", fallback_text),
|
| 39 |
-
dish.get("spice_level", fallback_text),
|
| 40 |
-
dish.get("portion_size", fallback_text)
|
| 41 |
-
)
|
| 42 |
-
return fallback_image, fallback_text, fallback_text, fallback_text, fallback_text
|
| 43 |
-
|
| 44 |
-
# Main Gradio app
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 47 |
|
|
@@ -52,35 +25,19 @@ with gr.Blocks() as demo:
|
|
| 52 |
btn_vegan = gr.Button("VEGAN")
|
| 53 |
btn_halal = gr.Button("HALAL")
|
| 54 |
|
| 55 |
-
# Dropdown for
|
| 56 |
gr.Markdown("### Available Dishes")
|
| 57 |
-
dish_dropdown = gr.Dropdown(choices=
|
| 58 |
-
|
| 59 |
-
# Dish details
|
| 60 |
-
gr.Markdown("### Dish Details")
|
| 61 |
-
dish_image = gr.Image(label="Dish Image")
|
| 62 |
-
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 63 |
-
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 64 |
-
dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
|
| 65 |
-
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 66 |
|
| 67 |
# Function to update dropdown list based on category
|
| 68 |
def update_dropdown(category):
|
| 69 |
dishes = filter_dishes(category)
|
| 70 |
return gr.update(choices=dishes, value=None)
|
| 71 |
|
| 72 |
-
# Function to update dish details
|
| 73 |
-
def update_dish_details(dish_name):
|
| 74 |
-
return get_dish_details(dish_name)
|
| 75 |
-
|
| 76 |
# Button events for category selection
|
| 77 |
btn_all.click(fn=lambda: update_dropdown("ALL"), outputs=dish_dropdown)
|
| 78 |
btn_vegan.click(fn=lambda: update_dropdown("VEGAN"), outputs=dish_dropdown)
|
| 79 |
btn_halal.click(fn=lambda: update_dropdown("HALAL"), outputs=dish_dropdown)
|
| 80 |
|
| 81 |
-
# Dish dropdown event for displaying details
|
| 82 |
-
dish_dropdown.change(fn=update_dish_details, inputs=dish_dropdown,
|
| 83 |
-
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 84 |
-
|
| 85 |
# Launch the app
|
| 86 |
demo.launch()
|
|
|
|
| 2 |
|
| 3 |
# Menu data
|
| 4 |
menu_data = [
|
| 5 |
+
{"name": "Veg Burger", "category": "VEGAN"},
|
| 6 |
+
{"name": "Chicken Biryani", "category": "HALAL"},
|
| 7 |
+
{"name": "Paneer Butter Masala", "category": "VEGAN"},
|
| 8 |
+
{"name": "Beef Steak", "category": "HALAL"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
]
|
| 10 |
|
| 11 |
# Function to filter dishes based on category
|
|
|
|
| 14 |
return [dish["name"] for dish in menu_data]
|
| 15 |
return [dish["name"] for dish in menu_data if dish["category"] == category]
|
| 16 |
|
| 17 |
+
# Main Gradio App
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 20 |
|
|
|
|
| 25 |
btn_vegan = gr.Button("VEGAN")
|
| 26 |
btn_halal = gr.Button("HALAL")
|
| 27 |
|
| 28 |
+
# Dropdown for Dish Selection
|
| 29 |
gr.Markdown("### Available Dishes")
|
| 30 |
+
dish_dropdown = gr.Dropdown(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Function to update dropdown list based on category
|
| 33 |
def update_dropdown(category):
|
| 34 |
dishes = filter_dishes(category)
|
| 35 |
return gr.update(choices=dishes, value=None)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Button events for category selection
|
| 38 |
btn_all.click(fn=lambda: update_dropdown("ALL"), outputs=dish_dropdown)
|
| 39 |
btn_vegan.click(fn=lambda: update_dropdown("VEGAN"), outputs=dish_dropdown)
|
| 40 |
btn_halal.click(fn=lambda: update_dropdown("HALAL"), outputs=dish_dropdown)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# Launch the app
|
| 43 |
demo.launch()
|