Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ def update_cart(cart):
|
|
| 19 |
html_content = "<h3>Cart Items</h3><ul>"
|
| 20 |
for item in cart:
|
| 21 |
html_content += f"<li>{item}</li>"
|
| 22 |
-
html_content += "</ul><button onclick='alert(\
|
| 23 |
return html_content
|
| 24 |
|
| 25 |
# Function to filter dishes by category
|
|
@@ -39,7 +39,7 @@ def display_dishes(category="ALL"):
|
|
| 39 |
<h4>{dish['name']}</h4>
|
| 40 |
<p>{dish['description']}</p>
|
| 41 |
<p><strong>Price:</strong> {dish['price']}</p>
|
| 42 |
-
<button onclick="
|
| 43 |
</div>
|
| 44 |
"""
|
| 45 |
html_content += "</div>"
|
|
@@ -63,57 +63,36 @@ with gr.Blocks() as demo:
|
|
| 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 |
-
|
| 67 |
-
|
| 68 |
-
|
| 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'>
|
| 72 |
-
<div style='overflow-y: auto;'>
|
| 73 |
-
<div>{cart_display}</div>
|
| 74 |
-
</div>
|
| 75 |
-
</div>
|
| 76 |
-
<button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
|
| 77 |
-
</div>
|
| 78 |
-
<script>
|
| 79 |
-
function toggleCartPopup() {
|
| 80 |
-
const popup = document.getElementById('cart-popup');
|
| 81 |
-
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
| 82 |
-
}
|
| 83 |
-
</script>
|
| 84 |
-
""")
|
| 85 |
-
|
| 86 |
-
gr.HTML("""
|
| 87 |
-
<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);'>
|
| 88 |
-
<span onclick='closeMenuPopup()' style='position: absolute; top: 5px; right: 10px; cursor: pointer;'>×</span>
|
| 89 |
-
<img id='popup-image' src='' style='width: 100%; border-radius: 5px; margin-bottom: 10px;'>
|
| 90 |
-
<h4 id='popup-title'></h4>
|
| 91 |
-
<p id='popup-description'></p>
|
| 92 |
-
<p id='popup-price'></p>
|
| 93 |
-
<button onclick='addItemToCart()' style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
|
| 94 |
-
</div>
|
| 95 |
-
<script>
|
| 96 |
-
let selectedItem = '';
|
| 97 |
-
|
| 98 |
-
function showMenuPopup(name, description, price, image) {
|
| 99 |
-
selectedItem = name;
|
| 100 |
-
document.getElementById('popup-title').textContent = name;
|
| 101 |
-
document.getElementById('popup-description').textContent = description;
|
| 102 |
-
document.getElementById('popup-price').textContent = price;
|
| 103 |
-
document.getElementById('popup-image').src = image;
|
| 104 |
-
document.getElementById('menu-popup').style.display = 'block';
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
function closeMenuPopup() {
|
| 108 |
-
document.getElementById('menu-popup').style.display = 'none';
|
| 109 |
-
}
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
demo.launch()
|
|
|
|
| 19 |
html_content = "<h3>Cart Items</h3><ul>"
|
| 20 |
for item in cart:
|
| 21 |
html_content += f"<li>{item}</li>"
|
| 22 |
+
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>"
|
| 23 |
return html_content
|
| 24 |
|
| 25 |
# Function to filter dishes by category
|
|
|
|
| 39 |
<h4>{dish['name']}</h4>
|
| 40 |
<p>{dish['description']}</p>
|
| 41 |
<p><strong>Price:</strong> {dish['price']}</p>
|
| 42 |
+
<button onclick=\"addItemToCart('{dish['name']}')\" style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
|
| 43 |
</div>
|
| 44 |
"""
|
| 45 |
html_content += "</div>"
|
|
|
|
| 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 |
+
def handle_add_to_cart(cart, dish_name):
|
| 67 |
+
cart.append(dish_name)
|
| 68 |
+
return cart, update_cart(cart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
with gr.Row():
|
| 71 |
+
gr.HTML("""
|
| 72 |
+
<div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
|
| 73 |
+
<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()'>
|
| 74 |
+
</div>
|
| 75 |
+
<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);'>
|
| 76 |
+
<div id='cart-content'></div>
|
| 77 |
+
<button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
|
| 78 |
+
</div>
|
| 79 |
+
<script>
|
| 80 |
+
function toggleCartPopup() {
|
| 81 |
+
const popup = document.getElementById('cart-popup');
|
| 82 |
+
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function addItemToCart(name) {
|
| 86 |
+
fetch('/run/predict', {
|
| 87 |
+
method: 'POST',
|
| 88 |
+
headers: { 'Content-Type': 'application/json' },
|
| 89 |
+
body: JSON.stringify({ data: [name] })
|
| 90 |
+
}).then(response => response.json()).then(data => {
|
| 91 |
+
document.getElementById('cart-content').innerHTML = data.data[1];
|
| 92 |
+
alert(name + ' has been added to the cart!');
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
</script>
|
| 96 |
+
""")
|
| 97 |
|
| 98 |
demo.launch()
|