Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ def filter_menu(preference):
|
|
| 36 |
</div>
|
| 37 |
<div style="flex-shrink: 0; text-align: center;">
|
| 38 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
| 39 |
-
<button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;"
|
| 40 |
onclick="return '{item['Dish Name']}'">Add</button>
|
| 41 |
</div>
|
| 42 |
</div>
|
|
@@ -47,17 +47,12 @@ def filter_menu(preference):
|
|
| 47 |
def render_dish_details(dish_name):
|
| 48 |
menu_data = load_menu()
|
| 49 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
<p style="font-size: 16px; color: #555;">{dish['Description']}</p>
|
| 57 |
-
<h4>${dish['Price ($)']}</h4>
|
| 58 |
-
</div>
|
| 59 |
-
"""
|
| 60 |
-
return details_html
|
| 61 |
|
| 62 |
# Gradio app definition
|
| 63 |
def app():
|
|
@@ -76,7 +71,10 @@ def app():
|
|
| 76 |
|
| 77 |
# Detailed view
|
| 78 |
detailed_view = gr.Column(visible=False)
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
spice_level = gr.Radio(
|
| 81 |
choices=["Mild", "Medium", "Spicy"],
|
| 82 |
label="Choose Spice Level",
|
|
@@ -102,8 +100,8 @@ def app():
|
|
| 102 |
return filter_menu(preference)
|
| 103 |
|
| 104 |
def show_dish_details(dish_name):
|
| 105 |
-
|
| 106 |
-
return gr.update(visible=False), gr.update(visible=True),
|
| 107 |
|
| 108 |
def add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
|
| 109 |
cart.append({
|
|
@@ -128,12 +126,12 @@ def app():
|
|
| 128 |
menu_output.change(
|
| 129 |
show_dish_details,
|
| 130 |
inputs=[menu_output],
|
| 131 |
-
outputs=[menu_output, detailed_view,
|
| 132 |
)
|
| 133 |
|
| 134 |
add_to_bag_button.click(
|
| 135 |
add_to_cart,
|
| 136 |
-
inputs=[
|
| 137 |
outputs=[cart_state, cart_output],
|
| 138 |
)
|
| 139 |
|
|
@@ -147,7 +145,10 @@ def app():
|
|
| 147 |
menu_output
|
| 148 |
|
| 149 |
with detailed_view:
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
| 151 |
spice_level
|
| 152 |
extras
|
| 153 |
quantity
|
|
@@ -160,7 +161,7 @@ def app():
|
|
| 160 |
|
| 161 |
return demo
|
| 162 |
|
| 163 |
-
|
| 164 |
if __name__ == "__main__":
|
| 165 |
demo = app()
|
| 166 |
demo.launch()
|
|
|
|
| 36 |
</div>
|
| 37 |
<div style="flex-shrink: 0; text-align: center;">
|
| 38 |
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
| 39 |
+
<button value="{item['Dish Name']}" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;"
|
| 40 |
onclick="return '{item['Dish Name']}'">Add</button>
|
| 41 |
</div>
|
| 42 |
</div>
|
|
|
|
| 47 |
def render_dish_details(dish_name):
|
| 48 |
menu_data = load_menu()
|
| 49 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
| 50 |
+
return (
|
| 51 |
+
dish["Image URL"],
|
| 52 |
+
f"## {dish_name}",
|
| 53 |
+
dish["Description"],
|
| 54 |
+
f"**Price:** ${dish['Price ($)']}"
|
| 55 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# Gradio app definition
|
| 58 |
def app():
|
|
|
|
| 71 |
|
| 72 |
# Detailed view
|
| 73 |
detailed_view = gr.Column(visible=False)
|
| 74 |
+
dish_image = gr.Image()
|
| 75 |
+
dish_name = gr.Markdown()
|
| 76 |
+
dish_description = gr.Markdown()
|
| 77 |
+
dish_price = gr.Markdown()
|
| 78 |
spice_level = gr.Radio(
|
| 79 |
choices=["Mild", "Medium", "Spicy"],
|
| 80 |
label="Choose Spice Level",
|
|
|
|
| 100 |
return filter_menu(preference)
|
| 101 |
|
| 102 |
def show_dish_details(dish_name):
|
| 103 |
+
img, name, desc, price = render_dish_details(dish_name)
|
| 104 |
+
return gr.update(visible=False), gr.update(visible=True), img, name, desc, price
|
| 105 |
|
| 106 |
def add_to_cart(dish_name, spice_level, extras, quantity, instructions, cart):
|
| 107 |
cart.append({
|
|
|
|
| 126 |
menu_output.change(
|
| 127 |
show_dish_details,
|
| 128 |
inputs=[menu_output],
|
| 129 |
+
outputs=[menu_output, detailed_view, dish_image, dish_name, dish_description, dish_price],
|
| 130 |
)
|
| 131 |
|
| 132 |
add_to_bag_button.click(
|
| 133 |
add_to_cart,
|
| 134 |
+
inputs=[dish_name, spice_level, extras, quantity, special_instructions, cart_state],
|
| 135 |
outputs=[cart_state, cart_output],
|
| 136 |
)
|
| 137 |
|
|
|
|
| 145 |
menu_output
|
| 146 |
|
| 147 |
with detailed_view:
|
| 148 |
+
dish_image
|
| 149 |
+
dish_name
|
| 150 |
+
dish_description
|
| 151 |
+
dish_price
|
| 152 |
spice_level
|
| 153 |
extras
|
| 154 |
quantity
|
|
|
|
| 161 |
|
| 162 |
return demo
|
| 163 |
|
| 164 |
+
|
| 165 |
if __name__ == "__main__":
|
| 166 |
demo = app()
|
| 167 |
demo.launch()
|