Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,18 +63,29 @@ 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 |
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'>
|
| 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 |
""")
|
|
@@ -106,7 +117,6 @@ with gr.Blocks() as demo:
|
|
| 106 |
|
| 107 |
function addItemToCart() {
|
| 108 |
closeMenuPopup();
|
| 109 |
-
toggleCartPopup();
|
| 110 |
alert('Item added to cart!');
|
| 111 |
fetch('/run/predict', {
|
| 112 |
method: 'POST',
|
|
@@ -121,4 +131,6 @@ with gr.Blocks() as demo:
|
|
| 121 |
</script>
|
| 122 |
""")
|
| 123 |
|
|
|
|
|
|
|
| 124 |
demo.launch()
|
|
|
|
| 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 |
+
cart_content = gr.HTML(value=update_cart())
|
| 67 |
+
|
| 68 |
gr.HTML("""
|
| 69 |
<div id='cart-icon' style='position: fixed; top: 10px; right: 10px; cursor: pointer;'>
|
| 70 |
<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()'>
|
| 71 |
</div>
|
| 72 |
<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);'>
|
| 73 |
+
<div id='cart-content'></div>
|
| 74 |
<button onclick='toggleCartPopup()' style='margin-top: 10px; padding: 5px 10px; background-color: #007bff; color: white; border: none; border-radius: 3px;'>Close</button>
|
| 75 |
</div>
|
| 76 |
<script>
|
| 77 |
function toggleCartPopup() {
|
| 78 |
const popup = document.getElementById('cart-popup');
|
| 79 |
popup.style.display = popup.style.display === 'block' ? 'none' : 'block';
|
| 80 |
+
fetch('/run/predict', {
|
| 81 |
+
method: 'POST',
|
| 82 |
+
headers: { 'Content-Type': 'application/json' },
|
| 83 |
+
body: JSON.stringify({ data: [] })
|
| 84 |
+
})
|
| 85 |
+
.then(response => response.json())
|
| 86 |
+
.then(data => {
|
| 87 |
+
document.getElementById('cart-content').innerHTML = data.data[0];
|
| 88 |
+
});
|
| 89 |
}
|
| 90 |
</script>
|
| 91 |
""")
|
|
|
|
| 117 |
|
| 118 |
function addItemToCart() {
|
| 119 |
closeMenuPopup();
|
|
|
|
| 120 |
alert('Item added to cart!');
|
| 121 |
fetch('/run/predict', {
|
| 122 |
method: 'POST',
|
|
|
|
| 131 |
</script>
|
| 132 |
""")
|
| 133 |
|
| 134 |
+
cart_content.update(lambda: update_cart())
|
| 135 |
+
|
| 136 |
demo.launch()
|