File size: 4,111 Bytes
7bf0ff9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np

# Data: Nutritional Information for the healthiest dishes
nutritional_data = {
    "Idli with Vegetable Sambar": {
        "Energy (kcal)": 100, "Protein (g)": 5.5, "Fat (g)": 1.5, "Carbohydrate (g)": 17.0, "Fiber (g)": 3.0, "Calcium (mg)": 35, "Iron (mg)": 1.0, "Vitamin C (mg)": 8.0
    },
    "Khichdi": {
        "Energy (kcal)": 120, "Protein (g)": 4.0, "Fat (g)": 2.5, "Carbohydrate (g)": 20.0, "Fiber (g)": 2.5, "Calcium (mg)": 40, "Iron (mg)": 1.0, "Vitamin C (mg)": 5.0
    },
    "Tandoori Chicken": {
        "Energy (kcal)": 150, "Protein (g)": 18.0, "Fat (g)": 7.0, "Carbohydrate (g)": 3.0, "Fiber (g)": 0.5, "Calcium (mg)": 15, "Iron (mg)": 1.2, "Vitamin C (mg)": 1.5
    },
    "Palak Paneer": {
        "Energy (kcal)": 140, "Protein (g)": 7.5, "Fat (g)": 10.0, "Carbohydrate (g)": 6.0, "Fiber (g)": 3.0, "Calcium (mg)": 200, "Iron (mg)": 3.0, "Vitamin C (mg)": 15.0
    },
    "Raita": {
        "Energy (kcal)": 60, "Protein (g)": 3.5, "Fat (g)": 2.0, "Carbohydrate (g)": 6.5, "Fiber (g)": 0.5, "Calcium (mg)": 100, "Iron (mg)": 0.5, "Vitamin C (mg)": 2.0
    },
    "Rajma": {
        "Energy (kcal)": 140, "Protein (g)": 7.5, "Fat (g)": 5.0, "Carbohydrate (g)": 20.0, "Fiber (g)": 6.0, "Calcium (mg)": 50, "Iron (mg)": 3.5, "Vitamin C (mg)": 4.0
    },
    "Baingan Bharta": {
        "Energy (kcal)": 70, "Protein (g)": 2.5, "Fat (g)": 3.0, "Carbohydrate (g)": 10.0, "Fiber (g)": 4.0, "Calcium (mg)": 30, "Iron (mg)": 0.7, "Vitamin C (mg)": 6.0
    },
    "Besan Chilla": {
        "Energy (kcal)": 180, "Protein (g)": 8.0, "Fat (g)": 7.0, "Carbohydrate (g)": 20.0, "Fiber (g)": 5.0, "Calcium (mg)": 30, "Iron (mg)": 2.5, "Vitamin C (mg)": 1.0
    },
    "Masoor Dal": {
        "Energy (kcal)": 110, "Protein (g)": 7.5, "Fat (g)": 2.0, "Carbohydrate (g)": 16.0, "Fiber (g)": 5.5, "Calcium (mg)": 25, "Iron (mg)": 3.0, "Vitamin C (mg)": 4.0
    },
    "Upma": {
        "Energy (kcal)": 150, "Protein (g)": 4.0, "Fat (g)": 6.0, "Carbohydrate (g)": 25.0, "Fiber (g)": 3.0, "Calcium (mg)": 30, "Iron (mg)": 1.0, "Vitamin C (mg)": 3.0
    }
}

def plot_nutritional_comparison(dish):
    """Plots a radar chart comparing the nutritional values of the selected dish."""
    labels = list(nutritional_data[dish].keys())
    values = list(nutritional_data[dish].values())
    
    # Normalize values for better comparison on the radar chart
    max_values = [max(nutritional_data[d][label] for d in nutritional_data) for label in labels]
    normalized_values = [value / max_val if max_val > 0 else 0 for value, max_val in zip(values, max_values)]
    
    # Setup the radar chart
    angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
    values += values[:1]  # repeat the first value to close the circle
    normalized_values += normalized_values[:1]
    angles += angles[:1]
    
    fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
    ax.fill(angles, normalized_values, color='blue', alpha=0.25)
    ax.plot(angles, normalized_values, color='blue', linewidth=2)
    ax.set_yticklabels([])
    ax.set_xticks(angles[:-1])
    ax.set_xticklabels(labels)
    ax.set_title(f'Nutritional Profile for {dish}', size=15, color='blue', y=1.1)
    
    return fig

# Gradio Interface
def create_interface():
    dishes = list(nutritional_data.keys())
    
    with gr.Blocks() as demo:
        gr.Markdown("# Nutritional Comparison of Healthiest Dishes")
        dish_selector = gr.Dropdown(choices=dishes, label="Select a Dish", value=dishes[0])
        nutritional_comparison_output = gr.Plot(label="Nutritional Comparison")
        
        # Update the plot based on the selected dish
        def update_nutritional_comparison(dish):
            return plot_nutritional_comparison(dish)
        
        dish_selector.change(fn=update_nutritional_comparison, inputs=dish_selector, outputs=nutritional_comparison_output)
        
        gr.Row(dish_selector, nutritional_comparison_output)
    
    return demo

# Launch the interface
demo = create_interface()
demo.launch(share=True)