Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,10 +25,17 @@ def update_cart():
|
|
| 25 |
html_content += "</ul><button onclick='alert(\'Order placed!\')' style='padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px;'>Place Order</button>"
|
| 26 |
return html_content
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Function to display dishes
|
| 29 |
-
def display_dishes():
|
|
|
|
| 30 |
html_content = "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
|
| 31 |
-
for dish in
|
| 32 |
html_content += f"""
|
| 33 |
<div style='border: 1px solid #ddd; padding: 10px; border-radius: 5px; width: 200px;'>
|
| 34 |
<img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 5px;'>
|
|
@@ -46,21 +53,31 @@ with gr.Blocks() as demo:
|
|
| 46 |
gr.HTML("<h1 style='text-align: center;'>Dynamic Menu with Cart</h1>")
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
-
gr.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
gr.HTML("""
|
| 66 |
<div id='menu-popup' style='display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);'>
|
|
@@ -104,6 +121,4 @@ with gr.Blocks() as demo:
|
|
| 104 |
</script>
|
| 105 |
""")
|
| 106 |
|
| 107 |
-
gr.HTML(value=display_dishes())
|
| 108 |
-
|
| 109 |
demo.launch()
|
|
|
|
| 25 |
html_content += "</ul><button onclick='alert(\'Order placed!\')' style='padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px;'>Place Order</button>"
|
| 26 |
return html_content
|
| 27 |
|
| 28 |
+
# Function to filter dishes by category
|
| 29 |
+
def filter_dishes(category):
|
| 30 |
+
if category == "ALL":
|
| 31 |
+
return menu_data
|
| 32 |
+
return [dish for dish in menu_data if dish["category"] == category]
|
| 33 |
+
|
| 34 |
# Function to display dishes
|
| 35 |
+
def display_dishes(category="ALL"):
|
| 36 |
+
filtered_dishes = filter_dishes(category)
|
| 37 |
html_content = "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
|
| 38 |
+
for dish in filtered_dishes:
|
| 39 |
html_content += f"""
|
| 40 |
<div style='border: 1px solid #ddd; padding: 10px; border-radius: 5px; width: 200px;'>
|
| 41 |
<img src='{dish['image']}' alt='{dish['name']}' style='width: 100%; height: 150px; object-fit: cover; border-radius: 5px;'>
|
|
|
|
| 53 |
gr.HTML("<h1 style='text-align: center;'>Dynamic Menu with Cart</h1>")
|
| 54 |
|
| 55 |
with gr.Row():
|
| 56 |
+
btn_all = gr.Button("ALL")
|
| 57 |
+
btn_vegan = gr.Button("VEGAN")
|
| 58 |
+
btn_halal = gr.Button("HALAL")
|
| 59 |
+
|
| 60 |
+
dish_display = gr.HTML(value=display_dishes())
|
| 61 |
+
|
| 62 |
+
btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
|
| 63 |
+
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 64 |
+
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 65 |
+
|
| 66 |
+
gr.HTML("""
|
| 67 |
+
<div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
|
| 68 |
+
<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Shopping_cart_icon.svg/512px-Shopping_cart_icon.svg.png' alt='Cart' style='width: 40px;' onclick='toggleCartPopup()'>
|
| 69 |
+
</div>
|
| 70 |
+
<div id='cart-popup' style='display: none; position: fixed; top: 50px; right: 10px; background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);'>
|
| 71 |
+
<div id='cart-content'>{update_cart()}</div>
|
| 72 |
+
<button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
|
| 73 |
+
</div>
|
| 74 |
+
<script>
|
| 75 |
+
function toggleCartPopup() {
|
| 76 |
+
const popup = document.getElementById('cart-popup');
|
| 77 |
+
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
| 78 |
+
}
|
| 79 |
+
</script>
|
| 80 |
+
""")
|
| 81 |
|
| 82 |
gr.HTML("""
|
| 83 |
<div id='menu-popup' style='display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);'>
|
|
|
|
| 121 |
</script>
|
| 122 |
""")
|
| 123 |
|
|
|
|
|
|
|
| 124 |
demo.launch()
|