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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -73
app.py CHANGED
@@ -1,74 +1,39 @@
1
  import gradio as gr
2
-
3
- # Define menu items
4
- menu_items = [
5
- {
6
- "name": "Chicken Butter Masala",
7
- "description": "A creamy and rich butter chicken dish.",
8
- },
9
- {
10
- "name": "Chicken Biryani",
11
- "description": "Aromatic rice cooked with chicken and spices.",
12
- },
13
- {
14
- "name": "Dosa",
15
- "description": "A crispy South Indian crepe served with chutney.",
16
- },
17
- {
18
- "name": "Aloo Curry",
19
- "description": "Potatoes cooked in a spicy curry sauce.",
20
- },
21
- ]
22
-
23
- # Function to handle the popup
24
- def show_popup(item_name, item_description):
25
- return f"### {item_name}\n\n{item_description}"
26
-
27
- # Create the Gradio interface
28
- def render_menu():
29
- with gr.Blocks(css="""
30
- .menu-item {
31
- border: 2px solid black;
32
- border-radius: 5px;
33
- padding: 15px;
34
- margin: 10px 0;
35
- font-size: 18px;
36
- font-weight: bold;
37
- text-align: center;
38
- background-color: #fff;
39
- cursor: pointer;
40
- }
41
- .menu-item:hover {
42
- background-color: #f0f0f0;
43
- }
44
- .menu-container {
45
- margin-top: 20px;
46
- }
47
- """) as demo:
48
- gr.Markdown("# Menu")
49
-
50
- # Popup display area
51
- popup_output = gr.Markdown("### Select an item to view details.")
52
-
53
- # Display the menu items
54
- with gr.Column(elem_id="menu-container"):
55
- for item in menu_items:
56
- with gr.Row(elem_classes=["menu-item"]):
57
- # Display item name with a clickable action
58
- button = gr.Button(item["name"], elem_id=f"{item['name']}-button")
59
- button.click(
60
- fn=show_popup,
61
- inputs=[],
62
- outputs=popup_output,
63
- _js=f"() => ['{item['name']}', '{item['description']}']"
64
- )
65
-
66
- # Popup section to show details
67
- gr.Markdown("## Selected Item Details")
68
- gr.Box(popup_output)
69
-
70
- return demo
71
-
72
- # Render the app
73
- demo = render_menu()
74
- demo.launch()
 
1
  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:
17
+ gr.Markdown("# 🍽️ Indian & Chinese Food Nutritional Information 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()