Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,17 +4,24 @@ import pandas as pd
|
|
| 4 |
# Load menu from Excel file
|
| 5 |
def load_menu(file_path="menu.xlsx"):
|
| 6 |
"""
|
| 7 |
-
Load menu data from an Excel file.
|
| 8 |
-
The Excel file should have columns: Name, Price, Description, Image
|
| 9 |
"""
|
| 10 |
menu_df = pd.read_excel(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
menu = []
|
| 12 |
for _, row in menu_df.iterrows():
|
| 13 |
menu.append({
|
| 14 |
-
"name": row[
|
| 15 |
-
"price": row[
|
| 16 |
-
"description": row[
|
| 17 |
-
"image": row[
|
| 18 |
})
|
| 19 |
return menu
|
| 20 |
|
|
@@ -35,13 +42,8 @@ def display_menu():
|
|
| 35 |
<div style="flex-grow: 1;">
|
| 36 |
<h4 style="margin: 0;">{item['name']} - ${item['price']}</h4>
|
| 37 |
<p style="margin: 5px 0; font-size: 12px;">{item['description']}</p>
|
| 38 |
-
<div style="display: flex; align-items: center;">
|
| 39 |
-
<button style="background-color: #f0f0f0; padding: 5px 10px; border-radius: 5px; margin-right: 5px;" onclick="decreaseQuantity('{item['name']}')">-</button>
|
| 40 |
-
<span id="quantity-{item['name']}" style="padding: 5px;">1</span>
|
| 41 |
-
<button style="background-color: #f0f0f0; padding: 5px 10px; border-radius: 5px; margin-left: 5px;" onclick="increaseQuantity('{item['name']}')">+</button>
|
| 42 |
-
</div>
|
| 43 |
</div>
|
| 44 |
-
<button
|
| 45 |
</div>
|
| 46 |
"""
|
| 47 |
return menu_html
|
|
|
|
| 4 |
# Load menu 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 |
+
|
| 11 |
+
# Automatically detect column names
|
| 12 |
+
columns = menu_df.columns.str.strip() # Trim column names to avoid issues with spaces
|
| 13 |
+
name_column = [col for col in columns if "name" in col.lower()][0]
|
| 14 |
+
price_column = [col for col in columns if "price" in col.lower()][0]
|
| 15 |
+
description_column = [col for col in columns if "description" in col.lower()][0]
|
| 16 |
+
image_column = [col for col in columns if "image" in col.lower()][0]
|
| 17 |
+
|
| 18 |
menu = []
|
| 19 |
for _, row in menu_df.iterrows():
|
| 20 |
menu.append({
|
| 21 |
+
"name": row[name_column],
|
| 22 |
+
"price": row[price_column],
|
| 23 |
+
"description": row[description_column],
|
| 24 |
+
"image": row[image_column]
|
| 25 |
})
|
| 26 |
return menu
|
| 27 |
|
|
|
|
| 42 |
<div style="flex-grow: 1;">
|
| 43 |
<h4 style="margin: 0;">{item['name']} - ${item['price']}</h4>
|
| 44 |
<p style="margin: 5px 0; font-size: 12px;">{item['description']}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
</div>
|
| 46 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 8px 12px; border-radius: 5px; cursor: pointer;" onclick="add_to_cart('{item['name']}', 1)">Add</button>
|
| 47 |
</div>
|
| 48 |
"""
|
| 49 |
return menu_html
|