Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
@@ -26,25 +26,25 @@ def filter_dishes(category):
|
|
| 26 |
|
| 27 |
# Function to get dish details
|
| 28 |
def get_dish_details(dish_name):
|
| 29 |
-
fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image"
|
| 30 |
for dish in menu_data:
|
| 31 |
if dish["name"] == dish_name:
|
| 32 |
return (
|
| 33 |
dish.get("image", fallback_image),
|
| 34 |
-
dish.get("description", "
|
| 35 |
dish.get("price", "N/A"),
|
| 36 |
dish.get("spice_level", "N/A"),
|
| 37 |
-
dish.get("portion_size", "N/A")
|
| 38 |
)
|
| 39 |
-
return fallback_image, "Dish not found", "N/A", "N/A", "N/A"
|
| 40 |
|
| 41 |
-
# Gradio app
|
| 42 |
def create_ui():
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 45 |
|
| 46 |
-
# Category Buttons
|
| 47 |
-
gr.Markdown("### Select a Category")
|
| 48 |
with gr.Row():
|
| 49 |
btn_all = gr.Button("ALL")
|
| 50 |
btn_vegan = gr.Button("VEGAN")
|
|
@@ -54,31 +54,33 @@ def create_ui():
|
|
| 54 |
gr.Markdown("### Available Dishes")
|
| 55 |
dish_dropdown = gr.Dropdown(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
|
| 56 |
|
| 57 |
-
# Dish Details
|
| 58 |
gr.Markdown("### Dish Details")
|
| 59 |
-
dish_image = gr.Image(label="Dish Image")
|
| 60 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 61 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
def
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
)
|
| 79 |
|
| 80 |
return demo
|
| 81 |
|
| 82 |
-
#
|
| 83 |
if __name__ == "__main__":
|
| 84 |
create_ui().launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Static menu data
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
|
|
| 26 |
|
| 27 |
# Function to get dish details
|
| 28 |
def get_dish_details(dish_name):
|
| 29 |
+
fallback_image = "https://via.placeholder.com/300x200.png?text=No+Image+Available"
|
| 30 |
for dish in menu_data:
|
| 31 |
if dish["name"] == dish_name:
|
| 32 |
return (
|
| 33 |
dish.get("image", fallback_image),
|
| 34 |
+
dish.get("description", "No description available."),
|
| 35 |
dish.get("price", "N/A"),
|
| 36 |
dish.get("spice_level", "N/A"),
|
| 37 |
+
dish.get("portion_size", "N/A"),
|
| 38 |
)
|
| 39 |
+
return fallback_image, "Dish not found.", "N/A", "N/A", "N/A"
|
| 40 |
|
| 41 |
+
# Main Gradio app
|
| 42 |
def create_ui():
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.HTML("<h1 style='text-align: center;'>Biryani Hub Menu</h1>")
|
| 45 |
|
| 46 |
+
# Category Selection Buttons
|
| 47 |
+
gr.Markdown("### Select a Category to View Available Dishes")
|
| 48 |
with gr.Row():
|
| 49 |
btn_all = gr.Button("ALL")
|
| 50 |
btn_vegan = gr.Button("VEGAN")
|
|
|
|
| 54 |
gr.Markdown("### Available Dishes")
|
| 55 |
dish_dropdown = gr.Dropdown(choices=filter_dishes("ALL"), label="Select a Dish", interactive=True)
|
| 56 |
|
| 57 |
+
# Dish Details Section
|
| 58 |
gr.Markdown("### Dish Details")
|
| 59 |
+
dish_image = gr.Image(label="Dish Image", type="pil")
|
| 60 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 61 |
dish_price = gr.Textbox(label="Price", interactive=False)
|
| 62 |
+
dish_spice = gr.Textbox(label="Spice Level", interactive=False)
|
| 63 |
+
dish_portion = gr.Textbox(label="Portion Size", interactive=False)
|
| 64 |
|
| 65 |
+
# Function to update dropdown list based on category
|
| 66 |
+
def update_dropdown(category):
|
| 67 |
+
dishes = filter_dishes(category)
|
| 68 |
+
return gr.update(choices=dishes, value=None), "Select a dish to view details", "", "", "", ""
|
| 69 |
|
| 70 |
+
# Connect category buttons to dropdown update
|
| 71 |
+
btn_all.click(fn=lambda: update_dropdown("ALL"), outputs=[dish_dropdown, dish_description, dish_price, dish_spice, dish_portion, dish_image])
|
| 72 |
+
btn_vegan.click(fn=lambda: update_dropdown("VEGAN"), outputs=[dish_dropdown, dish_description, dish_price, dish_spice, dish_portion, dish_image])
|
| 73 |
+
btn_halal.click(fn=lambda: update_dropdown("HALAL"), outputs=[dish_dropdown, dish_description, dish_price, dish_spice, dish_portion, dish_image])
|
| 74 |
|
| 75 |
+
# Update dish details when a dish is selected
|
| 76 |
+
def show_dish_details(dish_name):
|
| 77 |
+
image, description, price, spice_level, portion_size = get_dish_details(dish_name)
|
| 78 |
+
return image, description, price, spice_level, portion_size
|
| 79 |
+
|
| 80 |
+
dish_dropdown.change(fn=show_dish_details, inputs=dish_dropdown, outputs=[dish_image, dish_description, dish_price, dish_spice, dish_portion])
|
| 81 |
|
| 82 |
return demo
|
| 83 |
|
| 84 |
+
# Launch the app
|
| 85 |
if __name__ == "__main__":
|
| 86 |
create_ui().launch()
|