Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,120 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
menu_dropdown.change(
|
3 |
show_dish_details,
|
4 |
inputs=[menu_dropdown],
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
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 |
+
# Generate menu as a list of tuples (dish_name, button_label)
|
26 |
+
return [{"label": f"{row['Dish Name']} - ${row['Price ($)']}", "value": row['Dish Name']} for _, row in filtered_data.iterrows()]
|
27 |
+
|
28 |
+
# Dish details view
|
29 |
+
def render_dish_details(dish_name):
|
30 |
+
menu_data = load_menu()
|
31 |
+
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
32 |
+
return (
|
33 |
+
dish["Image URL"],
|
34 |
+
dish_name,
|
35 |
+
dish["Description"],
|
36 |
+
dish["Price ($)"]
|
37 |
+
)
|
38 |
+
|
39 |
+
# Add to cart function
|
40 |
+
def add_to_cart(dish_name, spice_level, extras, quantity, special_instructions, cart):
|
41 |
+
cart.append({
|
42 |
+
"name": dish_name,
|
43 |
+
"spice_level": spice_level,
|
44 |
+
"extras": extras,
|
45 |
+
"quantity": quantity,
|
46 |
+
"instructions": special_instructions
|
47 |
+
})
|
48 |
+
return cart, f"Added {dish_name} to cart!"
|
49 |
+
|
50 |
+
# Gradio app
|
51 |
+
def app():
|
52 |
+
with gr.Blocks() as demo:
|
53 |
+
cart_state = gr.State([])
|
54 |
+
|
55 |
+
# Menu page
|
56 |
+
menu_dropdown = gr.Dropdown(
|
57 |
+
label="Select a dish to view details",
|
58 |
+
choices=[],
|
59 |
+
interactive=True,
|
60 |
+
)
|
61 |
+
menu_output = gr.Dropdown(interactive=True)
|
62 |
+
|
63 |
+
# Dish details view
|
64 |
+
detailed_view = gr.Column(visible=False)
|
65 |
+
dish_image = gr.Image()
|
66 |
+
dish_name = gr.Markdown()
|
67 |
+
dish_description = gr.Markdown()
|
68 |
+
dish_price = gr.Markdown()
|
69 |
+
spice_level = gr.Radio(
|
70 |
+
choices=["Mild", "Medium", "Spicy"],
|
71 |
+
label="Choose Spice Level",
|
72 |
+
)
|
73 |
+
extras = gr.CheckboxGroup(
|
74 |
+
choices=["Extra Raita", "Extra Salan", "Extra Fried Onion"],
|
75 |
+
label="Choose Extras",
|
76 |
+
)
|
77 |
+
quantity = gr.Number(label="Quantity", value=1, interactive=True)
|
78 |
+
special_instructions = gr.Textbox(
|
79 |
+
label="Special Instructions",
|
80 |
+
placeholder="Add any special instructions here",
|
81 |
+
)
|
82 |
+
add_button = gr.Button("Add to Cart")
|
83 |
+
back_button = gr.Button("Back to Menu")
|
84 |
+
cart_view = gr.HTML(value="Your cart is empty.")
|
85 |
+
|
86 |
+
# Show the menu
|
87 |
+
def update_menu(preference):
|
88 |
+
return render_menu(preference)
|
89 |
+
|
90 |
+
# Show dish details
|
91 |
+
def show_dish_details(dish_name):
|
92 |
+
img, name, desc, price = render_dish_details(dish_name)
|
93 |
+
return (
|
94 |
+
gr.update(visible=False),
|
95 |
+
gr.update(visible=True),
|
96 |
+
img,
|
97 |
+
f"## {name}",
|
98 |
+
desc,
|
99 |
+
f"**Price:** ${price}",
|
100 |
+
)
|
101 |
+
|
102 |
+
# Add to cart
|
103 |
+
def handle_add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
|
104 |
+
updated_cart, message = add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart)
|
105 |
+
cart_html = "<br>".join(
|
106 |
+
[f"{item['quantity']}x {item['name']} - {item['spice_level']}" for item in updated_cart]
|
107 |
+
)
|
108 |
+
return updated_cart, cart_html
|
109 |
+
|
110 |
+
# Update menu based on preference
|
111 |
+
menu_dropdown.change(
|
112 |
+
update_menu,
|
113 |
+
inputs=["All"],
|
114 |
+
outputs=[menu_view()],
|
115 |
+
)
|
116 |
+
|
117 |
+
# Show dish details when an item is selected
|
118 |
menu_dropdown.change(
|
119 |
show_dish_details,
|
120 |
inputs=[menu_dropdown],
|