Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,49 +3,27 @@ import gradio as gr
|
|
| 3 |
# Extended menu data with dish details
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
-
"image": "https://
|
| 7 |
"description": "A delicious vegan burger with plant-based patty, lettuce, and tomato.",
|
| 8 |
"spice_level": "Medium", "portion_size": "Regular"},
|
| 9 |
{"name": "Chicken Biryani", "category": "HALAL",
|
| 10 |
-
"image": "https://
|
| 11 |
"description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces.",
|
| 12 |
"spice_level": "High", "portion_size": "Large"},
|
| 13 |
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 14 |
-
"image": "https://
|
| 15 |
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 16 |
"spice_level": "Mild", "portion_size": "Medium"},
|
| 17 |
{"name": "Beef Steak", "category": "HALAL",
|
| 18 |
-
"image": "https://
|
| 19 |
"description": "Juicy beef steak served with mashed potatoes and grilled vegetables.",
|
| 20 |
"spice_level": "Medium", "portion_size": "Large"},
|
| 21 |
{"name": "Mushroom Soup", "category": "VEGAN",
|
| 22 |
-
"image": "https://
|
| 23 |
"description": "Creamy mushroom soup with fresh herbs.",
|
| 24 |
"spice_level": "Mild", "portion_size": "Small"}
|
| 25 |
]
|
| 26 |
|
| 27 |
-
# Define available dishes and their portion sizes with image paths
|
| 28 |
-
dish_data = {
|
| 29 |
-
"Veg Burger": {
|
| 30 |
-
"main": "pizza_main.jpg",
|
| 31 |
-
"small": "pizza_small.jpg",
|
| 32 |
-
"medium": "pizza_medium.jpg",
|
| 33 |
-
"large": "pizza_large.jpg",
|
| 34 |
-
},
|
| 35 |
-
"Chicken Biryani": {
|
| 36 |
-
"main": "pizza_main.jpg",
|
| 37 |
-
"small": "pizza_small.jpg",
|
| 38 |
-
"medium": "pizza_medium.jpg",
|
| 39 |
-
"large": "pizza_large.jpg",
|
| 40 |
-
},
|
| 41 |
-
"Paneer Butter Masala": {
|
| 42 |
-
"main": "pizza_main.jpg",
|
| 43 |
-
"small": "pizza_small.jpg",
|
| 44 |
-
"medium": "pizza_medium.jpg",
|
| 45 |
-
"large": "pizza_large.jpg",
|
| 46 |
-
},
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
spice_options = ["🌶 Mild", "🌶🌶 Medium", "🌶🌶🌶 High"]
|
| 50 |
portion_options = ["🧆 Small", "🍽 Medium", "🍛 Large"]
|
| 51 |
|
|
@@ -63,7 +41,7 @@ def display_dishes(category):
|
|
| 63 |
html_content += f"""
|
| 64 |
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 65 |
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 66 |
-
onclick='selectDish(
|
| 67 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 68 |
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 69 |
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
|
@@ -74,16 +52,10 @@ def display_dishes(category):
|
|
| 74 |
|
| 75 |
# Function to fetch details of the selected dish
|
| 76 |
def get_dish_details(dish_name):
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
|
| 81 |
-
|
| 82 |
-
# Function to display the portion size image
|
| 83 |
-
def display_portion(dish_name, portion):
|
| 84 |
-
if dish_name in dish_data:
|
| 85 |
-
return dish_data[dish_name].get(portion, None)
|
| 86 |
-
return None
|
| 87 |
|
| 88 |
# Function to simulate placing an order
|
| 89 |
def place_order(dish_name, spice_level, portion_size):
|
|
@@ -104,16 +76,17 @@ with gr.Blocks() as demo:
|
|
| 104 |
gr.Markdown("### Available Dishes")
|
| 105 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
|
|
|
| 109 |
dish_image = gr.Image(label="Dish Image", height=200, width=200)
|
| 110 |
-
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 111 |
with gr.Column():
|
|
|
|
|
|
|
| 112 |
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="��� Medium")
|
| 113 |
-
portion_dropdown = gr.Radio(label="Select Portion Size", choices=
|
| 114 |
-
portion_image = gr.Image(label="Portion Size Image")
|
| 115 |
|
| 116 |
-
# Place Order Button
|
| 117 |
place_order_btn = gr.Button("Place Order")
|
| 118 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 119 |
|
|
@@ -125,19 +98,15 @@ with gr.Blocks() as demo:
|
|
| 125 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 126 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 127 |
|
| 128 |
-
# Event: Show dish details
|
| 129 |
def show_dish_details(dish_name):
|
| 130 |
-
image, name, description = get_dish_details(dish_name)
|
| 131 |
-
|
| 132 |
-
return image, name, description
|
| 133 |
|
| 134 |
# Hidden input to receive dish name from JavaScript
|
| 135 |
selected_dish_name = gr.Textbox(visible=False)
|
| 136 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 137 |
-
outputs=[dish_image, dish_name,
|
| 138 |
-
|
| 139 |
-
# Event: Display portion size image
|
| 140 |
-
portion_dropdown.change(fn=display_portion, inputs=[selected_dish_name, portion_dropdown], outputs=portion_image)
|
| 141 |
|
| 142 |
# Event: Place order button
|
| 143 |
place_order_btn.click(fn=place_order,
|
|
|
|
| 3 |
# Extended menu data with dish 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 |
"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 |
"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 |
"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 |
"spice_level": "Medium", "portion_size": "Large"},
|
| 21 |
{"name": "Mushroom Soup", "category": "VEGAN",
|
| 22 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Mushroom_Soup.jpg",
|
| 23 |
"description": "Creamy mushroom soup with fresh herbs.",
|
| 24 |
"spice_level": "Mild", "portion_size": "Small"}
|
| 25 |
]
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
spice_options = ["🌶 Mild", "🌶🌶 Medium", "🌶🌶🌶 High"]
|
| 28 |
portion_options = ["🧆 Small", "🍽 Medium", "🍛 Large"]
|
| 29 |
|
|
|
|
| 41 |
html_content += f"""
|
| 42 |
<div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
|
| 43 |
padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
|
| 44 |
+
onclick='selectDish("{dish['name']}")'>
|
| 45 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 46 |
style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
|
| 47 |
<h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
|
|
|
|
| 52 |
|
| 53 |
# Function to fetch details of the selected dish
|
| 54 |
def get_dish_details(dish_name):
|
| 55 |
+
for dish in menu_data:
|
| 56 |
+
if dish["name"] == dish_name:
|
| 57 |
+
return dish["image"], dish["name"], dish["description"], "🌶 Medium", "🍽 Medium"
|
| 58 |
+
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "N/A", "N/A"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Function to simulate placing an order
|
| 61 |
def place_order(dish_name, spice_level, portion_size):
|
|
|
|
| 76 |
gr.Markdown("### Available Dishes")
|
| 77 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 78 |
|
| 79 |
+
# Dish Details Section
|
| 80 |
+
gr.Markdown("### Dish Details")
|
| 81 |
+
with gr.Row():
|
| 82 |
dish_image = gr.Image(label="Dish Image", height=200, width=200)
|
|
|
|
| 83 |
with gr.Column():
|
| 84 |
+
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 85 |
+
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 86 |
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="��� Medium")
|
| 87 |
+
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="🍽 Medium")
|
|
|
|
| 88 |
|
| 89 |
+
# Place Order Button
|
| 90 |
place_order_btn = gr.Button("Place Order")
|
| 91 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 92 |
|
|
|
|
| 98 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 99 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 100 |
|
| 101 |
+
# Event: Show dish details when a dish is selected
|
| 102 |
def show_dish_details(dish_name):
|
| 103 |
+
image, name, description, spice, portion = get_dish_details(dish_name)
|
| 104 |
+
return image, name, description, spice, portion
|
|
|
|
| 105 |
|
| 106 |
# Hidden input to receive dish name from JavaScript
|
| 107 |
selected_dish_name = gr.Textbox(visible=False)
|
| 108 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 109 |
+
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown])
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Event: Place order button
|
| 112 |
place_order_btn.click(fn=place_order,
|