Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213148 unmodified lines23242526272817 unmodified lines46474849505152535455565758596061626364656667686970717273747576777879808182838485868726 unmodified lines1141151161171181191204 unmodified lines1251261271281291301311321331341351361371381391401411421 unmodified line14414514614714814915015115215315415515615715815916016163 unmodified lines225226227228229import 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 directorytry: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 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></div></div>"""return html_content# Function to update the cart displaydef update_cart():if len(cart_items) == 0:return "Your cart is empty."total_bill = 0cart_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_totalcart_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"<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>Instructions:</strong> {item['instructions']}<br>"cart_html += f"<strong>Item Total:</strong> ${item_total:.2f}"cart_html += "</li>"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()# 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 extrasconst 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 lineconst 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 linesreturn demoif __name__ == "__main__":demo = app()demo.launch()1234568 unmodified lines151617181920212223242526272817 unmodified lines46474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910026 unmodified lines1271281291301311324 unmodified lines1371381391401411421431441451461471481491501 unmodified line15215315415515615715815916016116216316416563 unmodified lines229230231232import gradio as grimport pandas as pd# 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 directorytry: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=\"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_display():global cart_itemsif len(cart_items) == 0:return "Your cart is empty."cart_html = "<h3>Your Cart:</h3><ul style='list-style-type: none; padding: 0;'>"for item in cart_items:extras = ", ".join(item.get("extras", []))cart_html += f"<li style='margin-bottom: 20px;'>"cart_html += f"<strong>Item:</strong> {item['name']} - ${item['price']:.2f}<br>"cart_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>"cart_html += f"<strong>Extras:</strong> {extras}<br>"cart_html += f"<strong>Instructions:</strong> {item['instructions']}<br>"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>"return cart_html# Function to finalize the orderdef finalize_order():global cart_itemsif 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 finalizingcart_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 extrasconst 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 lineconst 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 linesreturn demoif __name__ == "__main__":app().launch()
app.py+40-37