File size: 7,707 Bytes
a566697
 
 
 
 
 
c2ea612
a566697
 
 
c2ea612
a566697
c2ea612
a566697
 
c2ea612
a566697
 
 
 
 
c2ea612
 
a566697
 
 
 
c2ea612
 
 
 
a566697
 
c2ea612
a566697
c2ea612
a566697
 
 
 
 
c2ea612
 
a566697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea612
 
 
 
 
 
 
 
a566697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea612
a566697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea612
a566697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea612
 
a566697
 
c2ea612
a566697
 
 
 
 
c2ea612
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import pandas as pd
import tensorflow as tf
import gradio as gr
from sklearn.preprocessing import StandardScaler
import json

# Indian food database with detailed nutrition information
FOOD_DATABASE = {
    'foods': {
        'high_protein': {
            'Paneer': {'protein': 18, 'carbs': 5, 'fats': 20, 'calories': 265, 'benefits': ['calcium', 'high protein']},
            'Chicken Breast': {'protein': 31, 'carbs': 0, 'fats': 3.6, 'calories': 165, 'benefits': ['lean protein', 'B vitamins']},
            'Tofu': {'protein': 8, 'carbs': 1, 'fats': 5, 'calories': 70, 'benefits': ['protein', 'iron']}
        },
        'low_glycemic': {
            'Brown Rice': {'protein': 3, 'carbs': 45, 'fats': 1, 'calories': 216, 'benefits': ['fiber', 'minerals']},
            'Sweet Potato': {'protein': 2, 'carbs': 27, 'fats': 0, 'calories': 103, 'benefits': ['vitamin A', 'fiber']},
            'Greek Yogurt': {'protein': 10, 'carbs': 4, 'fats': 0, 'calories': 59, 'benefits': ['probiotics', 'calcium']}
        },
        'anti_inflammatory': {
            'Spinach': {'protein': 3, 'carbs': 3, 'fats': 0, 'calories': 23, 'benefits': ['antioxidants', 'iron']},
            'Turmeric': {'protein': 0, 'carbs': 1, 'fats': 0, 'calories': 9, 'benefits': ['curcumin', 'anti-inflammatory']},
            'Mangoes': {'protein': 0.8, 'carbs': 15, 'fats': 0.6, 'calories': 60, 'benefits': ['vitamin C', 'fiber']}
        }
    },
    'meal_plans': {
        'diabetes_friendly': {
            'breakfast': ['Greek Yogurt with Mangoes', 'Quinoa Porridge', 'Vegetable Upma'],
            'lunch': ['Grilled Chicken Salad', 'Lentil Soup', 'Palak Paneer'],
            'dinner': ['Grilled Salmon', 'Vegetable Stir-fry', 'Masoor Dal'],
            'snacks': ['Almonds', 'Hummus with Vegetables', 'Cucumber Salad']
        },
        'heart_healthy': {
            'breakfast': ['Oatmeal with Mangoes', 'Whole Grain Toast with Avocado', 'Smoothie Bowl'],
            'lunch': ['Mediterranean Salad', 'Grilled Fish Tacos', 'Vegetable Soup'],
            'dinner': ['Grilled Salmon', 'Lean Chicken Breast', 'Vegetable Biryani'],
            'snacks': ['Walnuts', 'Fresh Fruit', 'Greek Yogurt']
        }
    }
}

# Modify the genetic profile analysis function as per Indian dietary trends
def generate_personalized_recommendations(genetic_data, health_metrics, diet_type):
    """Generate personalized diet recommendations based on genetic and health data"""
    
    recommendations = {
        'risk_profile': [],
        'dietary_guidelines': [],
        'meal_plan': {},
        'foods_to_focus': [],
        'foods_to_avoid': []
    }
    
    # Analyze genetic risks
    if genetic_data['fto'] == 1:  # Risk variant
        recommendations['risk_profile'].append('FTO gene risk variant detected')
        recommendations['dietary_guidelines'].extend(GENETIC_PROFILES['FTO']['Risk Variant']['dietary_recommendations'])
    
    if genetic_data['pparg'] == 1:  # Risk variant
        recommendations['risk_profile'].append('PPARG gene risk variant detected')
        recommendations['dietary_guidelines'].extend(GENETIC_PROFILES['PPARG']['Risk Variant']['dietary_recommendations'])
    
    # Analyze health metrics
    if health_metrics['blood_glucose'] > 100:
        recommendations['dietary_guidelines'].append('Focus on low glycemic index foods')
        recommendations['meal_plan'] = FOOD_DATABASE['meal_plans']['diabetes_friendly']
        recommendations['foods_to_avoid'].extend(['White bread', 'Sugary drinks', 'Processed snacks'])
    
    if health_metrics['systolic_bp'] > 130 or health_metrics['diastolic_bp'] > 80:
        recommendations['dietary_guidelines'].append('Reduce sodium intake')
        recommendations['meal_plan'] = FOOD_DATABASE['meal_plans']['heart_healthy']
        recommendations['foods_to_focus'].extend(['Leafy greens', 'Berries', 'Whole grains'])
    
    # Adjust meal plan based on dietary preference (veg, non-veg, vegan)
    if diet_type == "Vegetarian":
        recommendations['meal_plan'] = {meal: [food for food in options if food != 'Chicken Breast' and food != 'Grilled Salmon']
                                        for meal, options in recommendations['meal_plan'].items()}
    elif diet_type == "Vegan":
        recommendations['meal_plan'] = {meal: [food for food in options if 'Paneer' not in food and 'Chicken Breast' not in food and 'Grilled Salmon' not in food]
                                        for meal, options in recommendations['meal_plan'].items()}
    
    return recommendations

