Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,82 +1,86 @@
|
|
| 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 |
# Function to filter dishes based on category
|
| 26 |
def filter_dishes(category):
|
| 27 |
-
return [dish["name"] for dish in menu_data
|
| 28 |
|
| 29 |
-
# Function to
|
| 30 |
def get_dish_details(dish_name):
|
|
|
|
| 31 |
fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
if dish["name"] == dish_name:
|
| 34 |
return (
|
| 35 |
dish.get("image", fallback_image),
|
| 36 |
-
dish.get("description",
|
| 37 |
-
dish.get("price",
|
| 38 |
-
dish.get("spice_level",
|
| 39 |
-
dish.get("portion_size",
|
| 40 |
)
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
# Main Gradio
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 46 |
|
| 47 |
-
# Category
|
| 48 |
gr.Markdown("### Select a Category")
|
| 49 |
with gr.Row():
|
| 50 |
btn_all = gr.Button("ALL")
|
| 51 |
btn_vegan = gr.Button("VEGAN")
|
| 52 |
btn_halal = gr.Button("HALAL")
|
| 53 |
|
| 54 |
-
# Dish Selection
|
| 55 |
gr.Markdown("### Available Dishes")
|
| 56 |
dish_radio = gr.Radio(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
|
| 57 |
|
| 58 |
# Dish Details
|
| 59 |
gr.Markdown("### Dish Details")
|
| 60 |
-
dish_image = gr.Image(label="Dish Image")
|
| 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 |
-
#
|
| 67 |
def update_dishes(category):
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
-
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_radio)
|
| 71 |
-
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_radio)
|
| 72 |
-
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_radio)
|
| 73 |
|
| 74 |
-
#
|
| 75 |
dish_radio.change(
|
| 76 |
fn=get_dish_details,
|
| 77 |
inputs=dish_radio,
|
| 78 |
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
|
| 79 |
)
|
| 80 |
|
| 81 |
-
#
|
| 82 |
demo.launch()
|
|
|
|
| 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 |
+
{"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
|
| 24 |
def filter_dishes(category):
|
| 25 |
+
return [dish["name"] for dish in menu_data if category == "ALL" or dish["category"] == category]
|
| 26 |
|
| 27 |
+
# Function to fetch details for a selected dish
|
| 28 |
def get_dish_details(dish_name):
|
| 29 |
+
# Fallback values for missing or invalid data
|
| 30 |
fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
|
| 31 |
+
fallback_text = "Information not available"
|
| 32 |
+
|
| 33 |
+
# Find the selected dish
|
| 34 |
+
for dish in menu_data:
|
| 35 |
if dish["name"] == dish_name:
|
| 36 |
return (
|
| 37 |
dish.get("image", fallback_image),
|
| 38 |
+
dish.get("description", fallback_text),
|
| 39 |
+
dish.get("price", fallback_text),
|
| 40 |
+
dish.get("spice_level", fallback_text),
|
| 41 |
+
dish.get("portion_size", fallback_text),
|
| 42 |
)
|
| 43 |
+
# If dish is not found, return fallbacks
|
| 44 |
+
return fallback_image, fallback_text, fallback_text, fallback_text, fallback_text
|
| 45 |
|
| 46 |
+
# Main Gradio App
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 49 |
|
| 50 |
+
# Category Selection
|
| 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", interactive=True)
|
| 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 |
dish_spice_level = gr.Textbox(label="Spice Level", interactive=False)
|
| 67 |
dish_portion_size = gr.Textbox(label="Portion Size", interactive=False)
|
| 68 |
|
| 69 |
+
# Update the dish list when category buttons are clicked
|
| 70 |
def update_dishes(category):
|
| 71 |
+
new_dishes = filter_dishes(category)
|
| 72 |
+
return gr.update(choices=new_dishes, value=None), "", "", "", "", ""
|
| 73 |
|
| 74 |
+
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 75 |
+
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 76 |
+
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=[dish_radio, dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size])
|
| 77 |
|
| 78 |
+
# Update dish details when a dish is selected
|
| 79 |
dish_radio.change(
|
| 80 |
fn=get_dish_details,
|
| 81 |
inputs=dish_radio,
|
| 82 |
outputs=[dish_image, dish_description, dish_price, dish_spice_level, dish_portion_size]
|
| 83 |
)
|
| 84 |
|
| 85 |
+
# Run the Gradio app
|
| 86 |
demo.launch()
|