File size: 1,882 Bytes
acc8bc0
1630406
99a998d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
acc8bc0
99a998d
acc8bc0
99a998d
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr

# Food item data
food_data = [
    {
        "name": "Apple",
        "image": "apple.jpg",
        "nutrition": {
            "Calories": "52 kcal",
            "Proteins": "0.3 g",
            "Carbohydrates": "14 g"
        }
    },
    {
        "name": "Banana",
        "image": "banana.jpg",
        "nutrition": {
            "Calories": "96 kcal",
            "Proteins": "1.3 g",
            "Carbohydrates": "27 g"
        }
    },
    {
        "name": "Chicken Breast",
        "image": "chicken_breast.jpg",
        "nutrition": {
            "Calories": "165 kcal",
            "Proteins": "31 g",
            "Carbohydrates": "0 g"
        }
    },
    {
        "name": "Rice",
        "image": "rice.jpg",
        "nutrition": {
            "Calories": "130 kcal",
            "Proteins": "2.7 g",
            "Carbohydrates": "28 g"
        }
    }
]

# Function to show food details
def food_details(food_name):
    # Find the food item by name
    food_item = next((food for food in food_data if food["name"] == food_name), None)
    if food_item:
        # Format nutrition details
        nutrition_details = "\n".join(f"{key}: {value}" for key, value in food_item["nutrition"].items())
        return f"### {food_item['name']}\n\n**Nutrition Details:**\n\n{nutrition_details}"
    return "Food item not found."

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# Food Nutrition App")
    
    # Food items gallery
    with gr.Row():
        for food in food_data:
            with gr.Column():
                gr.Markdown(f"### {food['name']}")
                food_button = gr.Button(image=food["image"])
                food_button.click(
                    food_details,
                    inputs=gr.Textbox(value=food["name"], visible=False),
                    outputs=gr.Markdown()
                )

demo.launch()