Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,6 +79,32 @@ def update_cart():
|
|
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,6 +123,13 @@ def app():
|
|
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>
|
@@ -215,6 +248,8 @@ def app():
|
|
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 |
|
|
|
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 |
# 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 |
+
order_page = gr.HTML(value="")
|
129 |
+
|
130 |
+
# Submit button action
|
131 |
+
submit_button.click(fn=submit_cart, inputs=[], outputs=order_page)
|
132 |
+
|
133 |
# JavaScript for modal and cart behavior
|
134 |
modal_and_cart_js = """
|
135 |
<script>
|
|
|
248 |
gr.Row([selected_preference])
|
249 |
gr.Row(menu_output)
|
250 |
gr.Row(cart_output)
|
251 |
+
gr.Row([submit_button])
|
252 |
+
gr.Row(order_page)
|
253 |
gr.Row(modal_window)
|
254 |
gr.HTML(modal_and_cart_js)
|
255 |
|