Spaces:
Build error
Build error
Update app.py
Browse files12345678910114568 unmodified lines151617181920212223242526272817 unmodified lines46474849495051525354555656575859606160626263646566676869707165667267746869767071727374757679777882838479808182838485868788899091929394959697989910026 unmodified lines1271281291171301311324 unmodified lines1371381391281401411311421431441351451461471391481491501 unmodified line15215315414715515615015715815315916016116215816316416563 unmodified lines229230231228229232import gradio as grimport pandas as pd
# Function to load the menu datadef load_menu(): menu_file = "menu.xlsx" # Ensure this file exists in the same directory try: return pd.read_excel(menu_file) except Exception as e: raise ValueError(f"Error loading menu file: {e}")
# Initialize cart globallycart_items = []
8 unmodified lines "Extra Fried Onion 4oz": 2,}
# Function to load the menu datadef load_menu(): menu_file = "menu.xlsx" # Ensure this file exists in the same directory try: return pd.read_excel(menu_file) except Exception as e: raise ValueError(f"Error loading menu file: {e}")
# Function to filter menu items based on preferencedef filter_menu(preference): menu_data = load_menu()17 unmodified lines </div> <div style=\"flex-shrink: 0; text-align: center;\"> <img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\"> <button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')\">Add</button> <button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"addToCart('{item['Dish Name']}', '{item['Price ($)']}', '{item['Description']}', '{item['Image URL']}')\">Add</button> </div> </div> """ return html_content
# Function to update the cart displaydef update_cart():def update_cart_display(): global cart_items
if len(cart_items) == 0: return "Your cart is empty."
total_bill = 0 cart_html = "<h3>Your Cart:</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_total
cart_html += f"<li style='margin-bottom: 20px; border: 1px solid #ddd; padding: 10px; border-radius: 8px;'>" cart_html += f"<strong>Item:</strong> {item['name']} - ${item_price:.2f}<br>" cart_html += f"<li style='margin-bottom: 20px;'>" cart_html += f"<strong>Item:</strong> {item['name']} - ${item['price']:.2f}<br>" cart_html += f"<strong>Quantity x Price:</strong> {item['quantity']} x ${item_price:.2f} = ${item_price * item['quantity']:.2f}<br>" cart_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>" cart_html += f"<strong>Extras:</strong> {extras} - ${extras_cost:.2f}<br>" cart_html += f"<strong>Extras:</strong> {extras}<br>" cart_html += f"<strong>Instructions:</strong> {item['instructions']}<br>" cart_html += f"<strong>Item Total:</strong> ${item_total:.2f}" cart_html += f"<strong>Quantity:</strong> {item['quantity']}<br>" cart_html += "</li>" cart_html += "</ul>"
total_bill = sum(item['price'] for item in cart_items) cart_html += f"<p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
cart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>" return cart_html
# Redirect to cart details pagedef redirect_to_cart(): return update_cart()# Function to finalize the orderdef finalize_order(): global cart_items
if len(cart_items) == 0: return "Your order is empty."
order_summary = "<h3>Final Order:</h3><ul>" for item in cart_items: order_summary += f"<li>{item['name']} - ${item['price']:.2f}</li>" order_summary += "</ul>"
total_bill = sum(item['price'] for item in cart_items) order_summary += f"<p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
# Lock the cart after finalizing cart_items = []
return order_summary
# Gradio app definitiondef app():26 unmodified lines "Extra Onion & Lemon": 2, "Extra Fried Onion 4oz": 2 };
function openModal(name, image, description, price) { document.getElementById('modal').style.display = 'block'; document.getElementById('modal-image').src = image;4 unmodified lines // Reset spice levels and extras 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; document.getElementById('special-instructions').value = ''; }
function closeModal() { document.getElementById('modal').style.display = 'none'; }
function addToCart() { const name = document.getElementById('modal-name').innerText; const price = document.getElementById('modal-price').innerText;1 unmodified line 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 = (parseFloat(price.replace('$', '')) + extrasCost) * quantity;
const cartItem = { name, price, spiceLevel, 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>";63 unmodified lines return demo
if __name__ == "__main__": demo = app() demo.launch() app().launch()app.py+40-37