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)