Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,8 +34,9 @@ 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 style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;"
|
| 38 |
-
|
|
|
|
| 39 |
</div>
|
| 40 |
</div>
|
| 41 |
"""
|
|
@@ -57,7 +58,7 @@ def render_dish_details(dish_name):
|
|
| 57 |
|
| 58 |
# Gradio app definition
|
| 59 |
def app():
|
| 60 |
-
with gr.Blocks(title="Dynamic Menu with
|
| 61 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 62 |
|
| 63 |
# Radio button for selecting preference
|
|
@@ -70,8 +71,8 @@ def app():
|
|
| 70 |
# Main menu output area
|
| 71 |
menu_output = gr.HTML(value=filter_menu("All"), visible=True)
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
dish_image = gr.Image()
|
| 76 |
dish_name = gr.Markdown()
|
| 77 |
dish_description = gr.Markdown()
|
|
@@ -100,12 +101,12 @@ def app():
|
|
| 100 |
def update_menu(preference):
|
| 101 |
return filter_menu(preference)
|
| 102 |
|
| 103 |
-
def
|
| 104 |
try:
|
| 105 |
img, name, desc, price = render_dish_details(dish_name)
|
| 106 |
return (
|
| 107 |
gr.update(visible=False), # Hide menu
|
| 108 |
-
gr.update(visible=True), # Show
|
| 109 |
img,
|
| 110 |
name,
|
| 111 |
desc,
|
|
@@ -142,11 +143,11 @@ def app():
|
|
| 142 |
)
|
| 143 |
|
| 144 |
menu_output.change(
|
| 145 |
-
|
| 146 |
inputs=[menu_output],
|
| 147 |
outputs=[
|
| 148 |
menu_output,
|
| 149 |
-
|
| 150 |
dish_image,
|
| 151 |
dish_name,
|
| 152 |
dish_description,
|
|
@@ -162,14 +163,14 @@ def app():
|
|
| 162 |
|
| 163 |
back_button.click(
|
| 164 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 165 |
-
outputs=[menu_output,
|
| 166 |
)
|
| 167 |
|
| 168 |
# Layout
|
| 169 |
with gr.Row(visible=True):
|
| 170 |
menu_output
|
| 171 |
|
| 172 |
-
with
|
| 173 |
dish_image
|
| 174 |
dish_name
|
| 175 |
dish_description
|
|
|
|
| 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']}" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">
|
| 38 |
+
View Details
|
| 39 |
+
</button>
|
| 40 |
</div>
|
| 41 |
</div>
|
| 42 |
"""
|
|
|
|
| 58 |
|
| 59 |
# Gradio app definition
|
| 60 |
def app():
|
| 61 |
+
with gr.Blocks(title="Dynamic Menu with Suggestions Page") as demo:
|
| 62 |
gr.Markdown("## Dynamic Menu with Preferences")
|
| 63 |
|
| 64 |
# Radio button for selecting preference
|
|
|
|
| 71 |
# Main menu output area
|
| 72 |
menu_output = gr.HTML(value=filter_menu("All"), visible=True)
|
| 73 |
|
| 74 |
+
# Suggestion page components
|
| 75 |
+
suggestion_page = gr.Column(visible=False)
|
| 76 |
dish_image = gr.Image()
|
| 77 |
dish_name = gr.Markdown()
|
| 78 |
dish_description = gr.Markdown()
|
|
|
|
| 101 |
def update_menu(preference):
|
| 102 |
return filter_menu(preference)
|
| 103 |
|
| 104 |
+
def show_suggestion_page(dish_name):
|
| 105 |
try:
|
| 106 |
img, name, desc, price = render_dish_details(dish_name)
|
| 107 |
return (
|
| 108 |
gr.update(visible=False), # Hide menu
|
| 109 |
+
gr.update(visible=True), # Show suggestion page
|
| 110 |
img,
|
| 111 |
name,
|
| 112 |
desc,
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
menu_output.change(
|
| 146 |
+
show_suggestion_page,
|
| 147 |
inputs=[menu_output],
|
| 148 |
outputs=[
|
| 149 |
menu_output,
|
| 150 |
+
suggestion_page,
|
| 151 |
dish_image,
|
| 152 |
dish_name,
|
| 153 |
dish_description,
|
|
|
|
| 163 |
|
| 164 |
back_button.click(
|
| 165 |
lambda: (gr.update(visible=True), gr.update(visible=False)),
|
| 166 |
+
outputs=[menu_output, suggestion_page],
|
| 167 |
)
|
| 168 |
|
| 169 |
# Layout
|
| 170 |
with gr.Row(visible=True):
|
| 171 |
menu_output
|
| 172 |
|
| 173 |
+
with suggestion_page:
|
| 174 |
dish_image
|
| 175 |
dish_name
|
| 176 |
dish_description
|