Spaces:
Build error
Build error
Update app.py
Browse files57 unmodified lines58596061626364656667686970711 unmodified line737475767778792 unmodified lines82838485868788899091929394959697982 unmodified lines1011021031041051061071081091101111121131141151161171181 unmodified line12012112212312412512612712812913013113213313413516 unmodified lines15215315415515615715815916016116216316416516616716857 unmodified linesreturn;}document.getElementById('modal').style.display = 'block';document.body.style.overflow = 'hidden'; // Disable scrollingdocument.getElementById('modal-image').src = image;document.getElementById('modal-name').innerText = name;document.getElementById('modal-description').innerText = description;document.getElementById('modal-price').innerText = price;const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');spiceLevelInputs.forEach(input => input.checked = false);const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');extrasInputs.forEach(input => input.checked = false);document.getElementById('quantity').value = 1;1 unmodified line}function closeModal() {document.getElementById('modal').style.display = 'none';document.body.style.overflow = ''; // Re-enable scrolling}function addToCart() {if (finalized) {2 unmodified lines}const name = document.getElementById('modal-name').innerText;const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));const spiceLevel = document.querySelector('input[name="spice-level"]:checked')?.value || "Not Selected";const quantity = parseInt(document.getElementById('quantity').value) || 1;const instructions = document.getElementById('special-instructions').value;const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);const itemTotal = (price + extrasCost) * quantity;const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };cart.push(cartItem);alert(`${name} added to cart!`);closeModal();}</script>"""2 unmodified lineswith gr.Blocks() as demo:gr.Markdown("## Dynamic Menu with Preferences")selected_preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],value="All",label="Choose a Preference",)menu_output = gr.HTML(value=filter_menu("All"))cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")modal_window = gr.HTML("""<div id="modal" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50%; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;"><div style="text-align: right;"><button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button></div>1 unmodified line<h2 id="modal-name"></h2><p id="modal-description"></p><p id="modal-price"></p><!-- Spice Levels --><label for="spice-level">Choose a Spice Level (Required):</label><div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;"><label><input type="radio" name="spice-level" value="American Mild" /> American Mild</label><label><input type="radio" name="spice-level" value="American Medium" /> American Medium</label><label><input type="radio" name="spice-level" value="American Spicy" /> American Spicy</label><label><input type="radio" name="spice-level" value="Indian Mild" /> Indian Mild</label><label><input type="radio" name="spice-level" value="Indian Medium" /> Indian Medium</label><label><input type="radio" name="spice-level" value="Indian Very Spicy" /> Indian Very Spicy</label></div><!-- Biryani Extras --><label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label><div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">16 unmodified lines</div>""")finalize_button = gr.Button("Finalize Order")finalize_button.click(lambda: "Order finalized!", outputs=[])selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])gr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row(modal_window)gr.Row(finalize_button)gr.HTML(modal_and_cart_js)return demo57 unmodified lines58596061626364656667681 unmodified line7071727374752 unmodified lines787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251262 unmodified lines1291301311321331341351361371381391401411421431441451461471481491501511521531 unmodified line15515615715815916016 unmodified lines17717817918018118218318418518618718818919019119219319419519619719857 unmodified linesreturn;}document.getElementById('modal').style.display = 'block';document.getElementById('modal-image').src = image;document.getElementById('modal-name').innerText = name;document.getElementById('modal-description').innerText = description;document.getElementById('modal-price').innerText = price;// Reset extrasconst extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');extrasInputs.forEach(input => input.checked = false);document.getElementById('quantity').value = 1;1 unmodified line}function closeModal() {document.getElementById('modal').style.display = 'none';}function addToCart() {if (finalized) {2 unmodified lines}const name = document.getElementById('modal-name').innerText;const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));const quantity = parseInt(document.getElementById('quantity').value) || 1;const instructions = document.getElementById('special-instructions').value;const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);const itemTotal = (price + extrasCost) * quantity;const cartItem = { name, price, quantity, instructions, extras, itemTotal };cart.push(cartItem);alert(`${name} added to cart!`);updateCartDisplay();closeModal();}function updateCartDisplay() {let totalBill = 0;let cartHTML = "<h3>Your Cart:</h3><ul>";cart.forEach((item, index) => {totalBill += item.itemTotal;const extras = item.extras.join(', ');cartHTML += `<li><input type='checkbox' id='cart-item-${index}' value='${index}' checked onclick='removeItem(${index})'> ${item.name} (x${item.quantity}, 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;}function removeItem(index) {cart.splice(index, 1);updateCartDisplay();}function finalizeOrder() {if (cart.length === 0) {alert("Your cart is empty. Please add items before finalizing.");return;}finalized = true;let finalOrderHTML = "<h3>Final Order:</h3><ul>";let totalBill = 0;cart.forEach(item => {totalBill += item.itemTotal;const extras = item.extras.join(', ');finalOrderHTML += `<li>${item.name} (x${item.quantity}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;});finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;document.getElementById('final-order').innerHTML = finalOrderHTML;alert("Your order has been finalized. You cannot make changes now.");}</script>"""2 unmodified lineswith gr.Blocks() as demo:gr.Markdown("## Dynamic Menu with Preferences")# Radio button for selecting preferenceselected_preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],value="All",label="Choose a Preference",)# Output area for menu itemsmenu_output = gr.HTML(value=filter_menu("All"))# Floating cart displaycart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")# Final order displayfinal_order_output = gr.HTML(value="", elem_id="final-order")# Modal windowmodal_window = gr.HTML("""<div id="modal" style="display: none; position: fixed; top: 10%; left: 5%; width: 90%; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;"><div style="text-align: right;"><button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button></div>1 unmodified line<h2 id="modal-name"></h2><p id="modal-description"></p><p id="modal-price"></p><!-- Biryani Extras --><label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label><div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">16 unmodified lines</div>""")# Finalize Order Buttonfinalize_button = gr.Button("Finalize Order")# Finalize order button click eventfinalize_button.click(lambda: "Order finalized!", outputs=[final_order_output])# Update menu dynamically based on preferenceselected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])# Layoutgr.Row([selected_preference])gr.Row(menu_output)gr.Row(cart_output)gr.Row(modal_window)gr.Row(finalize_button)gr.Row(final_order_output)gr.HTML(modal_and_cart_js)return demo
app.py+49-19