SathvikGanta commited on
Commit
ff2929a
Β·
verified Β·
1 Parent(s): d4dab20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -2,15 +2,9 @@ import gradio as gr
2
  from components.cards import create_food_card
3
  from components.data import FOOD_DATA
4
 
5
- # Function to display the food card when an item is selected
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
- # List of food items
13
- food_items = list(FOOD_DATA.keys())
14
 
15
  # Gradio app interface
16
  with gr.Blocks(css="styles.css") as app:
@@ -18,22 +12,23 @@ with gr.Blocks(css="styles.css") as app:
18
  gr.Markdown(
19
  """
20
  ### Explore Popular Dishes πŸ›
21
- Select a dish from the dropdown menu to see its image, nutritional facts, and portion size.
22
  """
23
  )
24
 
 
25
  with gr.Row():
26
- with gr.Column(scale=1):
27
- food_dropdown = gr.Dropdown(
28
- label="Select a Dish",
29
- choices=food_items,
30
- value=food_items[0],
31
- )
32
- with gr.Column(scale=2):
33
- display_area = gr.HTML(value=create_food_card(food_items[0]))
34
 
35
- # Event to update card content when a food item is selected
36
- food_dropdown.change(display_card, inputs=food_dropdown, outputs=display_area)
37
 
38
  # Launch the app
39
  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 an item is clicked
6
  def display_card(food_name):
7
+ return create_food_card(food_name)
 
 
 
 
 
 
8
 
9
  # Gradio app interface
10
  with gr.Blocks(css="styles.css") as app:
 
12
  gr.Markdown(
13
  """
14
  ### Explore Popular Dishes πŸ›
15
+ Click on any dish card below to view its image, nutritional facts, and portion size.
16
  """
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 item card is a clickable button
24
+ gr.Button(
25
+ value=food_name,
26
+ elem_id=f"food-{food_name.replace(' ', '-').lower()}",
27
+ interactive=True,
28
+ ).click(display_card, inputs=None, outputs=gr.HTML())
29
 
30
+ # Display area for the popup card
31
+ display_area = gr.HTML()
32
 
33
  # Launch the app
34
  app.launch()