Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,47 +74,97 @@ def app():
|
|
| 74 |
|
| 75 |
# Modal window
|
| 76 |
modal_window = gr.HTML("""
|
| 77 |
-
<div id="
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
<
|
| 103 |
-
<
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
<
|
| 111 |
-
<
|
| 112 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
</div>
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# Interactivity
|
| 120 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
|
|
|
| 74 |
|
| 75 |
# Modal window
|
| 76 |
modal_window = gr.HTML("""
|
| 77 |
+
<div id="modal" style="
|
| 78 |
+
display: none;
|
| 79 |
+
position: fixed;
|
| 80 |
+
top: 50%;
|
| 81 |
+
left: 50%;
|
| 82 |
+
transform: translate(-50%, -50%);
|
| 83 |
+
width: 90%;
|
| 84 |
+
max-width: 500px;
|
| 85 |
+
max-height: 90%;
|
| 86 |
+
background: white;
|
| 87 |
+
border-radius: 15px;
|
| 88 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
|
| 89 |
+
padding: 20px;
|
| 90 |
+
z-index: 1000;
|
| 91 |
+
overflow-y: auto;
|
| 92 |
+
font-family: Arial, sans-serif;
|
| 93 |
+
">
|
| 94 |
+
<div style="text-align: right;">
|
| 95 |
+
<button onclick="closeModal()" style="
|
| 96 |
+
background: none;
|
| 97 |
+
border: none;
|
| 98 |
+
font-size: 24px;
|
| 99 |
+
cursor: pointer;
|
| 100 |
+
color: #333;
|
| 101 |
+
">×</button>
|
| 102 |
+
</div>
|
| 103 |
+
<img id="modal-image" style="
|
| 104 |
+
width: 100%;
|
| 105 |
+
height: auto;
|
| 106 |
+
border-radius: 12px;
|
| 107 |
+
margin-bottom: 15px;
|
| 108 |
+
" />
|
| 109 |
+
<h2 id="modal-name" style="margin-bottom: 10px; font-size: 22px; color: #333;"></h2>
|
| 110 |
+
<p id="modal-description" style="margin-bottom: 10px; color: #555; font-size: 16px;"></p>
|
| 111 |
+
<p id="modal-price" style="margin-bottom: 20px; font-size: 18px; font-weight: bold; color: #222;"></p>
|
| 112 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 113 |
+
<label for="quantity" style="font-weight: bold;">Quantity:</label>
|
| 114 |
+
<input type="number" id="quantity" value="1" min="1" style="
|
| 115 |
+
width: 60px;
|
| 116 |
+
padding: 5px;
|
| 117 |
+
border: 1px solid #ccc;
|
| 118 |
+
border-radius: 5px;
|
| 119 |
+
" />
|
| 120 |
+
<button style="
|
| 121 |
+
background-color: #28a745;
|
| 122 |
+
color: white;
|
| 123 |
+
border: none;
|
| 124 |
+
padding: 10px 20px;
|
| 125 |
+
font-size: 16px;
|
| 126 |
+
border-radius: 8px;
|
| 127 |
+
cursor: pointer;
|
| 128 |
+
" onclick="addToCart()">Add</button>
|
| 129 |
+
</div>
|
| 130 |
</div>
|
| 131 |
+
|
| 132 |
+
<script>
|
| 133 |
+
let cart = [];
|
| 134 |
+
function openModal(name, image, description, price) {
|
| 135 |
+
const modal = document.getElementById('modal');
|
| 136 |
+
modal.style.display = 'block';
|
| 137 |
+
modal.style.top = '50%';
|
| 138 |
+
modal.style.left = '50%';
|
| 139 |
+
modal.style.transform = 'translate(-50%, -50%)';
|
| 140 |
+
document.getElementById('modal-image').src = image;
|
| 141 |
+
document.getElementById('modal-name').innerText = name;
|
| 142 |
+
document.getElementById('modal-description').innerText = description;
|
| 143 |
+
document.getElementById('modal-price').innerText = `$${price}`;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function closeModal() {
|
| 147 |
+
const modal = document.getElementById('modal');
|
| 148 |
+
modal.style.display = 'none';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function addToCart() {
|
| 152 |
+
const name = document.getElementById('modal-name').innerText;
|
| 153 |
+
const price = document.getElementById('modal-price').innerText;
|
| 154 |
+
const description = document.getElementById('modal-description').innerText;
|
| 155 |
+
const quantity = parseInt(document.getElementById('quantity').value) || 1;
|
| 156 |
+
const cartItem = { name, description, price, quantity };
|
| 157 |
+
cart.push(cartItem);
|
| 158 |
+
fetch("/update_cart", {
|
| 159 |
+
method: "POST",
|
| 160 |
+
headers: { "Content-Type": "application/json" },
|
| 161 |
+
body: JSON.stringify(cart)
|
| 162 |
+
});
|
| 163 |
+
alert(`${name} added to cart!`);
|
| 164 |
+
closeModal();
|
| 165 |
+
}
|
| 166 |
+
</script>
|
| 167 |
+
""")
|
| 168 |
|
| 169 |
# Interactivity
|
| 170 |
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|