Spaces:
Build error
Build error
Update app.py
Browse files78 unmodified lines79808182838485868788899091929394959697989910010110210310410510610710810911012 unmodified lines12312412512612712812913013113213313413513613713813914014114244 unmodified lines1871881891901911921934 unmodified lines19819920020120220320420520648 unmodified lines25525625725825926026126226326426526678 unmodified linescart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"return cart_html# Function to submit the cart and display on a new pagedef submit_cart():if len(cart_items) == 0:return "<h3>Your Order</h3><p>Your cart is empty.</p>"total_bill = 0order_html = "<h3>Your Order</h3><ul style='list-style-type: none; padding: 0;'>"for item in cart_items:extras = ", ".join(item.get("extras", []))extras_cost = sum(EXTRAS_PRICES.get(extra, 0) for extra in item.get("extras", []))item_price = float(item['price'].strip('$'))item_total = (item_price + extras_cost) * item['quantity']total_bill += item_totalorder_html += f"<li style='margin-bottom: 20px; border: 1px solid #ddd; padding: 10px; border-radius: 8px;'>"order_html += f"<strong>Item:</strong> {item['name']} - ${item_price:.2f}<br>"order_html += f"<strong>Quantity x Price:</strong> {item['quantity']} x ${item_price:.2f} = ${item_price * item['quantity']:.2f}<br>"order_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>"order_html += f"<strong>Extras:</strong> {extras} - ${extras_cost:.2f}<br>"order_html += f"<strong>Instructions:</strong> {item['instructions']}<br>"order_html += f"<strong>Item Total:</strong> ${item_total:.2f}"order_html += "</li>"order_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"return order_html# Gradio app definitiondef app():with gr.Blocks() as demo:12 unmodified lines# Floating cart displaycart_output = gr.HTML(value=update_cart(), elem_id="floating-cart")# Submit button for the cartsubmit_button = gr.Button("Submit Order")# Submit button action to navigate to a new pagedef navigate_to_order():return gr.Interface(fn=submit_cart,inputs=[],outputs="html",live=True,).launch()submit_button.click(fn=submit_cart, inputs=[], outputs="html")# JavaScript for modal and cart behaviormodal_and_cart_js = """<script>44 unmodified linesconst cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };cart.push(cartItem);alert(`${name} added to cart!`);updateCartDisplay();closeModal();}4 unmodified linescart.forEach(item => {totalBill += item.itemTotal;const extras = item.extras.join(', ');cartHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;});cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;document.getElementById('floating-cart').innerHTML = cartHTML;}</script>48 unmodified linesgr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row([submit_button])gr.Row(modal_window)gr.HTML(modal_and_cart_js)return demoif __name__ == "__main__":demo = app()demo.launch()78 unmodified lines79808182838412 unmodified lines97989910010110244 unmodified lines1471481491501511521534 unmodified lines15815916016116216316416516648 unmodified lines21521621721821922022122222322422578 unmodified linescart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"return cart_html# Gradio app definitiondef app():with gr.Blocks() as demo:12 unmodified lines# Floating cart displaycart_output = gr.HTML(value=update_cart(), elem_id="floating-cart")# JavaScript for modal and cart behaviormodal_and_cart_js = """<script>44 unmodified linesconst cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };cart.push(cartItem);alert(${name} added to cart!);updateCartDisplay();closeModal();}4 unmodified linescart.forEach(item => {totalBill += item.itemTotal;const extras = item.extras.join(', ');cartHTML += <li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>;});cartHTML += </ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>;document.getElementById('floating-cart').innerHTML = cartHTML;}</script>48 unmodified linesgr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row(modal_window)gr.HTML(modal_and_cart_js)return demoif _name_ == "_main_":demo = app()demo.launch()
app.py+5-46