Update app.py
Browse files
app.py
CHANGED
|
@@ -1,83 +1,46 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
import pandas as pd
|
| 3 |
import tensorflow as tf
|
| 4 |
import gradio as gr
|
| 5 |
from sklearn.preprocessing import StandardScaler
|
| 6 |
import json
|
| 7 |
|
| 8 |
-
#
|
| 9 |
FOOD_DATABASE = {
|
| 10 |
'foods': {
|
| 11 |
'high_protein': {
|
| 12 |
-
'
|
| 13 |
'Chicken Breast': {'protein': 31, 'carbs': 0, 'fats': 3.6, 'calories': 165, 'benefits': ['lean protein', 'B vitamins']},
|
| 14 |
-
'
|
| 15 |
},
|
| 16 |
'low_glycemic': {
|
| 17 |
-
'
|
| 18 |
'Sweet Potato': {'protein': 2, 'carbs': 27, 'fats': 0, 'calories': 103, 'benefits': ['vitamin A', 'fiber']},
|
| 19 |
'Greek Yogurt': {'protein': 10, 'carbs': 4, 'fats': 0, 'calories': 59, 'benefits': ['probiotics', 'calcium']}
|
| 20 |
},
|
| 21 |
'anti_inflammatory': {
|
| 22 |
'Spinach': {'protein': 3, 'carbs': 3, 'fats': 0, 'calories': 23, 'benefits': ['antioxidants', 'iron']},
|
| 23 |
-
'
|
| 24 |
-
'
|
| 25 |
}
|
| 26 |
},
|
| 27 |
'meal_plans': {
|
| 28 |
'diabetes_friendly': {
|
| 29 |
-
'breakfast': ['Greek Yogurt with
|
| 30 |
-
'lunch': ['Grilled Chicken Salad', 'Lentil Soup', '
|
| 31 |
-
'dinner': ['
|
| 32 |
-
'snacks': ['Almonds', 'Hummus with Vegetables', '
|
| 33 |
},
|
| 34 |
'heart_healthy': {
|
| 35 |
-
'breakfast': ['Oatmeal with
|
| 36 |
'lunch': ['Mediterranean Salad', 'Grilled Fish Tacos', 'Vegetable Soup'],
|
| 37 |
-
'dinner': ['Grilled Salmon', 'Lean Chicken Breast', '
|
| 38 |
'snacks': ['Walnuts', 'Fresh Fruit', 'Greek Yogurt']
|
| 39 |
}
|
| 40 |
}
|
| 41 |
}
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
'FTO': {
|
| 46 |
-
'Risk Variant': {
|
| 47 |
-
'implications': 'Increased risk of obesity and diabetes',
|
| 48 |
-
'dietary_recommendations': [
|
| 49 |
-
'Focus on high-protein meals to increase satiety',
|
| 50 |
-
'Choose low glycemic index foods',
|
| 51 |
-
'Increase fiber intake',
|
| 52 |
-
'Regular meal timing'
|
| 53 |
-
]
|
| 54 |
-
}
|
| 55 |
-
},
|
| 56 |
-
'ADRB3': {
|
| 57 |
-
'Risk Variant': {
|
| 58 |
-
'implications': 'Reduced metabolic rate',
|
| 59 |
-
'dietary_recommendations': [
|
| 60 |
-
'Include thermogenic foods',
|
| 61 |
-
'Higher protein intake',
|
| 62 |
-
'Controlled portion sizes',
|
| 63 |
-
'Green tea consumption'
|
| 64 |
-
]
|
| 65 |
-
}
|
| 66 |
-
},
|
| 67 |
-
'PPARG': {
|
| 68 |
-
'Risk Variant': {
|
| 69 |
-
'implications': 'Reduced insulin sensitivity',
|
| 70 |
-
'dietary_recommendations': [
|
| 71 |
-
'Choose low glycemic index foods',
|
| 72 |
-
'Include omega-3 rich foods',
|
| 73 |
-
'Increase fiber intake',
|
| 74 |
-
'Include anti-inflammatory foods'
|
| 75 |
-
]
|
| 76 |
-
}
|
| 77 |
-
}
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
def generate_personalized_recommendations(genetic_data, health_metrics):
|
| 81 |
"""Generate personalized diet recommendations based on genetic and health data"""
|
| 82 |
|
| 83 |
recommendations = {
|
|
@@ -108,6 +71,14 @@ def generate_personalized_recommendations(genetic_data, health_metrics):
|
|
| 108 |
recommendations['meal_plan'] = FOOD_DATABASE['meal_plans']['heart_healthy']
|
| 109 |
recommendations['foods_to_focus'].extend(['Leafy greens', 'Berries', 'Whole grains'])
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
return recommendations
|
| 112 |
|
| 113 |
def format_recommendations(recommendations):
|
|
@@ -134,22 +105,10 @@ def format_recommendations(recommendations):
|
|
| 134 |
for option in options:
|
| 135 |
output += f"• {option}\n"
|
| 136 |
|
| 137 |
-
# Foods to Focus On
|
| 138 |
-
if recommendations['foods_to_focus']:
|
| 139 |
-
output += "\n✅ FOODS TO FOCUS ON:\n"
|
| 140 |
-
for food in recommendations['foods_to_focus']:
|
| 141 |
-
output += f"• {food}\n"
|
| 142 |
-
|
| 143 |
-
# Foods to Avoid
|
| 144 |
-
if recommendations['foods_to_avoid']:
|
| 145 |
-
output += "\n❌ FOODS TO AVOID:\n"
|
| 146 |
-
for food in recommendations['foods_to_avoid']:
|
| 147 |
-
output += f"• {food}\n"
|
| 148 |
-
|
| 149 |
return output
|
| 150 |
|
| 151 |
def predict_diet(fto_variant, adrb3_variant, pparg_variant, apob_variant,
|
| 152 |
-
blood_glucose, blood_pressure, bmi, age, activity_level):
|
| 153 |
|
| 154 |
# Process genetic data
|
| 155 |
genetic_data = {
|
|
@@ -175,7 +134,7 @@ def predict_diet(fto_variant, adrb3_variant, pparg_variant, apob_variant,
|
|
| 175 |
}
|
| 176 |
|
| 177 |
# Generate recommendations
|
| 178 |
-
recommendations = generate_personalized_recommendations(genetic_data, health_metrics)
|
| 179 |
|
| 180 |
# Format and return recommendations
|
| 181 |
return format_recommendations(recommendations)
|
|
@@ -192,13 +151,14 @@ iface = gr.Interface(
|
|
| 192 |
gr.Textbox(label="Blood Pressure (systolic/diastolic)", placeholder="120/80", value="120/80"),
|
| 193 |
gr.Number(label="BMI", value=25),
|
| 194 |
gr.Number(label="Age", value=30),
|
| 195 |
-
gr.Radio(["Sedentary", "Active"], label="Activity Level")
|
|
|
|
| 196 |
],
|
| 197 |
outputs="text",
|
| 198 |
-
title="
|
| 199 |
description="Get personalized dietary recommendations based on your genetic profile and health metrics.",
|
| 200 |
theme="huggingface"
|
| 201 |
)
|
| 202 |
|
| 203 |
# Launch the interface
|
| 204 |
-
iface.launch(share=True)
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import tensorflow as tf
|
| 3 |
import gradio as gr
|
| 4 |
from sklearn.preprocessing import StandardScaler
|
| 5 |
import json
|
| 6 |
|
| 7 |
+
# Indian food database with detailed nutrition information
|
| 8 |
FOOD_DATABASE = {
|
| 9 |
'foods': {
|
| 10 |
'high_protein': {
|
| 11 |
+
'Paneer': {'protein': 18, 'carbs': 5, 'fats': 20, 'calories': 265, 'benefits': ['calcium', 'high protein']},
|
| 12 |
'Chicken Breast': {'protein': 31, 'carbs': 0, 'fats': 3.6, 'calories': 165, 'benefits': ['lean protein', 'B vitamins']},
|
| 13 |
+
'Tofu': {'protein': 8, 'carbs': 1, 'fats': 5, 'calories': 70, 'benefits': ['protein', 'iron']}
|
| 14 |
},
|
| 15 |
'low_glycemic': {
|
| 16 |
+
'Brown Rice': {'protein': 3, 'carbs': 45, 'fats': 1, 'calories': 216, 'benefits': ['fiber', 'minerals']},
|
| 17 |
'Sweet Potato': {'protein': 2, 'carbs': 27, 'fats': 0, 'calories': 103, 'benefits': ['vitamin A', 'fiber']},
|
| 18 |
'Greek Yogurt': {'protein': 10, 'carbs': 4, 'fats': 0, 'calories': 59, 'benefits': ['probiotics', 'calcium']}
|
| 19 |
},
|
| 20 |
'anti_inflammatory': {
|
| 21 |
'Spinach': {'protein': 3, 'carbs': 3, 'fats': 0, 'calories': 23, 'benefits': ['antioxidants', 'iron']},
|
| 22 |
+
'Turmeric': {'protein': 0, 'carbs': 1, 'fats': 0, 'calories': 9, 'benefits': ['curcumin', 'anti-inflammatory']},
|
| 23 |
+
'Mangoes': {'protein': 0.8, 'carbs': 15, 'fats': 0.6, 'calories': 60, 'benefits': ['vitamin C', 'fiber']}
|
| 24 |
}
|
| 25 |
},
|
| 26 |
'meal_plans': {
|
| 27 |
'diabetes_friendly': {
|
| 28 |
+
'breakfast': ['Greek Yogurt with Mangoes', 'Quinoa Porridge', 'Vegetable Upma'],
|
| 29 |
+
'lunch': ['Grilled Chicken Salad', 'Lentil Soup', 'Palak Paneer'],
|
| 30 |
+
'dinner': ['Grilled Salmon', 'Vegetable Stir-fry', 'Masoor Dal'],
|
| 31 |
+
'snacks': ['Almonds', 'Hummus with Vegetables', 'Cucumber Salad']
|
| 32 |
},
|
| 33 |
'heart_healthy': {
|
| 34 |
+
'breakfast': ['Oatmeal with Mangoes', 'Whole Grain Toast with Avocado', 'Smoothie Bowl'],
|
| 35 |
'lunch': ['Mediterranean Salad', 'Grilled Fish Tacos', 'Vegetable Soup'],
|
| 36 |
+
'dinner': ['Grilled Salmon', 'Lean Chicken Breast', 'Vegetable Biryani'],
|
| 37 |
'snacks': ['Walnuts', 'Fresh Fruit', 'Greek Yogurt']
|
| 38 |
}
|
| 39 |
}
|
| 40 |
}
|
| 41 |
|
| 42 |
+
# Modify the genetic profile analysis function as per Indian dietary trends
|
| 43 |
+
def generate_personalized_recommendations(genetic_data, health_metrics, diet_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
"""Generate personalized diet recommendations based on genetic and health data"""
|
| 45 |
|
| 46 |
recommendations = {
|
|
|
|
| 71 |
recommendations['meal_plan'] = FOOD_DATABASE['meal_plans']['heart_healthy']
|
| 72 |
recommendations['foods_to_focus'].extend(['Leafy greens', 'Berries', 'Whole grains'])
|
| 73 |
|
| 74 |
+
# Adjust meal plan based on dietary preference (veg, non-veg, vegan)
|
| 75 |
+
if diet_type == "Vegetarian":
|
| 76 |
+
recommendations['meal_plan'] = {meal: [food for food in options if food != 'Chicken Breast' and food != 'Grilled Salmon']
|
| 77 |
+
for meal, options in recommendations['meal_plan'].items()}
|
| 78 |
+
elif diet_type == "Vegan":
|
| 79 |
+
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]
|
| 80 |
+
for meal, options in recommendations['meal_plan'].items()}
|
| 81 |
+
|
| 82 |
return recommendations
|
| 83 |
|
| 84 |
def format_recommendations(recommendations):
|
|
|
|
| 105 |
for option in options:
|
| 106 |
output += f"• {option}\n"
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
return output
|
| 109 |
|
| 110 |
def predict_diet(fto_variant, adrb3_variant, pparg_variant, apob_variant,
|
| 111 |
+
blood_glucose, blood_pressure, bmi, age, activity_level, diet_type):
|
| 112 |
|
| 113 |
# Process genetic data
|
| 114 |
genetic_data = {
|
|
|
|
| 134 |
}
|
| 135 |
|
| 136 |
# Generate recommendations
|
| 137 |
+
recommendations = generate_personalized_recommendations(genetic_data, health_metrics, diet_type)
|
| 138 |
|
| 139 |
# Format and return recommendations
|
| 140 |
return format_recommendations(recommendations)
|
|
|
|
| 151 |
gr.Textbox(label="Blood Pressure (systolic/diastolic)", placeholder="120/80", value="120/80"),
|
| 152 |
gr.Number(label="BMI", value=25),
|
| 153 |
gr.Number(label="Age", value=30),
|
| 154 |
+
gr.Radio(["Sedentary", "Active"], label="Activity Level"),
|
| 155 |
+
gr.Radio(["Vegetarian", "Non-Vegetarian", "Vegan"], label="Diet Preference")
|
| 156 |
],
|
| 157 |
outputs="text",
|
| 158 |
+
title="Indian Diet-Based Nutrigenomics Recommendation System",
|
| 159 |
description="Get personalized dietary recommendations based on your genetic profile and health metrics.",
|
| 160 |
theme="huggingface"
|
| 161 |
)
|
| 162 |
|
| 163 |
# Launch the interface
|
| 164 |
+
iface.launch(share=True)
|