Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,15 +156,21 @@ with gr.Blocks() as demo:
|
|
| 156 |
const quantity = document.getElementById('quantity').value || 1;
|
| 157 |
const customDescription = document.getElementById('custom-description').value || "None";
|
| 158 |
|
| 159 |
-
//
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
</script>
|
| 170 |
""")
|
|
@@ -174,11 +180,5 @@ with gr.Blocks() as demo:
|
|
| 174 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 175 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 176 |
|
| 177 |
-
# Link Add to Cart functionality
|
| 178 |
-
gr.Button("Add", visible=False).click(
|
| 179 |
-
add_to_cart,
|
| 180 |
-
inputs=[gr.Textbox(), gr.Textbox(), gr.Textbox(), gr.Number(), gr.Textbox()],
|
| 181 |
-
outputs=cart_display
|
| 182 |
-
)
|
| 183 |
|
| 184 |
demo.launch()
|
|
|
|
| 156 |
const quantity = document.getElementById('quantity').value || 1;
|
| 157 |
const customDescription = document.getElementById('custom-description').value || "None";
|
| 158 |
|
| 159 |
+
// Pass to Gradio backend
|
| 160 |
+
fetch("/run/add_to_cart", {
|
| 161 |
+
method: "POST",
|
| 162 |
+
headers: {"Content-Type": "application/json"},
|
| 163 |
+
body: JSON.stringify({
|
| 164 |
+
dish_name: selectedDish,
|
| 165 |
+
spice_level: spiceLevel,
|
| 166 |
+
selected_extras: selectedExtras,
|
| 167 |
+
quantity: quantity,
|
| 168 |
+
custom_description: customDescription
|
| 169 |
+
})
|
| 170 |
+
}).then(response => response.json()).then(data => {
|
| 171 |
+
document.querySelector("#cart-display").innerHTML = data.html;
|
| 172 |
+
closePopup();
|
| 173 |
+
});
|
| 174 |
}
|
| 175 |
</script>
|
| 176 |
""")
|
|
|
|
| 180 |
btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
|
| 181 |
btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
demo.launch()
|