Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,23 +34,23 @@ def filter_menu(preference):
|
|
34 |
</div>
|
35 |
<div style="flex-shrink: 0; text-align: center;">
|
36 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
37 |
-
<button value="{item['Dish Name']}" onclick="
|
38 |
</div>
|
39 |
</div>
|
40 |
"""
|
41 |
return html_content
|
42 |
|
43 |
-
# Function to render
|
44 |
def render_dish_details(dish_name):
|
45 |
-
print(f"
|
46 |
menu_data = load_menu()
|
47 |
try:
|
48 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
49 |
return (
|
50 |
-
dish["Image URL"],
|
51 |
-
|
52 |
-
dish["Description"],
|
53 |
-
f"${dish['Price ($)']}"
|
54 |
)
|
55 |
except IndexError:
|
56 |
raise ValueError(f"Dish '{dish_name}' not found!")
|
@@ -58,14 +58,19 @@ def render_dish_details(dish_name):
|
|
58 |
# Gradio app definition
|
59 |
def app():
|
60 |
with gr.Blocks() as demo:
|
61 |
-
gr.Markdown("## Menu with
|
62 |
|
63 |
-
selected_dish = gr.State("") #
|
64 |
|
65 |
-
# Menu
|
|
|
|
|
|
|
|
|
|
|
66 |
menu_html = gr.HTML(value=filter_menu("All"))
|
67 |
|
68 |
-
# Suggestion page
|
69 |
suggestion_page = gr.Column(visible=False)
|
70 |
dish_image = gr.Image(label="Dish Image")
|
71 |
dish_name = gr.Markdown()
|
@@ -73,6 +78,9 @@ def app():
|
|
73 |
dish_price = gr.Markdown()
|
74 |
|
75 |
# Functions
|
|
|
|
|
|
|
76 |
def show_suggestion(dish_name):
|
77 |
try:
|
78 |
img, name, desc, price = render_dish_details(dish_name)
|
@@ -80,14 +88,27 @@ def app():
|
|
80 |
gr.update(visible=False),
|
81 |
gr.update(visible=True),
|
82 |
img,
|
83 |
-
name,
|
84 |
desc,
|
85 |
-
price
|
86 |
)
|
87 |
except ValueError as e:
|
88 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Event Handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
menu_html.change(
|
92 |
show_suggestion,
|
93 |
inputs=[selected_dish],
|
|
|
34 |
</div>
|
35 |
<div style="flex-shrink: 0; text-align: center;">
|
36 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
37 |
+
<button value="{item['Dish Name']}" onclick="selectDish('{item['Dish Name']}')" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
|
38 |
</div>
|
39 |
</div>
|
40 |
"""
|
41 |
return html_content
|
42 |
|
43 |
+
# Function to render dish details for the suggestion page
|
44 |
def render_dish_details(dish_name):
|
45 |
+
print(f"Dish name received: {dish_name}") # Debugging line
|
46 |
menu_data = load_menu()
|
47 |
try:
|
48 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
49 |
return (
|
50 |
+
dish["Image URL"],
|
51 |
+
dish_name,
|
52 |
+
dish["Description"],
|
53 |
+
f"${dish['Price ($)']}"
|
54 |
)
|
55 |
except IndexError:
|
56 |
raise ValueError(f"Dish '{dish_name}' not found!")
|
|
|
58 |
# Gradio app definition
|
59 |
def app():
|
60 |
with gr.Blocks() as demo:
|
61 |
+
gr.Markdown("## Menu with Dynamic Filters")
|
62 |
|
63 |
+
selected_dish = gr.State("") # State for the selected dish name
|
64 |
|
65 |
+
# Menu components
|
66 |
+
preference_selector = gr.Radio(
|
67 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
68 |
+
value="All",
|
69 |
+
label="Choose a Preference"
|
70 |
+
)
|
71 |
menu_html = gr.HTML(value=filter_menu("All"))
|
72 |
|
73 |
+
# Suggestion page components
|
74 |
suggestion_page = gr.Column(visible=False)
|
75 |
dish_image = gr.Image(label="Dish Image")
|
76 |
dish_name = gr.Markdown()
|
|
|
78 |
dish_price = gr.Markdown()
|
79 |
|
80 |
# Functions
|
81 |
+
def update_menu(preference):
|
82 |
+
return filter_menu(preference)
|
83 |
+
|
84 |
def show_suggestion(dish_name):
|
85 |
try:
|
86 |
img, name, desc, price = render_dish_details(dish_name)
|
|
|
88 |
gr.update(visible=False),
|
89 |
gr.update(visible=True),
|
90 |
img,
|
91 |
+
f"## {name}",
|
92 |
desc,
|
93 |
+
price
|
94 |
)
|
95 |
except ValueError as e:
|
96 |
+
return (
|
97 |
+
gr.update(visible=True),
|
98 |
+
gr.update(visible=False),
|
99 |
+
"",
|
100 |
+
f"Error: {str(e)}",
|
101 |
+
"",
|
102 |
+
""
|
103 |
+
)
|
104 |
|
105 |
# Event Handlers
|
106 |
+
preference_selector.change(
|
107 |
+
update_menu,
|
108 |
+
inputs=[preference_selector],
|
109 |
+
outputs=[menu_html]
|
110 |
+
)
|
111 |
+
|
112 |
menu_html.change(
|
113 |
show_suggestion,
|
114 |
inputs=[selected_dish],
|