Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,105 +1,57 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
# Load menu data from Excel
|
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 |
-
# Main menu view
|
13 |
-
def render_menu(preference):
|
14 |
-
menu_data = load_menu()
|
15 |
-
|
16 |
-
if preference == "Halal/Non-Veg":
|
17 |
-
filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
18 |
-
elif preference == "Vegetarian":
|
19 |
-
filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
20 |
-
elif preference == "Guilt-Free":
|
21 |
-
filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
|
22 |
-
else:
|
23 |
-
filtered_data = menu_data
|
24 |
-
|
25 |
-
menu_html = ""
|
26 |
-
for _, item in filtered_data.iterrows():
|
27 |
-
menu_html += f"""
|
28 |
-
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px;">
|
29 |
-
<div style="flex: 1; margin-right: 15px;">
|
30 |
-
<h3 style="margin: 0;">{item['Dish Name']}</h3>
|
31 |
-
<p style="margin: 5px 0;">${item['Price ($)']}</p>
|
32 |
-
<p>{item['Description']}</p>
|
33 |
-
</div>
|
34 |
-
<div>
|
35 |
-
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover;">
|
36 |
-
<button style="background-color: #28a745; color: white; padding: 8px 15px; border: none; cursor: pointer;"
|
37 |
-
onclick="return '{item['Dish Name']}'">View Details</button>
|
38 |
-
</div>
|
39 |
-
</div>
|
40 |
-
"""
|
41 |
-
return menu_html
|
42 |
-
|
43 |
-
# Dish details view
|
44 |
-
def render_dish_details(dish_name):
|
45 |
-
menu_data = load_menu()
|
46 |
-
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
47 |
-
return {
|
48 |
-
"image": dish["Image URL"],
|
49 |
-
"name": dish_name,
|
50 |
-
"description": dish["Description"],
|
51 |
-
"price": dish["Price ($)"]
|
52 |
-
}
|
53 |
-
|
54 |
-
# Add to cart
|
55 |
-
def add_to_cart(dish_name, spice_level, extras, quantity, special_instructions, cart):
|
56 |
-
cart.append({
|
57 |
-
"name": dish_name,
|
58 |
-
"spice_level": spice_level,
|
59 |
-
"extras": extras,
|
60 |
-
"quantity": quantity,
|
61 |
-
"instructions": special_instructions
|
62 |
-
})
|
63 |
-
return cart, f"Added {dish_name} to cart!"
|
64 |
-
|
65 |
-
# Gradio app
|
66 |
-
def app():
|
67 |
-
with gr.Blocks() as demo:
|
68 |
-
cart_state = gr.State([])
|
69 |
-
|
70 |
-
# Menu page
|
71 |
-
menu_html = gr.HTML(render_menu("All"))
|
72 |
-
detailed_view = gr.Column(visible=False)
|
73 |
-
cart_view = gr.Column(visible=False)
|
74 |
-
|
75 |
-
# Detailed view inputs
|
76 |
-
spice_level = gr.Dropdown(choices=["Mild", "Medium", "Spicy"], label="Spice Level")
|
77 |
-
extras = gr.CheckboxGroup(choices=["Extra Raita", "Extra Salan", "Extra Onion"], label="Extras")
|
78 |
-
quantity = gr.Number(value=1, label="Quantity")
|
79 |
-
special_instructions = gr.Textbox(placeholder="Add instructions", label="Special Instructions")
|
80 |
-
add_button = gr.Button("Add to Cart")
|
81 |
-
back_button = gr.Button("Back to Menu")
|
82 |
-
|
83 |
-
# Cart view
|
84 |
-
cart_html = gr.HTML(value="Your cart is empty.")
|
85 |
-
|
86 |
-
# Switch to detailed view
|
87 |
-
def show_dish_details(dish_name):
|
88 |
-
details = render_dish_details(dish_name)
|
89 |
-
return gr.update(visible=False), gr.update(visible=True), details["image"], details["name"], details["description"], details["price"]
|
90 |
-
|
91 |
-
# Add to cart
|
92 |
-
def handle_add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
|
93 |
-
return add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart)
|
94 |
-
|
95 |
-
# Navigation
|
96 |
-
menu_html.change(show_dish_details, inputs=["dish_name"], outputs=[menu_html, detailed_view])
|
97 |
-
|
98 |
-
add_button.click(handle_add_to_cart, inputs=[spice_level, extras, quantity, special_instructions, cart_state], outputs=[cart_state, cart_html])
|
99 |
-
|
100 |
-
back_button.click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[menu_html, detailed_view])
|
101 |
-
|
102 |
-
return demo
|
103 |
|
104 |
if __name__ == "__main__":
|
105 |
demo = app()
|
|
|
1 |
+
# Show dish details when an item is selected
|
2 |
+
menu_dropdown.change(
|
3 |
+
show_dish_details,
|
4 |
+
inputs=[menu_dropdown],
|
5 |
+
outputs=[
|
6 |
+
menu_dropdown,
|
7 |
+
detailed_view,
|
8 |
+
dish_image,
|
9 |
+
dish_name,
|
10 |
+
dish_description,
|
11 |
+
dish_price,
|
12 |
+
],
|
13 |
+
)
|
14 |
+
|
15 |
+
# Handle adding items to the cart
|
16 |
+
add_button.click(
|
17 |
+
handle_add_to_cart,
|
18 |
+
inputs=[
|
19 |
+
dish_name,
|
20 |
+
spice_level,
|
21 |
+
extras,
|
22 |
+
quantity,
|
23 |
+
special_instructions,
|
24 |
+
cart_state,
|
25 |
+
],
|
26 |
+
outputs=[cart_state, cart_view],
|
27 |
+
)
|
28 |
+
|
29 |
+
# Back button to return to menu
|
30 |
+
back_button.click(
|
31 |
+
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
32 |
+
outputs=[menu_dropdown, detailed_view],
|
33 |
+
)
|
34 |
+
|
35 |
+
# Layout for Gradio app
|
36 |
+
with gr.Row():
|
37 |
+
gr.Markdown("## Menu")
|
38 |
+
menu_dropdown
|
39 |
+
cart_view
|
40 |
+
|
41 |
+
with detailed_view:
|
42 |
+
dish_image
|
43 |
+
dish_name
|
44 |
+
dish_description
|
45 |
+
dish_price
|
46 |
+
spice_level
|
47 |
+
extras
|
48 |
+
quantity
|
49 |
+
special_instructions
|
50 |
+
add_button
|
51 |
+
back_button
|
52 |
+
|
53 |
+
return demo
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
demo = app()
|