Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,7 +63,7 @@ def display_dishes(category="ALL"):
|
|
| 63 |
<h4>{dish['name']}</h4>
|
| 64 |
<p>{dish['description']}</p>
|
| 65 |
<p><strong>Price:</strong> ${dish['price']}</p>
|
| 66 |
-
<button onclick="
|
| 67 |
</div>
|
| 68 |
"""
|
| 69 |
html_content += "</div>"
|
|
@@ -91,10 +91,63 @@ with gr.Blocks() as demo:
|
|
| 91 |
def add_to_cart_wrapper(dish_name, price):
|
| 92 |
return add_item_to_cart(dish_name, price)
|
| 93 |
|
| 94 |
-
add_button = gr.Button("Add to Cart")
|
| 95 |
-
add_button.click(add_to_cart_wrapper, inputs=[gr.Textbox(), gr.Number()], outputs=[cart_display, total_items, total_price])
|
| 96 |
-
|
| 97 |
clear_button = gr.Button("Clear Cart")
|
| 98 |
clear_button.click(clear_cart, outputs=[cart_display, total_items, total_price])
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
demo.launch()
|
|
|
|
| 63 |
<h4>{dish['name']}</h4>
|
| 64 |
<p>{dish['description']}</p>
|
| 65 |
<p><strong>Price:</strong> ${dish['price']}</p>
|
| 66 |
+
<button onclick="showMenuPopup('{dish['name']}', '{dish['description']}', {dish['price']}, '{dish['image']}')" style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
|
| 67 |
</div>
|
| 68 |
"""
|
| 69 |
html_content += "</div>"
|
|
|
|
| 91 |
def add_to_cart_wrapper(dish_name, price):
|
| 92 |
return add_item_to_cart(dish_name, price)
|
| 93 |
|
|
|
|
|
|
|
|
|
|
| 94 |
clear_button = gr.Button("Clear Cart")
|
| 95 |
clear_button.click(clear_cart, outputs=[cart_display, total_items, total_price])
|
| 96 |
|
| 97 |
+
gr.HTML("""
|
| 98 |
+
<div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
|
| 99 |
+
<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()'>
|
| 100 |
+
</div>
|
| 101 |
+
<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);'>
|
| 102 |
+
<span onclick='toggleCartPopup()' style='position: absolute; top: 10px; right: 15px; font-size: 20px; font-weight: bold; cursor: pointer;'>×</span>
|
| 103 |
+
<div id='cart-content'>Your cart is empty.</div>
|
| 104 |
+
<button onclick='alert("Order placed!")' style='margin-top: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px;'>Place Order</button>
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
<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);'>
|
| 108 |
+
<span onclick='closeMenuPopup()' style='position: absolute; top: 5px; right: 10px; cursor: pointer;'>×</span>
|
| 109 |
+
<img id='popup-image' src='' style='width: 100%; border-radius: 5px; margin-bottom: 10px;'>
|
| 110 |
+
<h4 id='popup-title'></h4>
|
| 111 |
+
<p id='popup-description'></p>
|
| 112 |
+
<p id='popup-price'></p>
|
| 113 |
+
<button onclick='addItemToCart()' style='padding: 5px 10px; background-color: #28a745; color: white; border: none; border-radius: 3px;'>Add to Cart</button>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<script>
|
| 117 |
+
let selectedItem = '';
|
| 118 |
+
|
| 119 |
+
function toggleCartPopup() {
|
| 120 |
+
const popup = document.getElementById('cart-popup');
|
| 121 |
+
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
| 122 |
+
fetch('/run/predict', {
|
| 123 |
+
method: 'POST',
|
| 124 |
+
headers: { 'Content-Type': 'application/json' },
|
| 125 |
+
body: JSON.stringify({ data: [] })
|
| 126 |
+
}).then(response => response.json()).then(data => {
|
| 127 |
+
document.getElementById('cart-content').innerHTML = data.data[1];
|
| 128 |
+
});
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
function showMenuPopup(name, description, price, image) {
|
| 132 |
+
selectedItem = name;
|
| 133 |
+
document.getElementById('popup-title').textContent = name;
|
| 134 |
+
document.getElementById('popup-description').textContent = description;
|
| 135 |
+
document.getElementById('popup-price').textContent = `Price: ${price}`;
|
| 136 |
+
document.getElementById('popup-image').src = image;
|
| 137 |
+
document.getElementById('menu-popup').style.display = 'block';
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function closeMenuPopup() {
|
| 141 |
+
document.getElementById('menu-popup').style.display = 'none';
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
function addItemToCart() {
|
| 145 |
+
closeMenuPopup();
|
| 146 |
+
const inputBox = gradioApp().querySelector("textarea[aria-label='Selected Item']");
|
| 147 |
+
inputBox.value = selectedItem;
|
| 148 |
+
gradioApp().querySelector("button[aria-label='Add to Cart']").click();
|
| 149 |
+
}
|
| 150 |
+
</script>
|
| 151 |
+
""")
|
| 152 |
+
|
| 153 |
demo.launch()
|