Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
# Extended menu data with dish details
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
-
"image": "
|
| 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",
|
|
@@ -24,6 +24,28 @@ menu_data = [
|
|
| 24 |
"spice_level": "Mild", "portion_size": "Small"}
|
| 25 |
]
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 28 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 29 |
|
|
@@ -52,10 +74,16 @@ def display_dishes(category):
|
|
| 52 |
|
| 53 |
# Function to fetch details of the selected dish
|
| 54 |
def get_dish_details(dish_name):
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
# Function to simulate placing an order
|
| 61 |
def place_order(dish_name, spice_level, portion_size):
|
|
@@ -84,7 +112,8 @@ with gr.Blocks() as demo:
|
|
| 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=
|
|
|
|
| 88 |
|
| 89 |
# Place Order Button
|
| 90 |
place_order_btn = gr.Button("Place Order")
|
|
@@ -100,13 +129,16 @@ with gr.Blocks() as demo:
|
|
| 100 |
|
| 101 |
# Event: Show dish details when a dish is selected
|
| 102 |
def show_dish_details(dish_name):
|
| 103 |
-
image, name, description
|
| 104 |
-
return image, name, description
|
| 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
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Event: Place order button
|
| 112 |
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",
|
|
|
|
| 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": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
| 31 |
+
"small": "https://via.placeholder.com/150?text=Veg+Burger+Small",
|
| 32 |
+
"medium": "https://via.placeholder.com/150?text=Veg+Burger+Medium",
|
| 33 |
+
"large": "https://via.placeholder.com/150?text=Veg+Burger+Large",
|
| 34 |
+
},
|
| 35 |
+
"Chicken Biryani": {
|
| 36 |
+
"main": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
|
| 37 |
+
"small": "https://via.placeholder.com/150?text=Chicken+Biryani+Small",
|
| 38 |
+
"medium": "https://via.placeholder.com/150?text=Chicken+Biryani+Medium",
|
| 39 |
+
"large": "https://via.placeholder.com/150?text=Chicken+Biryani+Large",
|
| 40 |
+
},
|
| 41 |
+
"Paneer Butter Masala": {
|
| 42 |
+
"main": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
|
| 43 |
+
"small": "https://via.placeholder.com/150?text=Paneer+Small",
|
| 44 |
+
"medium": "https://via.placeholder.com/150?text=Paneer+Medium",
|
| 45 |
+
"large": "https://via.placeholder.com/150?text=Paneer+Large",
|
| 46 |
+
},
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 50 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 51 |
|
|
|
|
| 74 |
|
| 75 |
# Function to fetch details of the selected dish
|
| 76 |
def get_dish_details(dish_name):
|
| 77 |
+
if dish_name in dish_data:
|
| 78 |
+
main_image = dish_data[dish_name]["main"]
|
| 79 |
+
return main_image, dish_name, "Select a portion size below:"
|
| 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):
|
|
|
|
| 112 |
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 113 |
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 114 |
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="πΆ Medium")
|
| 115 |
+
portion_dropdown = gr.Radio(label="Select Portion Size", choices=["small", "medium", "large"], value="medium")
|
| 116 |
+
portion_image = gr.Image(label="Portion Size Image")
|
| 117 |
|
| 118 |
# Place Order Button
|
| 119 |
place_order_btn = gr.Button("Place Order")
|
|
|
|
| 129 |
|
| 130 |
# Event: Show dish details when a dish is selected
|
| 131 |
def show_dish_details(dish_name):
|
| 132 |
+
image, name, description = get_dish_details(dish_name)
|
| 133 |
+
return image, name, description
|
| 134 |
|
| 135 |
# Hidden input to receive dish name from JavaScript
|
| 136 |
selected_dish_name = gr.Textbox(visible=False)
|
| 137 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 138 |
+
outputs=[dish_image, dish_name, dish_description])
|
| 139 |
+
|
| 140 |
+
# Event: Display portion size image
|
| 141 |
+
portion_dropdown.change(fn=display_portion, inputs=[selected_dish_name, portion_dropdown], outputs=portion_image)
|
| 142 |
|
| 143 |
# Event: Place order button
|
| 144 |
place_order_btn.click(fn=place_order,
|