Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,6 @@ import pandas as pd
|
|
| 3 |
|
| 4 |
# Load menu data from Excel file
|
| 5 |
def load_menu(file_path="menu.xlsx"):
|
| 6 |
-
"""
|
| 7 |
-
Load menu data from an Excel file dynamically based on column headers.
|
| 8 |
-
"""
|
| 9 |
menu_df = pd.read_excel(file_path)
|
| 10 |
menu_df.columns = menu_df.columns.str.strip().str.lower()
|
| 11 |
|
|
@@ -40,16 +37,34 @@ def display_menu():
|
|
| 40 |
"""
|
| 41 |
menu_html = ""
|
| 42 |
for item in menu_data:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
<div>
|
| 47 |
-
<
|
| 48 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
</div>
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return menu_html
|
| 54 |
|
| 55 |
def add_to_cart(item_name):
|
|
@@ -67,7 +82,7 @@ def add_to_cart(item_name):
|
|
| 67 |
"quantity": 1
|
| 68 |
}
|
| 69 |
break
|
| 70 |
-
return
|
| 71 |
|
| 72 |
def update_quantity(item_name, new_quantity):
|
| 73 |
"""
|
|
@@ -78,7 +93,7 @@ def update_quantity(item_name, new_quantity):
|
|
| 78 |
del cart[item_name]
|
| 79 |
else:
|
| 80 |
cart[item_name]["quantity"] = new_quantity
|
| 81 |
-
return
|
| 82 |
|
| 83 |
def view_cart():
|
| 84 |
"""
|
|
|
|
| 3 |
|
| 4 |
# Load menu data from Excel file
|
| 5 |
def load_menu(file_path="menu.xlsx"):
|
|
|
|
|
|
|
|
|
|
| 6 |
menu_df = pd.read_excel(file_path)
|
| 7 |
menu_df.columns = menu_df.columns.str.strip().str.lower()
|
| 8 |
|
|
|
|
| 37 |
"""
|
| 38 |
menu_html = ""
|
| 39 |
for item in menu_data:
|
| 40 |
+
if item["name"] in cart:
|
| 41 |
+
# Quantity selector if the item is already in the cart
|
| 42 |
+
menu_html += f"""
|
| 43 |
+
<div style="display: flex; align-items: center; margin-bottom: 15px; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 44 |
+
<img src="{item['image']}" alt="{item['name']}" style="width: 80px; height: 80px; border-radius: 5px; margin-right: 15px;">
|
| 45 |
+
<div>
|
| 46 |
+
<h4 style="margin: 0;">{item['name']} - ${item['price']}</h4>
|
| 47 |
+
<p style="font-size: 12px; color: gray;">{item['description']}</p>
|
| 48 |
+
</div>
|
| 49 |
+
<div style="margin-left: auto; display: flex; align-items: center;">
|
| 50 |
+
<button onclick="update_quantity('{item['name']}', {cart[item['name']]['quantity'] - 1})" style="background-color: #dc3545; color: white; border: none; padding: 5px; border-radius: 5px;">-</button>
|
| 51 |
+
<span style="margin: 0 10px;">{cart[item['name']]['quantity']}</span>
|
| 52 |
+
<button onclick="update_quantity('{item['name']}', {cart[item['name']]['quantity'] + 1})" style="background-color: #28a745; color: white; border: none; padding: 5px; border-radius: 5px;">+</button>
|
| 53 |
+
</div>
|
| 54 |
</div>
|
| 55 |
+
"""
|
| 56 |
+
else:
|
| 57 |
+
# Add button if the item is not in the cart
|
| 58 |
+
menu_html += f"""
|
| 59 |
+
<div style="display: flex; align-items: center; margin-bottom: 15px; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
|
| 60 |
+
<img src="{item['image']}" alt="{item['name']}" style="width: 80px; height: 80px; border-radius: 5px; margin-right: 15px;">
|
| 61 |
+
<div>
|
| 62 |
+
<h4 style="margin: 0;">{item['name']} - ${item['price']}</h4>
|
| 63 |
+
<p style="font-size: 12px; color: gray;">{item['description']}</p>
|
| 64 |
+
</div>
|
| 65 |
+
<button onclick="add_to_cart('{item['name']}')" style="background-color: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer; margin-left: auto;">Add</button>
|
| 66 |
+
</div>
|
| 67 |
+
"""
|
| 68 |
return menu_html
|
| 69 |
|
| 70 |
def add_to_cart(item_name):
|
|
|
|
| 82 |
"quantity": 1
|
| 83 |
}
|
| 84 |
break
|
| 85 |
+
return display_menu()
|
| 86 |
|
| 87 |
def update_quantity(item_name, new_quantity):
|
| 88 |
"""
|
|
|
|
| 93 |
del cart[item_name]
|
| 94 |
else:
|
| 95 |
cart[item_name]["quantity"] = new_quantity
|
| 96 |
+
return display_menu()
|
| 97 |
|
| 98 |
def view_cart():
|
| 99 |
"""
|