Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,32 +79,6 @@ def update_cart():
|
|
| 79 |
cart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 80 |
return cart_html
|
| 81 |
|
| 82 |
-
# Function to submit the cart and display on a new page
|
| 83 |
-
def submit_cart():
|
| 84 |
-
if len(cart_items) == 0:
|
| 85 |
-
return "<h3>Your Order</h3><p>Your cart is empty.</p>"
|
| 86 |
-
|
| 87 |
-
total_bill = 0
|
| 88 |
-
order_html = "<h3>Your Order</h3><ul style='list-style-type: none; padding: 0;'>"
|
| 89 |
-
for item in cart_items:
|
| 90 |
-
extras = ", ".join(item.get("extras", []))
|
| 91 |
-
extras_cost = sum(EXTRAS_PRICES.get(extra, 0) for extra in item.get("extras", []))
|
| 92 |
-
item_price = float(item['price'].strip('$'))
|
| 93 |
-
item_total = (item_price + extras_cost) * item['quantity']
|
| 94 |
-
total_bill += item_total
|
| 95 |
-
|
| 96 |
-
order_html += f"<li style='margin-bottom: 20px; border: 1px solid #ddd; padding: 10px; border-radius: 8px;'>"
|
| 97 |
-
order_html += f"<strong>Item:</strong> {item['name']} - ${item_price:.2f}<br>"
|
| 98 |
-
order_html += f"<strong>Quantity x Price:</strong> {item['quantity']} x ${item_price:.2f} = ${item_price * item['quantity']:.2f}<br>"
|
| 99 |
-
order_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>"
|
| 100 |
-
order_html += f"<strong>Extras:</strong> {extras} - ${extras_cost:.2f}<br>"
|
| 101 |
-
order_html += f"<strong>Instructions:</strong> {item['instructions']}<br>"
|
| 102 |
-
order_html += f"<strong>Item Total:</strong> ${item_total:.2f}"
|
| 103 |
-
order_html += "</li>"
|
| 104 |
-
|
| 105 |
-
order_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 106 |
-
return order_html
|
| 107 |
-
|
| 108 |
# Gradio app definition
|
| 109 |
def app():
|
| 110 |
with gr.Blocks() as demo:
|
|
@@ -123,20 +97,6 @@ def app():
|
|
| 123 |
# Floating cart display
|
| 124 |
cart_output = gr.HTML(value=update_cart(), elem_id="floating-cart")
|
| 125 |
|
| 126 |
-
# Submit button for the cart
|
| 127 |
-
submit_button = gr.Button("Submit Order")
|
| 128 |
-
|
| 129 |
-
# Submit button action to navigate to a new page
|
| 130 |
-
def navigate_to_order():
|
| 131 |
-
return gr.Interface(
|
| 132 |
-
fn=submit_cart,
|
| 133 |
-
inputs=[],
|
| 134 |
-
outputs="html",
|
| 135 |
-
live=True,
|
| 136 |
-
).launch()
|
| 137 |
-
|
| 138 |
-
submit_button.click(fn=submit_cart, inputs=[], outputs="html")
|
| 139 |
-
|
| 140 |
# JavaScript for modal and cart behavior
|
| 141 |
modal_and_cart_js = """
|
| 142 |
<script>
|
|
@@ -187,7 +147,7 @@ def app():
|
|
| 187 |
const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
|
| 188 |
cart.push(cartItem);
|
| 189 |
|
| 190 |
-
alert(
|
| 191 |
updateCartDisplay();
|
| 192 |
closeModal();
|
| 193 |
}
|
|
@@ -198,9 +158,9 @@ def app():
|
|
| 198 |
cart.forEach(item => {
|
| 199 |
totalBill += item.itemTotal;
|
| 200 |
const extras = item.extras.join(', ');
|
| 201 |
-
cartHTML +=
|
| 202 |
});
|
| 203 |
-
cartHTML +=
|
| 204 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 205 |
}
|
| 206 |
</script>
|
|
@@ -255,12 +215,11 @@ def app():
|
|
| 255 |
gr.Row([selected_preference])
|
| 256 |
gr.Row(menu_output)
|
| 257 |
gr.Row(cart_output)
|
| 258 |
-
gr.Row([submit_button])
|
| 259 |
gr.Row(modal_window)
|
| 260 |
gr.HTML(modal_and_cart_js)
|
| 261 |
|
| 262 |
return demo
|
| 263 |
|
| 264 |
-
if
|
| 265 |
demo = app()
|
| 266 |
-
demo.launch()
|
|
|
|
| 79 |
cart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 80 |
return cart_html
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# Gradio app definition
|
| 83 |
def app():
|
| 84 |
with gr.Blocks() as demo:
|
|
|
|
| 97 |
# Floating cart display
|
| 98 |
cart_output = gr.HTML(value=update_cart(), elem_id="floating-cart")
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# JavaScript for modal and cart behavior
|
| 101 |
modal_and_cart_js = """
|
| 102 |
<script>
|
|
|
|
| 147 |
const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
|
| 148 |
cart.push(cartItem);
|
| 149 |
|
| 150 |
+
alert(${name} added to cart!);
|
| 151 |
updateCartDisplay();
|
| 152 |
closeModal();
|
| 153 |
}
|
|
|
|
| 158 |
cart.forEach(item => {
|
| 159 |
totalBill += item.itemTotal;
|
| 160 |
const extras = item.extras.join(', ');
|
| 161 |
+
cartHTML += <li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>;
|
| 162 |
});
|
| 163 |
+
cartHTML += </ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>;
|
| 164 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
| 165 |
}
|
| 166 |
</script>
|
|
|
|
| 215 |
gr.Row([selected_preference])
|
| 216 |
gr.Row(menu_output)
|
| 217 |
gr.Row(cart_output)
|
|
|
|
| 218 |
gr.Row(modal_window)
|
| 219 |
gr.HTML(modal_and_cart_js)
|
| 220 |
|
| 221 |
return demo
|
| 222 |
|
| 223 |
+
if _name_ == "_main_":
|
| 224 |
demo = app()
|
| 225 |
+
demo.launch()
|