Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
# Function to load the menu data
|
| 5 |
-
def load_menu():
|
| 6 |
-
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
| 7 |
-
try:
|
| 8 |
-
return pd.read_excel(menu_file)
|
| 9 |
-
except Exception as e:
|
| 10 |
-
raise ValueError(f"Error loading menu file: {e}")
|
| 11 |
-
|
| 12 |
# Initialize cart globally
|
| 13 |
cart_items = []
|
| 14 |
|
|
@@ -23,6 +15,14 @@ EXTRAS_PRICES = {
|
|
| 23 |
"Extra Fried Onion 4oz": 2,
|
| 24 |
}
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Function to filter menu items based on preference
|
| 27 |
def filter_menu(preference):
|
| 28 |
menu_data = load_menu()
|
|
@@ -46,42 +46,55 @@ def filter_menu(preference):
|
|
| 46 |
</div>
|
| 47 |
<div style=\"flex-shrink: 0; text-align: center;\">
|
| 48 |
<img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
|
| 49 |
-
<button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
"""
|
| 53 |
return html_content
|
| 54 |
|
| 55 |
# Function to update the cart display
|
| 56 |
-
def
|
|
|
|
|
|
|
| 57 |
if len(cart_items) == 0:
|
| 58 |
return "Your cart is empty."
|
| 59 |
|
| 60 |
-
total_bill = 0
|
| 61 |
cart_html = "<h3>Your Cart:</h3><ul style='list-style-type: none; padding: 0;'>"
|
| 62 |
-
|
| 63 |
for item in cart_items:
|
| 64 |
extras = ", ".join(item.get("extras", []))
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
item_total = (item_price + extras_cost) * item['quantity']
|
| 68 |
-
total_bill += item_total
|
| 69 |
-
|
| 70 |
-
cart_html += f"<li style='margin-bottom: 20px; border: 1px solid #ddd; padding: 10px; border-radius: 8px;'>"
|
| 71 |
-
cart_html += f"<strong>Item:</strong> {item['name']} - ${item_price:.2f}<br>"
|
| 72 |
-
cart_html += f"<strong>Quantity x Price:</strong> {item['quantity']} x ${item_price:.2f} = ${item_price * item['quantity']:.2f}<br>"
|
| 73 |
cart_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>"
|
| 74 |
-
cart_html += f"<strong>Extras:</strong> {extras}
|
| 75 |
cart_html += f"<strong>Instructions:</strong> {item['instructions']}<br>"
|
| 76 |
-
cart_html += f"<strong>
|
| 77 |
cart_html += "</li>"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
cart_html += f"</ul><p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 80 |
return cart_html
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
def
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# Gradio app definition
|
| 87 |
def app():
|
|
@@ -114,7 +127,6 @@ def app():
|
|
| 114 |
"Extra Onion & Lemon": 2,
|
| 115 |
"Extra Fried Onion 4oz": 2
|
| 116 |
};
|
| 117 |
-
|
| 118 |
function openModal(name, image, description, price) {
|
| 119 |
document.getElementById('modal').style.display = 'block';
|
| 120 |
document.getElementById('modal-image').src = image;
|
|
@@ -125,18 +137,14 @@ def app():
|
|
| 125 |
// Reset spice levels and extras
|
| 126 |
const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
|
| 127 |
spiceLevelInputs.forEach(input => input.checked = false);
|
| 128 |
-
|
| 129 |
const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
|
| 130 |
extrasInputs.forEach(input => input.checked = false);
|
| 131 |
-
|
| 132 |
document.getElementById('quantity').value = 1;
|
| 133 |
document.getElementById('special-instructions').value = '';
|
| 134 |
}
|
| 135 |
-
|
| 136 |
function closeModal() {
|
| 137 |
document.getElementById('modal').style.display = 'none';
|
| 138 |
}
|
| 139 |
-
|
| 140 |
function addToCart() {
|
| 141 |
const name = document.getElementById('modal-name').innerText;
|
| 142 |
const price = document.getElementById('modal-price').innerText;
|
|
@@ -144,18 +152,14 @@ def app():
|
|
| 144 |
const quantity = parseInt(document.getElementById('quantity').value) || 1;
|
| 145 |
const instructions = document.getElementById('special-instructions').value;
|
| 146 |
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
|
| 147 |
-
|
| 148 |
const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
|
| 149 |
const itemTotal = (parseFloat(price.replace('$', '')) + extrasCost) * quantity;
|
| 150 |
-
|
| 151 |
const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
|
| 152 |
cart.push(cartItem);
|
| 153 |
-
|
| 154 |
alert(`${name} added to cart!`);
|
| 155 |
updateCartDisplay();
|
| 156 |
closeModal();
|
| 157 |
}
|
| 158 |
-
|
| 159 |
function updateCartDisplay() {
|
| 160 |
let totalBill = 0;
|
| 161 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
|
@@ -225,5 +229,4 @@ def app():
|
|
| 225 |
return demo
|
| 226 |
|
| 227 |
if __name__ == "__main__":
|
| 228 |
-
|
| 229 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Initialize cart globally
|
| 5 |
cart_items = []
|
| 6 |
|
|
|
|
| 15 |
"Extra Fried Onion 4oz": 2,
|
| 16 |
}
|
| 17 |
|
| 18 |
+
# Function to load the menu data
|
| 19 |
+
def load_menu():
|
| 20 |
+
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
| 21 |
+
try:
|
| 22 |
+
return pd.read_excel(menu_file)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
raise ValueError(f"Error loading menu file: {e}")
|
| 25 |
+
|
| 26 |
# Function to filter menu items based on preference
|
| 27 |
def filter_menu(preference):
|
| 28 |
menu_data = load_menu()
|
|
|
|
| 46 |
</div>
|
| 47 |
<div style=\"flex-shrink: 0; text-align: center;\">
|
| 48 |
<img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
|
| 49 |
+
<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>
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
"""
|
| 53 |
return html_content
|
| 54 |
|
| 55 |
# Function to update the cart display
|
| 56 |
+
def update_cart_display():
|
| 57 |
+
global cart_items
|
| 58 |
+
|
| 59 |
if len(cart_items) == 0:
|
| 60 |
return "Your cart is empty."
|
| 61 |
|
|
|
|
| 62 |
cart_html = "<h3>Your Cart:</h3><ul style='list-style-type: none; padding: 0;'>"
|
|
|
|
| 63 |
for item in cart_items:
|
| 64 |
extras = ", ".join(item.get("extras", []))
|
| 65 |
+
cart_html += f"<li style='margin-bottom: 20px;'>"
|
| 66 |
+
cart_html += f"<strong>Item:</strong> {item['name']} - ${item['price']:.2f}<br>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
cart_html += f"<strong>Spice Level:</strong> {item['spiceLevel']}<br>"
|
| 68 |
+
cart_html += f"<strong>Extras:</strong> {extras}<br>"
|
| 69 |
cart_html += f"<strong>Instructions:</strong> {item['instructions']}<br>"
|
| 70 |
+
cart_html += f"<strong>Quantity:</strong> {item['quantity']}<br>"
|
| 71 |
cart_html += "</li>"
|
| 72 |
+
cart_html += "</ul>"
|
| 73 |
+
|
| 74 |
+
total_bill = sum(item['price'] for item in cart_items)
|
| 75 |
+
cart_html += f"<p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 76 |
|
|
|
|
| 77 |
return cart_html
|
| 78 |
|
| 79 |
+
# Function to finalize the order
|
| 80 |
+
def finalize_order():
|
| 81 |
+
global cart_items
|
| 82 |
+
|
| 83 |
+
if len(cart_items) == 0:
|
| 84 |
+
return "Your order is empty."
|
| 85 |
+
|
| 86 |
+
order_summary = "<h3>Final Order:</h3><ul>"
|
| 87 |
+
for item in cart_items:
|
| 88 |
+
order_summary += f"<li>{item['name']} - ${item['price']:.2f}</li>"
|
| 89 |
+
order_summary += "</ul>"
|
| 90 |
+
|
| 91 |
+
total_bill = sum(item['price'] for item in cart_items)
|
| 92 |
+
order_summary += f"<p><strong>Total Bill: ${total_bill:.2f}</strong></p>"
|
| 93 |
+
|
| 94 |
+
# Lock the cart after finalizing
|
| 95 |
+
cart_items = []
|
| 96 |
+
|
| 97 |
+
return order_summary
|
| 98 |
|
| 99 |
# Gradio app definition
|
| 100 |
def app():
|
|
|
|
| 127 |
"Extra Onion & Lemon": 2,
|
| 128 |
"Extra Fried Onion 4oz": 2
|
| 129 |
};
|
|
|
|
| 130 |
function openModal(name, image, description, price) {
|
| 131 |
document.getElementById('modal').style.display = 'block';
|
| 132 |
document.getElementById('modal-image').src = image;
|
|
|
|
| 137 |
// Reset spice levels and extras
|
| 138 |
const spiceLevelInputs = document.querySelectorAll('input[name="spice-level"]');
|
| 139 |
spiceLevelInputs.forEach(input => input.checked = false);
|
|
|
|
| 140 |
const extrasInputs = document.querySelectorAll('input[name="biryani-extra"]');
|
| 141 |
extrasInputs.forEach(input => input.checked = false);
|
|
|
|
| 142 |
document.getElementById('quantity').value = 1;
|
| 143 |
document.getElementById('special-instructions').value = '';
|
| 144 |
}
|
|
|
|
| 145 |
function closeModal() {
|
| 146 |
document.getElementById('modal').style.display = 'none';
|
| 147 |
}
|
|
|
|
| 148 |
function addToCart() {
|
| 149 |
const name = document.getElementById('modal-name').innerText;
|
| 150 |
const price = document.getElementById('modal-price').innerText;
|
|
|
|
| 152 |
const quantity = parseInt(document.getElementById('quantity').value) || 1;
|
| 153 |
const instructions = document.getElementById('special-instructions').value;
|
| 154 |
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
|
|
|
|
| 155 |
const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
|
| 156 |
const itemTotal = (parseFloat(price.replace('$', '')) + extrasCost) * quantity;
|
|
|
|
| 157 |
const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
|
| 158 |
cart.push(cartItem);
|
|
|
|
| 159 |
alert(`${name} added to cart!`);
|
| 160 |
updateCartDisplay();
|
| 161 |
closeModal();
|
| 162 |
}
|
|
|
|
| 163 |
function updateCartDisplay() {
|
| 164 |
let totalBill = 0;
|
| 165 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
|
|
|
| 229 |
return demo
|
| 230 |
|
| 231 |
if __name__ == "__main__":
|
| 232 |
+
app().launch()
|
|
|