File size: 1,511 Bytes
873849b
d4dab20
 
 
67c9708
d4dab20
67c9708
 
 
 
d4dab20
 
 
 
 
 
 
3d58636
d4dab20
 
 
e8c00b9
 
0a4873f
3d58636
 
ff2929a
3d58636
 
 
 
 
e8c00b9
 
 
3d58636
 
e8c00b9
 
 
 
 
 
 
d4dab20
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from components.cards import create_food_card
from components.data import FOOD_DATA

# Function to render the popup card when a button is clicked
def display_card(food_name):
    if food_name in FOOD_DATA:
        return create_food_card(food_name)
    else:
        return "<p>No data available for the selected item.</p>"

# Gradio app interface
with gr.Blocks(css="styles.css") as app:
    gr.Markdown("# 🍽️ Indian & Chinese Food Nutritional Information App")
    gr.Markdown(
        """
        ### Explore Popular Dishes πŸ›
        Click on any dish below to view its image, nutritional facts, and portion size.
        """
    )

    # Define the popup area as an HTML component
    popup_area = gr.HTML(visible=False, elem_id="popup")

    # Display all items as a vertical list
    with gr.Column(elem_id="food-list"):
        for food_name in FOOD_DATA.keys():
            gr.Button(
                value=food_name,
                elem_id=f"food-{food_name.replace(' ', '-').lower()}",
                interactive=True,
            ).click(
                display_card,  # Update the popup content
                inputs=[gr.Textbox(value=food_name, visible=False)],
                outputs=popup_area  # Set the HTML content of the popup
            )

    # Close popup button
    gr.Button("Close Popup", elem_id="close-popup").click(
        lambda: "",  # Clear the popup content
        inputs=None,
        outputs=popup_area,
    )

# Launch the app
app.launch()