def format_recommendations(recommendations):
    """Format recommendations into a readable output"""
    output = "🧬 PERSONALIZED NUTRIGENOMIC DIET RECOMMENDATIONS 🧬\n\n"
    
    # Risk Profile
    output += "πŸ“Š GENETIC RISK PROFILE:\n"
    for risk in recommendations['risk_profile']:
        output += f"β€’ {risk}\n"
    output += "\n"
    
    # Dietary Guidelines
    output += "πŸ₯— DIETARY GUIDELINES:\n"
    for guideline in set(recommendations['dietary_guidelines']):  # Remove duplicates
        output += f"β€’ {guideline}\n"
    output += "\n"
    
    # Meal Plan
    if recommendations['meal_plan']:
        output += "🍽️ RECOMMENDED MEAL PLAN:\n"
        for meal, options in recommendations['meal_plan'].items():
            output += f"\n{meal.upper()}:\n"
            for option in options:
                output += f"β€’ {option}\n"
    
    return output

def predict_diet(fto_variant, adrb3_variant, pparg_variant, apob_variant,
                blood_glucose, blood_pressure, bmi, age, activity_level, diet_type):
    
    # Process genetic data
    genetic_data = {
        'fto': float(fto_variant == "Risk Variant"),
        'adrb3': float(adrb3_variant == "Risk Variant"),
        'pparg': float(pparg_variant == "Risk Variant"),
        'apob': float(apob_variant == "Risk Variant")
    }
    
    # Process health metrics
    try:
        systolic, diastolic = map(float, blood_pressure.split('/'))
    except:
        return "Please enter blood pressure in the format systolic/diastolic (e.g., 120/80)"
    
    health_metrics = {
        'blood_glucose': float(blood_glucose),
        'systolic_bp': systolic,
        'diastolic_bp': diastolic,
        'bmi': float(bmi),
        'age': float(age),
        'activity': float(activity_level == "Active")
    }
    
    # Generate recommendations
    recommendations = generate_personalized_recommendations(genetic_data, health_metrics, diet_type)
    
    # Format and return recommendations
    return format_recommendations(recommendations)

# Create Gradio interface
iface = gr.Interface(
    fn=predict_diet,
    inputs=[
        gr.Radio(["Normal", "Risk Variant"], label="FTO Gene Variant (Obesity Risk)"),
        gr.Radio(["Normal", "Risk Variant"], label="ADRB3 Gene Variant (Metabolism)"),
        gr.Radio(["Normal", "Risk Variant"], label="PPARG Gene Variant (Insulin Sensitivity)"),
        gr.Radio(["Normal", "Risk Variant"], label="APOB Gene Variant (Lipid Metabolism)"),
        gr.Number(label="Fasting Blood Glucose (mg/dL)", value=90),
        gr.Textbox(label="Blood Pressure (systolic/diastolic)", placeholder="120/80", value="120/80"),
        gr.Number(label="BMI", value=25),
        gr.Number(label="Age", value=30),
        gr.Radio(["Sedentary", "Active"], label="Activity Level"),
        gr.Radio(["Vegetarian", "Non-Vegetarian", "Vegan"], label="Diet Preference")
    ],
    outputs="text",
    title="Indian Diet-Based Nutrigenomics Recommendation System",
    description="Get personalized dietary recommendations based on your genetic profile and health metrics.",
    theme="huggingface"
)

# Launch the interface
iface.launch(share=True)