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",
|
|
@@ -16,9 +16,11 @@ menu_data = [
|
|
| 16 |
"spice_level": "πΆπΆπΆ High", "portion_size": "π½ Medium"},
|
| 17 |
]
|
| 18 |
|
|
|
|
| 19 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 20 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 21 |
|
|
|
|
| 22 |
def display_dishes(category):
|
| 23 |
filtered_dishes = [dish for dish in menu_data if category == "ALL" or dish["category"] == category]
|
| 24 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
@@ -35,18 +37,22 @@ def display_dishes(category):
|
|
| 35 |
html_content += "</div>"
|
| 36 |
return html_content
|
| 37 |
|
|
|
|
| 38 |
def get_dish_details(dish_name):
|
| 39 |
for dish in menu_data:
|
| 40 |
if dish["name"] == dish_name:
|
| 41 |
return dish["image"], dish["name"], dish["description"], dish["spice_level"], dish["portion_size"]
|
| 42 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "πΆ Mild", "π§ Small"
|
| 43 |
|
|
|
|
| 44 |
def place_order(dish_name, spice_level, portion_size):
|
| 45 |
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 46 |
|
|
|
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 49 |
-
|
|
|
|
| 50 |
gr.HTML("""
|
| 51 |
<script>
|
| 52 |
function selectDish(dishName) {
|
|
@@ -68,6 +74,7 @@ with gr.Blocks() as demo:
|
|
| 68 |
gr.Markdown("### Available Dishes")
|
| 69 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 70 |
|
|
|
|
| 71 |
popup = gr.Group(visible=False)
|
| 72 |
with popup:
|
| 73 |
with gr.Row():
|
|
@@ -82,6 +89,7 @@ with gr.Blocks() as demo:
|
|
| 82 |
place_order_btn = gr.Button("Place Order")
|
| 83 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 84 |
|
|
|
|
| 85 |
def update_dishes(category):
|
| 86 |
return gr.update(value=display_dishes(category))
|
| 87 |
|
|
@@ -89,6 +97,7 @@ with gr.Blocks() as demo:
|
|
| 89 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 90 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 91 |
|
|
|
|
| 92 |
selected_dish_name = gr.Textbox(visible=False)
|
| 93 |
selected_dish_name.change(
|
| 94 |
fn=lambda dish_name: (*get_dish_details(dish_name), gr.update(visible=True)),
|
|
@@ -96,8 +105,15 @@ with gr.Blocks() as demo:
|
|
| 96 |
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown, popup],
|
| 97 |
)
|
| 98 |
|
|
|
|
| 99 |
close_popup.click(fn=lambda: gr.update(visible=False), outputs=popup)
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
demo.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Menu data
|
| 4 |
menu_data = [
|
| 5 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 6 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
|
|
| 16 |
"spice_level": "πΆπΆπΆ High", "portion_size": "π½ Medium"},
|
| 17 |
]
|
| 18 |
|
| 19 |
+
# Dropdown options
|
| 20 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 21 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 22 |
|
| 23 |
+
# Function to generate dish display HTML
|
| 24 |
def display_dishes(category):
|
| 25 |
filtered_dishes = [dish for dish in menu_data if category == "ALL" or dish["category"] == category]
|
| 26 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
|
|
| 37 |
html_content += "</div>"
|
| 38 |
return html_content
|
| 39 |
|
| 40 |
+
# Function to retrieve dish details
|
| 41 |
def get_dish_details(dish_name):
|
| 42 |
for dish in menu_data:
|
| 43 |
if dish["name"] == dish_name:
|
| 44 |
return dish["image"], dish["name"], dish["description"], dish["spice_level"], dish["portion_size"]
|
| 45 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "πΆ Mild", "π§ Small"
|
| 46 |
|
| 47 |
+
# Function to confirm an order
|
| 48 |
def place_order(dish_name, spice_level, portion_size):
|
| 49 |
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 50 |
|
| 51 |
+
# Create the Gradio app
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
gr.HTML("<h1 style='text-align: center;'>π Biryani Hub Menu π</h1>")
|
| 54 |
+
|
| 55 |
+
# JavaScript function to handle dish selection
|
| 56 |
gr.HTML("""
|
| 57 |
<script>
|
| 58 |
function selectDish(dishName) {
|
|
|
|
| 74 |
gr.Markdown("### Available Dishes")
|
| 75 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 76 |
|
| 77 |
+
# Pop-up for dish details
|
| 78 |
popup = gr.Group(visible=False)
|
| 79 |
with popup:
|
| 80 |
with gr.Row():
|
|
|
|
| 89 |
place_order_btn = gr.Button("Place Order")
|
| 90 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 91 |
|
| 92 |
+
# Update the displayed dishes
|
| 93 |
def update_dishes(category):
|
| 94 |
return gr.update(value=display_dishes(category))
|
| 95 |
|
|
|
|
| 97 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 98 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 99 |
|
| 100 |
+
# Show dish details in pop-up
|
| 101 |
selected_dish_name = gr.Textbox(visible=False)
|
| 102 |
selected_dish_name.change(
|
| 103 |
fn=lambda dish_name: (*get_dish_details(dish_name), gr.update(visible=True)),
|
|
|
|
| 105 |
outputs=[dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown, popup],
|
| 106 |
)
|
| 107 |
|
| 108 |
+
# Close the pop-up
|
| 109 |
close_popup.click(fn=lambda: gr.update(visible=False), outputs=popup)
|
| 110 |
|
| 111 |
+
# Place the order
|
| 112 |
+
place_order_btn.click(
|
| 113 |
+
fn=place_order,
|
| 114 |
+
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 115 |
+
outputs=order_status,
|
| 116 |
+
)
|
| 117 |
|
| 118 |
demo.launch()
|
| 119 |
+
|