Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,7 +67,7 @@ popup_js = """
|
|
| 67 |
<h3>${name}</h3>
|
| 68 |
<p>${description}</p>
|
| 69 |
<p style="font-weight: bold;">Price: ${price}</p>
|
| 70 |
-
<button
|
| 71 |
Add to Cart
|
| 72 |
</button>
|
| 73 |
<button onclick="closePopup()" style="padding: 10px 20px; background-color: #dc3545; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">
|
|
@@ -76,19 +76,18 @@ popup_js = """
|
|
| 76 |
`;
|
| 77 |
popup.style.display = "block";
|
| 78 |
overlay.style.display = "block";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
}
|
| 80 |
|
| 81 |
function closePopup() {
|
| 82 |
document.getElementById("custom-popup").style.display = "none";
|
| 83 |
document.getElementById("overlay").style.display = "none";
|
| 84 |
}
|
| 85 |
-
|
| 86 |
-
async function addToCart(name) {
|
| 87 |
-
// Call the Gradio backend function to add item to the cart
|
| 88 |
-
const response = await google.colab.kernel.invokeFunction('notebook.add_to_cart', [name], {});
|
| 89 |
-
alert(response.data); // Show a success message
|
| 90 |
-
closePopup(); // Close the popup
|
| 91 |
-
}
|
| 92 |
</script>
|
| 93 |
"""
|
| 94 |
|
|
@@ -140,6 +139,6 @@ with gr.Blocks() as demo:
|
|
| 140 |
)
|
| 141 |
|
| 142 |
# Register the backend function for JavaScript integration
|
| 143 |
-
demo.
|
| 144 |
|
| 145 |
demo.launch()
|
|
|
|
| 67 |
<h3>${name}</h3>
|
| 68 |
<p>${description}</p>
|
| 69 |
<p style="font-weight: bold;">Price: ${price}</p>
|
| 70 |
+
<button id="add-to-cart-button" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer;">
|
| 71 |
Add to Cart
|
| 72 |
</button>
|
| 73 |
<button onclick="closePopup()" style="padding: 10px 20px; background-color: #dc3545; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">
|
|
|
|
| 76 |
`;
|
| 77 |
popup.style.display = "block";
|
| 78 |
overlay.style.display = "block";
|
| 79 |
+
|
| 80 |
+
document.getElementById("add-to-cart-button").onclick = async function() {
|
| 81 |
+
const response = await google.colab.kernel.invokeFunction('add_to_cart', [name], {});
|
| 82 |
+
alert(response.data);
|
| 83 |
+
closePopup();
|
| 84 |
+
};
|
| 85 |
}
|
| 86 |
|
| 87 |
function closePopup() {
|
| 88 |
document.getElementById("custom-popup").style.display = "none";
|
| 89 |
document.getElementById("overlay").style.display = "none";
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
</script>
|
| 92 |
"""
|
| 93 |
|
|
|
|
| 139 |
)
|
| 140 |
|
| 141 |
# Register the backend function for JavaScript integration
|
| 142 |
+
demo.load(lambda: None, inputs=[], outputs=[], live=True) # Dummy to integrate JavaScript
|
| 143 |
|
| 144 |
demo.launch()
|