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