Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,35 @@ def load_menu():
|
|
9 |
except Exception as e:
|
10 |
raise ValueError(f"Error loading menu file: {e}")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# JavaScript for modal and cart behavior
|
13 |
modal_and_cart_js = """
|
14 |
<script>
|
@@ -118,7 +147,7 @@ def app():
|
|
118 |
)
|
119 |
|
120 |
# Output area for menu items
|
121 |
-
menu_output = gr.HTML(value="
|
122 |
|
123 |
# Floating cart display
|
124 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
@@ -174,6 +203,9 @@ def app():
|
|
174 |
# Finalize order button click event
|
175 |
finalize_button.click(lambda: "Order finalized!", outputs=[final_order_output])
|
176 |
|
|
|
|
|
|
|
177 |
# Layout
|
178 |
gr.Row([selected_preference])
|
179 |
gr.Row(menu_output)
|
|
|
9 |
except Exception as e:
|
10 |
raise ValueError(f"Error loading menu file: {e}")
|
11 |
|
12 |
+
# Function to filter menu items based on preference
|
13 |
+
def filter_menu(preference):
|
14 |
+
menu_data = load_menu()
|
15 |
+
if preference == "Halal/Non-Veg":
|
16 |
+
filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
17 |
+
elif preference == "Vegetarian":
|
18 |
+
filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
19 |
+
elif preference == "Guilt-Free":
|
20 |
+
filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
|
21 |
+
else:
|
22 |
+
filtered_data = menu_data
|
23 |
+
|
24 |
+
html_content = ""
|
25 |
+
for _, item in filtered_data.iterrows():
|
26 |
+
html_content += f"""
|
27 |
+
<div style=\"display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);\">
|
28 |
+
<div style=\"flex: 1; margin-right: 15px;\">
|
29 |
+
<h3 style=\"margin: 0; font-size: 18px;\">{item['Dish Name']}</h3>
|
30 |
+
<p style=\"margin: 5px 0; font-size: 16px; color: #888;\">${item['Price ($)']}</p>
|
31 |
+
<p style=\"margin: 5px 0; font-size: 14px; color: #555;\">{item['Description']}</p>
|
32 |
+
</div>
|
33 |
+
<div style=\"flex-shrink: 0; text-align: center;\">
|
34 |
+
<img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
|
35 |
+
<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>
|
36 |
+
</div>
|
37 |
+
</div>
|
38 |
+
"""
|
39 |
+
return html_content
|
40 |
+
|
41 |
# JavaScript for modal and cart behavior
|
42 |
modal_and_cart_js = """
|
43 |
<script>
|
|
|
147 |
)
|
148 |
|
149 |
# Output area for menu items
|
150 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
151 |
|
152 |
# Floating cart display
|
153 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
|
|
203 |
# Finalize order button click event
|
204 |
finalize_button.click(lambda: "Order finalized!", outputs=[final_order_output])
|
205 |
|
206 |
+
# Update menu dynamically based on preference
|
207 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
208 |
+
|
209 |
# Layout
|
210 |
gr.Row([selected_preference])
|
211 |
gr.Row(menu_output)
|