Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
-
#
|
5 |
def load_menu():
|
6 |
try:
|
7 |
-
return pd.read_excel("menu.xlsx") # Ensure menu.xlsx
|
8 |
except Exception as e:
|
9 |
raise ValueError(f"Error loading menu file: {e}")
|
10 |
|
@@ -25,7 +25,7 @@ def filter_menu(preference):
|
|
25 |
for _, item in filtered_data.iterrows():
|
26 |
html_content += f"""
|
27 |
<div class="menu-item">
|
28 |
-
<img src="{item['Image URL']}" alt="{item['Dish Name']}">
|
29 |
<h3>{item['Dish Name']}</h3>
|
30 |
<p>{item['Description']}</p>
|
31 |
<p><strong>${item['Price ($)']}</strong></p>
|
@@ -41,9 +41,9 @@ def get_dish_details(dish_name):
|
|
41 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
42 |
return (
|
43 |
dish["Image URL"],
|
44 |
-
|
45 |
dish["Description"],
|
46 |
-
dish[
|
47 |
dish["Ingredients"]
|
48 |
)
|
49 |
except IndexError:
|
@@ -52,9 +52,9 @@ def get_dish_details(dish_name):
|
|
52 |
# Main Gradio app
|
53 |
def app():
|
54 |
with gr.Blocks(css="style.css") as demo:
|
55 |
-
gr.Markdown("## Dynamic Menu with Modal
|
56 |
|
57 |
-
#
|
58 |
preference_selector = gr.Radio(
|
59 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
60 |
value="All",
|
@@ -62,7 +62,7 @@ def app():
|
|
62 |
)
|
63 |
menu_output = gr.HTML(value=filter_menu("All"))
|
64 |
|
65 |
-
# Modal
|
66 |
modal = gr.Column(visible=False, elem_classes=["popup"])
|
67 |
modal_image = gr.Image(label="Dish Image")
|
68 |
modal_name = gr.Markdown()
|
@@ -75,11 +75,11 @@ def app():
|
|
75 |
add_to_cart_button = gr.Button("Add to Cart")
|
76 |
close_modal_button = gr.Button("Close")
|
77 |
|
78 |
-
# Cart
|
79 |
cart_state = gr.State([])
|
80 |
cart_output = gr.HTML(value="Your cart is empty.")
|
81 |
|
82 |
-
#
|
83 |
def update_menu(preference):
|
84 |
return filter_menu(preference)
|
85 |
|
@@ -90,7 +90,7 @@ def app():
|
|
90 |
img,
|
91 |
f"### {name}",
|
92 |
f"**Description:** {desc}\n\n**Ingredients:** {ingredients}",
|
93 |
-
|
94 |
)
|
95 |
|
96 |
def close_modal():
|
@@ -110,7 +110,7 @@ def app():
|
|
110 |
)
|
111 |
return cart, cart_html
|
112 |
|
113 |
-
#
|
114 |
preference_selector.change(update_menu, inputs=[preference_selector], outputs=[menu_output])
|
115 |
menu_output.change(show_modal, inputs=[menu_output], outputs=[modal, modal_image, modal_name, modal_description, modal_price])
|
116 |
close_modal_button.click(close_modal, outputs=[modal])
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
+
# Function to load menu data from Excel
|
5 |
def load_menu():
|
6 |
try:
|
7 |
+
return pd.read_excel("menu.xlsx") # Ensure menu.xlsx exists in the same directory
|
8 |
except Exception as e:
|
9 |
raise ValueError(f"Error loading menu file: {e}")
|
10 |
|
|
|
25 |
for _, item in filtered_data.iterrows():
|
26 |
html_content += f"""
|
27 |
<div class="menu-item">
|
28 |
+
<img src="{item['Image URL']}" alt="{item['Dish Name']}" class="dish-image">
|
29 |
<h3>{item['Dish Name']}</h3>
|
30 |
<p>{item['Description']}</p>
|
31 |
<p><strong>${item['Price ($)']}</strong></p>
|
|
|
41 |
dish = menu_data[menu_data["Dish Name"] == dish_name].iloc[0]
|
42 |
return (
|
43 |
dish["Image URL"],
|
44 |
+
dish_name,
|
45 |
dish["Description"],
|
46 |
+
f"${dish['Price ($)']}",
|
47 |
dish["Ingredients"]
|
48 |
)
|
49 |
except IndexError:
|
|
|
52 |
# Main Gradio app
|
53 |
def app():
|
54 |
with gr.Blocks(css="style.css") as demo:
|
55 |
+
gr.Markdown("## Dynamic Menu with Modal Window")
|
56 |
|
57 |
+
# Home page menu
|
58 |
preference_selector = gr.Radio(
|
59 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
60 |
value="All",
|
|
|
62 |
)
|
63 |
menu_output = gr.HTML(value=filter_menu("All"))
|
64 |
|
65 |
+
# Modal (hidden by default)
|
66 |
modal = gr.Column(visible=False, elem_classes=["popup"])
|
67 |
modal_image = gr.Image(label="Dish Image")
|
68 |
modal_name = gr.Markdown()
|
|
|
75 |
add_to_cart_button = gr.Button("Add to Cart")
|
76 |
close_modal_button = gr.Button("Close")
|
77 |
|
78 |
+
# Cart
|
79 |
cart_state = gr.State([])
|
80 |
cart_output = gr.HTML(value="Your cart is empty.")
|
81 |
|
82 |
+
# Handlers
|
83 |
def update_menu(preference):
|
84 |
return filter_menu(preference)
|
85 |
|
|
|
90 |
img,
|
91 |
f"### {name}",
|
92 |
f"**Description:** {desc}\n\n**Ingredients:** {ingredients}",
|
93 |
+
price
|
94 |
)
|
95 |
|
96 |
def close_modal():
|
|
|
110 |
)
|
111 |
return cart, cart_html
|
112 |
|
113 |
+
# Events
|
114 |
preference_selector.change(update_menu, inputs=[preference_selector], outputs=[menu_output])
|
115 |
menu_output.change(show_modal, inputs=[menu_output], outputs=[modal, modal_image, modal_name, modal_description, modal_price])
|
116 |
close_modal_button.click(close_modal, outputs=[modal])
|