Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,12 @@ import gradio as gr
|
|
2 |
from components.cards import create_food_card
|
3 |
from components.data import FOOD_DATA
|
4 |
|
5 |
-
# Function to render the popup card when
|
6 |
def display_card(food_name):
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
# Gradio app interface
|
10 |
with gr.Blocks(css="styles.css") as app:
|
@@ -17,18 +20,18 @@ with gr.Blocks(css="styles.css") as app:
|
|
17 |
)
|
18 |
|
19 |
# Display all items as clickable cards
|
20 |
-
with gr.Row():
|
21 |
for food_name in FOOD_DATA.keys():
|
22 |
with gr.Column():
|
23 |
-
# Each
|
24 |
gr.Button(
|
25 |
value=food_name,
|
26 |
elem_id=f"food-{food_name.replace(' ', '-').lower()}",
|
27 |
interactive=True,
|
28 |
-
).click(display_card, inputs=
|
29 |
|
30 |
# Display area for the popup card
|
31 |
-
display_area = gr.HTML()
|
32 |
|
33 |
# Launch the app
|
34 |
app.launch()
|
|
|
2 |
from components.cards import create_food_card
|
3 |
from components.data import FOOD_DATA
|
4 |
|
5 |
+
# Function to render the popup card when a button is clicked
|
6 |
def display_card(food_name):
|
7 |
+
if food_name in FOOD_DATA:
|
8 |
+
return create_food_card(food_name)
|
9 |
+
else:
|
10 |
+
return "<p>No data available for the selected item.</p>"
|
11 |
|
12 |
# Gradio app interface
|
13 |
with gr.Blocks(css="styles.css") as app:
|
|
|
20 |
)
|
21 |
|
22 |
# Display all items as clickable cards
|
23 |
+
with gr.Row(elem_id="food-list"):
|
24 |
for food_name in FOOD_DATA.keys():
|
25 |
with gr.Column():
|
26 |
+
# Each button is a card for a food item
|
27 |
gr.Button(
|
28 |
value=food_name,
|
29 |
elem_id=f"food-{food_name.replace(' ', '-').lower()}",
|
30 |
interactive=True,
|
31 |
+
).click(display_card, inputs=[gr.Textbox(value=food_name, visible=False)], outputs="display-area")
|
32 |
|
33 |
# Display area for the popup card
|
34 |
+
display_area = gr.HTML(elem_id="display-area")
|
35 |
|
36 |
# Launch the app
|
37 |
app.launch()
|