Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,13 +27,11 @@ menu_data = [
|
|
| 27 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 28 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 29 |
|
| 30 |
-
# Function to filter dishes based on category
|
| 31 |
def filter_dishes(category):
|
| 32 |
if category == "ALL":
|
| 33 |
return menu_data
|
| 34 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 35 |
|
| 36 |
-
# Function to display dishes with images
|
| 37 |
def display_dishes(category):
|
| 38 |
filtered_dishes = filter_dishes(category)
|
| 39 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
@@ -50,47 +48,41 @@ def display_dishes(category):
|
|
| 50 |
html_content += "</div>"
|
| 51 |
return html_content
|
| 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):
|
| 62 |
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 63 |
|
| 64 |
-
# Main Gradio App
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 67 |
|
| 68 |
-
# Buttons for category selection
|
| 69 |
gr.Markdown("### Select a Category")
|
| 70 |
with gr.Row():
|
| 71 |
btn_all = gr.Button("ALL")
|
| 72 |
btn_vegan = gr.Button("VEGAN")
|
| 73 |
btn_halal = gr.Button("HALAL")
|
| 74 |
|
| 75 |
-
# Dish display section
|
| 76 |
gr.Markdown("### Available Dishes")
|
| 77 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 78 |
|
| 79 |
-
# Dish Details
|
| 80 |
-
gr.
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
place_order_btn = gr.Button("Place Order")
|
| 91 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 92 |
|
| 93 |
-
# Event: Update dish display for selected category
|
| 94 |
def update_dishes(category):
|
| 95 |
return gr.update(value=display_dishes(category))
|
| 96 |
|
|
@@ -98,22 +90,23 @@ with gr.Blocks() as demo:
|
|
| 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,
|
| 113 |
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 114 |
outputs=order_status)
|
| 115 |
|
| 116 |
-
# Inject JavaScript to handle clicks and pass dish names
|
| 117 |
gr.HTML("""
|
| 118 |
<script>
|
| 119 |
function selectDish(dishName) {
|
|
|
|
| 27 |
spice_options = ["πΆ Mild", "πΆπΆ Medium", "πΆπΆπΆ High"]
|
| 28 |
portion_options = ["π§ Small", "π½ Medium", "π Large"]
|
| 29 |
|
|
|
|
| 30 |
def filter_dishes(category):
|
| 31 |
if category == "ALL":
|
| 32 |
return menu_data
|
| 33 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 34 |
|
|
|
|
| 35 |
def display_dishes(category):
|
| 36 |
filtered_dishes = filter_dishes(category)
|
| 37 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
|
|
| 48 |
html_content += "</div>"
|
| 49 |
return html_content
|
| 50 |
|
|
|
|
| 51 |
def get_dish_details(dish_name):
|
| 52 |
for dish in menu_data:
|
| 53 |
if dish["name"] == dish_name:
|
| 54 |
return dish["image"], dish["name"], dish["description"], "πΆ Medium", "π½ Medium"
|
| 55 |
return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available.", "N/A", "N/A"
|
| 56 |
|
|
|
|
| 57 |
def place_order(dish_name, spice_level, portion_size):
|
| 58 |
return f"β
Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
|
| 59 |
|
|
|
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 62 |
|
|
|
|
| 63 |
gr.Markdown("### Select a Category")
|
| 64 |
with gr.Row():
|
| 65 |
btn_all = gr.Button("ALL")
|
| 66 |
btn_vegan = gr.Button("VEGAN")
|
| 67 |
btn_halal = gr.Button("HALAL")
|
| 68 |
|
|
|
|
| 69 |
gr.Markdown("### Available Dishes")
|
| 70 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 71 |
|
| 72 |
+
# Dish Details Pop-up
|
| 73 |
+
with gr.Box(visible=False) as popup:
|
| 74 |
+
with gr.Row():
|
| 75 |
+
dish_image = gr.Image(label="Dish Image", height=200, width=200)
|
| 76 |
+
with gr.Column():
|
| 77 |
+
dish_name = gr.Textbox(label="Dish Name", interactive=False)
|
| 78 |
+
dish_description = gr.Textbox(label="Description", interactive=False)
|
| 79 |
+
spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="πΆ Medium")
|
| 80 |
+
portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="π½ Medium")
|
| 81 |
+
close_popup = gr.Button("Close")
|
| 82 |
+
|
| 83 |
place_order_btn = gr.Button("Place Order")
|
| 84 |
order_status = gr.Textbox(label="Order Status", interactive=False)
|
| 85 |
|
|
|
|
| 86 |
def update_dishes(category):
|
| 87 |
return gr.update(value=display_dishes(category))
|
| 88 |
|
|
|
|
| 90 |
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 91 |
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 92 |
|
|
|
|
| 93 |
def show_dish_details(dish_name):
|
| 94 |
image, name, description, spice, portion = get_dish_details(dish_name)
|
| 95 |
+
return gr.update(visible=True), image, name, description, spice, portion
|
| 96 |
+
|
| 97 |
+
def close_dish_popup():
|
| 98 |
+
return gr.update(visible=False)
|
| 99 |
|
|
|
|
| 100 |
selected_dish_name = gr.Textbox(visible=False)
|
| 101 |
selected_dish_name.change(fn=show_dish_details, inputs=selected_dish_name,
|
| 102 |
+
outputs=[popup, dish_image, dish_name, dish_description, spice_dropdown, portion_dropdown])
|
| 103 |
+
|
| 104 |
+
close_popup.click(fn=close_dish_popup, outputs=popup)
|
| 105 |
|
|
|
|
| 106 |
place_order_btn.click(fn=place_order,
|
| 107 |
inputs=[dish_name, spice_dropdown, portion_dropdown],
|
| 108 |
outputs=order_status)
|
| 109 |
|
|
|
|
| 110 |
gr.HTML("""
|
| 111 |
<script>
|
| 112 |
function selectDish(dishName) {
|