Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,85 +2,87 @@ import gradio as gr
|
|
| 2 |
|
| 3 |
# Menu data with all details
|
| 4 |
menu_data = {
|
| 5 |
-
"
|
| 6 |
-
{"name": "Veg Burger", "category": "
|
|
|
|
| 7 |
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
|
| 8 |
"price": "$8.99", "spice_level": "Medium", "portion_size": "Regular"},
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 11 |
"price": "$12.99", "spice_level": "High", "portion_size": "Large"},
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 14 |
"price": "$10.99", "spice_level": "Mild", "portion_size": "Medium"},
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 17 |
"price": "$14.99", "spice_level": "Medium", "portion_size": "Large"}
|
| 18 |
]
|
| 19 |
}
|
| 20 |
|
| 21 |
-
#
|
| 22 |
def filter_dishes(category):
|
| 23 |
if category == "ALL":
|
| 24 |
-
return [dish["name"] for dish in menu_data["
|
| 25 |
-
|
| 26 |
-
return [dish["name"] for dish in menu_data["All"] if dish["category"] == "Vegan"]
|
| 27 |
-
elif category == "HALAL":
|
| 28 |
-
return [dish["name"] for dish in menu_data["All"] if dish["category"] == "Halal"]
|
| 29 |
-
return []
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
def
|
| 33 |
-
fallback_image = "https://via.placeholder.com/300x200.png?text=
|
| 34 |
-
for dish in menu_data["
|
| 35 |
if dish["name"] == dish_name:
|
| 36 |
return (
|
| 37 |
-
dish.get("image"
|
| 38 |
dish.get("description", "Description not available."),
|
| 39 |
dish.get("price", "N/A"),
|
| 40 |
dish.get("spice_level", "N/A"),
|
| 41 |
dish.get("portion_size", "N/A")
|
| 42 |
)
|
| 43 |
-
return fallback_image, "
|
| 44 |
|
| 45 |
-
#
|
| 46 |
def create_ui():
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 49 |
|
| 50 |
-
# Category
|
| 51 |
gr.Markdown("### Select a Category")
|
| 52 |
with gr.Row():
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
#
|
| 58 |
gr.Markdown("### Select a Dish")
|
| 59 |
dish_radio = gr.Radio(label="Available Dishes", choices=filter_dishes("ALL"))
|
| 60 |
|
| 61 |
-
# Dish Details
|
| 62 |
gr.Markdown("### Dish Details")
|
| 63 |
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 64 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 65 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
# Event: Update
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
# Event:
|
| 75 |
dish_radio.change(
|
| 76 |
-
fn=
|
| 77 |
inputs=dish_radio,
|
| 78 |
-
outputs=[dish_image, dish_description, dish_price,
|
| 79 |
)
|
| 80 |
|
| 81 |
return demo
|
| 82 |
|
| 83 |
-
#
|
| 84 |
if __name__ == "__main__":
|
| 85 |
-
|
| 86 |
-
interface.launch()
|
|
|
|
| 2 |
|
| 3 |
# Menu data with all details
|
| 4 |
menu_data = {
|
| 5 |
+
"ALL": [
|
| 6 |
+
{"name": "Veg Burger", "category": "VEGAN",
|
| 7 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
| 8 |
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
|
| 9 |
"price": "$8.99", "spice_level": "Medium", "portion_size": "Regular"},
|
| 10 |
+
|
| 11 |
+
{"name": "Chicken Biryani", "category": "HALAL",
|
| 12 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
|
| 13 |
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 14 |
"price": "$12.99", "spice_level": "High", "portion_size": "Large"},
|
| 15 |
+
|
| 16 |
+
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 17 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
|
| 18 |
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 19 |
"price": "$10.99", "spice_level": "Mild", "portion_size": "Medium"},
|
| 20 |
+
|
| 21 |
+
{"name": "Beef Steak", "category": "HALAL",
|
| 22 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
|
| 23 |
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 24 |
"price": "$14.99", "spice_level": "Medium", "portion_size": "Large"}
|
| 25 |
]
|
| 26 |
}
|
| 27 |
|
| 28 |
+
# Filter dishes by 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 |
+
# Show details for a selected dish
|
| 35 |
+
def show_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 |
+
return fallback_image, "No dish selected", "N/A", "N/A", "N/A"
|
| 47 |
|
| 48 |
+
# Gradio UI
|
| 49 |
def create_ui():
|
| 50 |
with gr.Blocks() as demo:
|
| 51 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 52 |
|
| 53 |
+
# Category Buttons
|
| 54 |
gr.Markdown("### Select a Category")
|
| 55 |
with gr.Row():
|
| 56 |
+
btn_all = gr.Button("ALL")
|
| 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 |
+
dish_spice = gr.Textbox(label="Spice Level", interactive=False)
|
| 70 |
+
dish_portion = gr.Textbox(label="Portion Size", interactive=False)
|
| 71 |
|
| 72 |
+
# Event: Update dish list when a category button is clicked
|
| 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 |
+
# Event: Display dish details when a dish is selected
|
| 78 |
dish_radio.change(
|
| 79 |
+
fn=show_dish_details,
|
| 80 |
inputs=dish_radio,
|
| 81 |
+
outputs=[dish_image, dish_description, dish_price, dish_spice, dish_portion]
|
| 82 |
)
|
| 83 |
|
| 84 |
return demo
|
| 85 |
|
| 86 |
+
# Run the app
|
| 87 |
if __name__ == "__main__":
|
| 88 |
+
create_ui().launch()
|
|
|