Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,86 +9,63 @@ def load_menu():
|
|
9 |
except Exception as e:
|
10 |
raise ValueError(f"Error loading menu file: {e}")
|
11 |
|
12 |
-
# Function to
|
13 |
-
def
|
|
|
14 |
menu_data = load_menu()
|
15 |
-
return list(menu_data["Category"].unique())
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
item
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
</div>
|
43 |
-
|
44 |
-
"""
|
45 |
return html_content
|
46 |
|
47 |
# Gradio app definition
|
48 |
def app():
|
49 |
-
with gr.Blocks(title="Dynamic Menu with
|
50 |
-
|
51 |
-
|
52 |
-
# Dropdown for selecting a category
|
53 |
-
category_dropdown = gr.Dropdown(
|
54 |
-
choices=get_categories(),
|
55 |
-
value="Appetizer",
|
56 |
-
label="Select a Category",
|
57 |
-
)
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
choices=
|
62 |
-
value="
|
63 |
-
label="
|
64 |
)
|
65 |
|
66 |
-
# Output area for
|
67 |
-
menu_output = gr.HTML()
|
68 |
|
69 |
# Define interactivity
|
70 |
-
|
71 |
-
return gr.update(choices=get_dishes(category), value=get_dishes(category)[0])
|
72 |
-
|
73 |
-
category_dropdown.change(
|
74 |
-
update_dishes,
|
75 |
-
inputs=[category_dropdown],
|
76 |
-
outputs=[dish_dropdown]
|
77 |
-
)
|
78 |
-
|
79 |
-
dish_dropdown.change(
|
80 |
-
get_menu_item,
|
81 |
-
inputs=[dish_dropdown],
|
82 |
-
outputs=[menu_output]
|
83 |
-
)
|
84 |
-
|
85 |
-
# Layout
|
86 |
-
gr.Row([category_dropdown, dish_dropdown])
|
87 |
-
gr.Row(menu_output)
|
88 |
|
89 |
return demo
|
90 |
|
91 |
# Run the app
|
92 |
if __name__ == "__main__":
|
93 |
demo = app()
|
94 |
-
demo.launch()
|
|
|
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 |
+
# Load menu data
|
15 |
menu_data = load_menu()
|
|
|
16 |
|
17 |
+
# Check for the required columns
|
18 |
+
required_columns = ["Category", "Dish Name", "Price ($)", "Image URL", "Description"]
|
19 |
+
for col in required_columns:
|
20 |
+
if col not in menu_data.columns:
|
21 |
+
raise ValueError(f"Missing column in Excel file: {col}")
|
22 |
|
23 |
+
# Filter data based on preference
|
24 |
+
if preference != "All":
|
25 |
+
filtered_data = menu_data[menu_data["Category"].str.contains(preference, case=False, na=False)]
|
26 |
+
else:
|
27 |
+
filtered_data = menu_data
|
28 |
+
|
29 |
+
# Generate HTML for the menu
|
30 |
+
html_content = ""
|
31 |
+
for _, item in filtered_data.iterrows():
|
32 |
+
html_content += f"""
|
33 |
+
<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);">
|
34 |
+
<div style="flex: 1; margin-right: 15px;">
|
35 |
+
<h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
|
36 |
+
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
|
37 |
+
<p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
|
38 |
+
</div>
|
39 |
+
<div style="flex-shrink: 0; text-align: center;">
|
40 |
+
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
41 |
+
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
|
42 |
+
</div>
|
43 |
</div>
|
44 |
+
"""
|
|
|
45 |
return html_content
|
46 |
|
47 |
# Gradio app definition
|
48 |
def app():
|
49 |
+
with gr.Blocks(title="Dynamic Menu with Preferences") as demo:
|
50 |
+
# Add a title
|
51 |
+
gr.Markdown("## Dynamic Menu with Preferences")
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
# Radio button for selecting preference
|
54 |
+
selected_preference = gr.Radio(
|
55 |
+
choices=["All", "Vegan", "Halal", "Guilt-Free"],
|
56 |
+
value="All",
|
57 |
+
label="Choose a Preference",
|
58 |
)
|
59 |
|
60 |
+
# Output area for menu items
|
61 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
62 |
|
63 |
# Define interactivity
|
64 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
return demo
|
67 |
|
68 |
# Run the app
|
69 |
if __name__ == "__main__":
|
70 |
demo = app()
|
71 |
+
demo.launch()
|