Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 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",
|
|
@@ -13,27 +12,16 @@ menu_data = [
|
|
| 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 |
-
|
| 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 |
-
#
|
| 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,78 +38,74 @@ def display_dishes(category):
|
|
| 50 |
html_content += "</div>"
|
| 51 |
return html_content
|
| 52 |
|
| 53 |
-
#
|
| 54 |
def get_dish_details(dish_name):
|
| 55 |
for dish in menu_data:
|
| 56 |
if dish["name"] == dish_name:
|
| 57 |
-
return
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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
|
| 76 |
-
gr.Markdown("### Available Dishes")
|
| 77 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
gr.
|
| 81 |
-
|
| 82 |
-
|
| 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 |
-
|
| 93 |
-
# Event: Update dish display for selected category
|
| 94 |
def update_dishes(category):
|
| 95 |
return gr.update(value=display_dishes(category))
|
| 96 |
|
| 97 |
-
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_display)
|
| 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 |
-
|
| 104 |
-
return image, name, description, spice, portion
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 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 |
-
#
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
#
|
| 117 |
gr.HTML("""
|
| 118 |
<script>
|
| 119 |
function selectDish(dishName) {
|
| 120 |
-
let input = document.querySelector('input[aria-label="
|
| 121 |
input.value = dishName;
|
| 122 |
input.dispatchEvent(new Event('input', { bubbles: true }));
|
| 123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
</script>
|
| 125 |
""")
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
menu_data = [
|
| 4 |
{"name": "Veg Burger", "category": "VEGAN",
|
| 5 |
"image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
|
|
|
|
| 12 |
{"name": "Paneer Butter Masala", "category": "VEGAN",
|
| 13 |
"image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
|
| 14 |
"description": "Paneer cooked in a rich and creamy tomato-based gravy.",
|
| 15 |
+
"spice_level": "Mild", "portion_size": "Medium"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
+
# Filter dishes by category
|
|
|
|
|
|
|
|
|
|
| 19 |
def filter_dishes(category):
|
| 20 |
if category == "ALL":
|
| 21 |
return menu_data
|
| 22 |
return [dish for dish in menu_data if dish["category"] == category]
|
| 23 |
|
| 24 |
+
# Generate HTML for dish display
|
| 25 |
def display_dishes(category):
|
| 26 |
filtered_dishes = filter_dishes(category)
|
| 27 |
html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
|
|
|
|
| 38 |
html_content += "</div>"
|
| 39 |
return html_content
|
| 40 |
|
| 41 |
+
# Fetch selected dish details
|
| 42 |
def get_dish_details(dish_name):
|
| 43 |
for dish in menu_data:
|
| 44 |
if dish["name"] == dish_name:
|
| 45 |
+
return f"""
|
| 46 |
+
<div style="text-align: center; padding: 20px; font-family: Arial, sans-serif;">
|
| 47 |
+
<img src="{dish['image']}" alt="{dish['name']}"
|
| 48 |
+
style="width: 250px; height: 150px; object-fit: cover; border-radius: 10px;">
|
| 49 |
+
<h2 style="margin-top: 20px; color: #444;">{dish['name']}</h2>
|
| 50 |
+
<p style="margin-top: 10px; font-size: 16px; color: #666;">{dish['description']}</p>
|
| 51 |
+
<button style="padding: 10px 20px; background-color: #28a745; color: white; border: none;
|
| 52 |
+
border-radius: 5px; cursor: pointer;" onclick="closePopup()">Close</button>
|
| 53 |
+
</div>
|
| 54 |
+
"""
|
| 55 |
+
return "Dish not found!"
|
| 56 |
|
| 57 |
# Main Gradio App
|
| 58 |
with gr.Blocks() as demo:
|
| 59 |
gr.HTML("<h1 style='text-align: center; color: #333;'>π Biryani Hub Menu π</h1>")
|
| 60 |
|
| 61 |
+
# Category Buttons
|
|
|
|
| 62 |
with gr.Row():
|
| 63 |
btn_all = gr.Button("ALL")
|
| 64 |
btn_vegan = gr.Button("VEGAN")
|
| 65 |
btn_halal = gr.Button("HALAL")
|
| 66 |
|
| 67 |
+
# Dish display
|
|
|
|
| 68 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 69 |
|
| 70 |
+
# Hidden pop-up for dish details
|
| 71 |
+
popup = gr.HTML(visible=False)
|
| 72 |
+
|
| 73 |
+
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def update_dishes(category):
|
| 75 |
return gr.update(value=display_dishes(category))
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def show_dish_details(dish_name):
|
| 78 |
+
return gr.update(visible=True, value=get_dish_details(dish_name))
|
|
|
|
| 79 |
|
| 80 |
+
def hide_popup():
|
| 81 |
+
return gr.update(visible=False)
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
# Button actions
|
| 84 |
+
btn_all.click(fn=lambda: update_dishes("ALL"), outputs=dish_display)
|
| 85 |
+
btn_vegan.click(fn=lambda: update_dishes("VEGAN"), outputs=dish_display)
|
| 86 |
+
btn_halal.click(fn=lambda: update_dishes("HALAL"), outputs=dish_display)
|
| 87 |
|
| 88 |
+
# JavaScript for dish selection
|
| 89 |
gr.HTML("""
|
| 90 |
<script>
|
| 91 |
function selectDish(dishName) {
|
| 92 |
+
let input = document.querySelector('input[aria-label="popup"]');
|
| 93 |
input.value = dishName;
|
| 94 |
input.dispatchEvent(new Event('input', { bubbles: true }));
|
| 95 |
}
|
| 96 |
+
function closePopup() {
|
| 97 |
+
let closeButton = document.querySelector('button[aria-label="close_popup"]');
|
| 98 |
+
closeButton.click();
|
| 99 |
+
}
|
| 100 |
</script>
|
| 101 |
""")
|
| 102 |
|
| 103 |
+
# Hidden input and close button
|
| 104 |
+
dish_name_input = gr.Textbox(visible=False, label="popup")
|
| 105 |
+
close_button = gr.Button("Close Popup", visible=False)
|
| 106 |
+
|
| 107 |
+
# Link events
|
| 108 |
+
dish_name_input.change(fn=show_dish_details, inputs=dish_name_input, outputs=popup)
|
| 109 |
+
close_button.click(fn=hide_popup, outputs=popup)
|
| 110 |
+
|
| 111 |
demo.launch()
|