Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -137,45 +137,63 @@ with gr.Blocks() as demo:
|
|
| 137 |
<button onclick="addItemToCart()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px;">Add to Cart</button>
|
| 138 |
</div>
|
| 139 |
<script>
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
demo.launch()
|
| 181 |
|
|
|
|
| 137 |
<button onclick="addItemToCart()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px;">Add to Cart</button>
|
| 138 |
</div>
|
| 139 |
<script>
|
| 140 |
+
let selectedDish = "";
|
| 141 |
+
let selectedExtras = [];
|
| 142 |
+
|
| 143 |
+
function showPopup(title, description, price) {
|
| 144 |
+
selectedDish = title;
|
| 145 |
+
document.getElementById('popup-title').textContent = title;
|
| 146 |
+
document.getElementById('popup-description').textContent = description;
|
| 147 |
+
document.getElementById('popup-price').textContent = price;
|
| 148 |
+
document.getElementById('popup').style.display = 'block';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
function closePopup() {
|
| 152 |
+
document.getElementById('popup').style.display = 'none';
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function increaseQuantity() {
|
| 156 |
+
const quantityInput = document.getElementById('quantity');
|
| 157 |
+
quantityInput.value = parseInt(quantityInput.value) + 1;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
function decreaseQuantity() {
|
| 161 |
+
const quantityInput = document.getElementById('quantity');
|
| 162 |
+
if (parseInt(quantityInput.value) > 1) {
|
| 163 |
+
quantityInput.value = parseInt(quantityInput.value) - 1;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
function addItemToCart() {
|
| 168 |
+
const extrasInputs = document.querySelectorAll('input[name="extras"]:checked');
|
| 169 |
+
selectedExtras = Array.from(extrasInputs).map(input => input.value);
|
| 170 |
+
const quantity = document.getElementById('quantity').value || 1;
|
| 171 |
+
const customDescription = document.getElementById('custom-description').value || "None";
|
| 172 |
+
|
| 173 |
+
// Pass data to Gradio backend
|
| 174 |
+
const gradioApp = document.querySelector("gradio-app").shadowRoot;
|
| 175 |
+
const dishNameInput = gradioApp.querySelector("textarea[aria-label='Dish Name']");
|
| 176 |
+
const extrasInput = gradioApp.querySelector("textarea[aria-label='Selected Extras']");
|
| 177 |
+
const quantityInput = gradioApp.querySelector("input[aria-label='Quantity']");
|
| 178 |
+
const customDescriptionInput = gradioApp.querySelector("textarea[aria-label='Custom Description']");
|
| 179 |
+
const addToCartButton = gradioApp.querySelector("button[aria-label='Add to Cart']");
|
| 180 |
+
|
| 181 |
+
if (dishNameInput && extrasInput && quantityInput && customDescriptionInput && addToCartButton) {
|
| 182 |
+
dishNameInput.value = selectedDish;
|
| 183 |
+
extrasInput.value = JSON.stringify(selectedExtras);
|
| 184 |
+
quantityInput.value = quantity;
|
| 185 |
+
customDescriptionInput.value = customDescription;
|
| 186 |
+
|
| 187 |
+
// Trigger Gradio's add-to-cart function
|
| 188 |
+
addToCartButton.click();
|
| 189 |
+
closePopup();
|
| 190 |
+
} else {
|
| 191 |
+
console.error("Failed to locate Gradio inputs or button.");
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
</script>
|
| 195 |
+
|
| 196 |
+
""")
|
| 197 |
|
| 198 |
demo.launch()
|
| 199 |
|