mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 15:08:46 +01:00
Introduces DSPy-based nutrition and plan generation modules, including image analysis for nutritional info and personalized diet/exercise plans. Adds new API endpoints for health metrics/goals, nutrition image analysis, and plan management. Updates models, schemas, and backend structure to support these features, and includes initial training data and configuration for prompt optimization.
514 lines
18 KiB
Python
514 lines
18 KiB
Python
import dspy
|
|
|
|
from app.ai.nutrition import NutritionalInfo
|
|
|
|
# A diverse set of 50 validated examples covering:
|
|
# - Home cooked meals
|
|
# - Restaurant items
|
|
# - Snacks
|
|
# - Complex dishes with hidden calories
|
|
|
|
train_examples = [
|
|
# --- Breakfast ---
|
|
dspy.Example(
|
|
description="Oatmeal with almonds, blueberries, and honey",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 cup cooked oats (150 cal). 1 oz almonds (160 cal). "
|
|
"1/2 cup blueberries (40 cal). 1 tbsp honey (60 cal). Total ~410 cal.",
|
|
name="Oatmeal Bowl",
|
|
calories=410,
|
|
protein=10,
|
|
carbs=65,
|
|
fats=16,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Two eggs over easy with two slices of bacon and buttered toast",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="2 eggs (140 cal) cooked in fat (+20 cal). 2 slices bacon (90 cal). "
|
|
"1 slice huge toast (100 cal) + 1 tsp butter (35 cal). Total ~385 cal.",
|
|
name="Eggs & Bacon Breakfast",
|
|
calories=385,
|
|
protein=20,
|
|
carbs=15,
|
|
fats=26,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Greek yogurt parfait with granola and strawberries",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 cup non-fat greek yogurt (130 cal). 1/2 cup granola (200 cal). "
|
|
"1 cup sliced strawberries (50 cal). Total ~380 cal.",
|
|
name="Yogurt Parfait",
|
|
calories=380,
|
|
protein=24,
|
|
carbs=55,
|
|
fats=8,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Avocado toast with a poached egg",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 slice artisan bread (110 cal). 1/2 avocado (120 cal). "
|
|
"1 poached egg (70 cal). Drizzle of oil/seasoning (20 cal). Total ~320 cal.",
|
|
name="Avocado Toast",
|
|
calories=320,
|
|
protein=10,
|
|
carbs=20,
|
|
fats=22,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Spinach and feta omelette containing 3 eggs",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="3 eggs (210 cal). 1 tsp oil/butter (40 cal). "
|
|
"1 cup spinach (10 cal). 1 oz feta (75 cal). Total ~335 cal.",
|
|
name="Spinach Feta Omelette",
|
|
calories=335,
|
|
protein=22,
|
|
carbs=4,
|
|
fats=25,
|
|
),
|
|
).with_inputs("description"),
|
|
# --- Lunch ---
|
|
dspy.Example(
|
|
description="Grilled chicken breast sandwich with mayo, lettuce, tomato",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Bun (180 cal). Chicken breast 4oz (160 cal). "
|
|
"1 tbsp mayo (90 cal). Veggies (10 cal). Total ~440 cal.",
|
|
name="Grilled Chicken Sandwich",
|
|
calories=440,
|
|
protein=30,
|
|
carbs=35,
|
|
fats=18,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Caesar salad with grilled chicken",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Romaine lettuce (20 cal). 4oz chicken (160 cal). 2 tbsp dressing (170 cal). "
|
|
"Croutons (100 cal). Parmesan (60 cal). Total ~510 cal.",
|
|
name="Chicken Caesar Salad",
|
|
calories=510,
|
|
protein=35,
|
|
carbs=15,
|
|
fats=35,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Turkey club sandwich with bacon and cheese",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="3 slices bread (240 cal). Turkey (60 cal). Bacon (90 cal). "
|
|
"Cheese (110 cal). Mayo (90 cal). Lettuce / Tomato. Total ~590 cal.",
|
|
name="Turkey Club",
|
|
calories=590,
|
|
protein=30,
|
|
carbs=45,
|
|
fats=32,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Quinoa bowl with black beans, corn, and avocado",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 cup cooked quinoa (220 cal). 1/2 cup black beans (110 cal). "
|
|
"1/2 cup corn (70 cal). 1/4 avocado (60 cal). Lime dressing (50 cal). Total ~510 cal.",
|
|
name="Veggie Quinoa Bowl",
|
|
calories=510,
|
|
protein=18,
|
|
carbs=85,
|
|
fats=12,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Tuna salad sushi roll (6 pieces) and miso soup",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Sushi roll (rice, tuna, mayo) ~300 cal. Miso soup ~40 cal. Total ~340 cal.",
|
|
name="Sushi Lunch",
|
|
calories=340,
|
|
protein=15,
|
|
carbs=45,
|
|
fats=8,
|
|
),
|
|
).with_inputs("description"),
|
|
# --- Dinner (Complex) ---
|
|
dspy.Example(
|
|
description="Spaghetti bolognaise with parmesan cheese",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="2 cups pasta cooked (400 cal). 1 cup meat sauce/beef (300 cal). "
|
|
"1 tbsp oil in cooking (120 cal). 2 tbsp parmesan (40 cal). Total ~860 cal.",
|
|
name="Spaghetti Bolognese",
|
|
calories=860,
|
|
protein=35,
|
|
carbs=100,
|
|
fats=35,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Grilled salmon with asparagus and roasted potatoes",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="6oz Salmon fillet (350 cal). Oil for cooking (60 cal). "
|
|
"Asparagus (30 cal) + oil (30 cal). 1 cup roasted potatoes (150 cal) + oil (60 cal). Total ~680 cal.",
|
|
name="Salmon Dinner",
|
|
calories=680,
|
|
protein=40,
|
|
carbs=25,
|
|
fats=45,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Beef stir fry with rice",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 cup rice (200 cal). 4oz Beef strips (250 cal). "
|
|
"Oil for frying 2 tbsp (240 cal). Veggies (50 cal). Sauce (50 cal). Total ~790 cal.",
|
|
name="Beef Stir Fry",
|
|
calories=790,
|
|
protein=30,
|
|
carbs=50,
|
|
fats=50,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Cheeseburger with fries",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Bun (200 cal). 4oz Patty 80/20 (280 cal). Cheese (100 cal). "
|
|
"Condiments (50 cal). Small fries (300 cal). Total ~930 cal.",
|
|
name="Burger and Fries",
|
|
calories=930,
|
|
protein=35,
|
|
carbs=90,
|
|
fats=45,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Chicken Tikka Masala with Naan and Rice",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Curry with cream/butter/chicken (600 cal). "
|
|
"1 cup Rice (200 cal). 1 piece Naan (250 cal). Total ~1050 cal.",
|
|
name="Chicken Tikka Meal",
|
|
calories=1050,
|
|
protein=45,
|
|
carbs=120,
|
|
fats=45,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="2 slices of pepperoni pizza",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="2 slices (300 cal each). Total ~600 cal. High fat/carbs.",
|
|
name="2 Pizza Slices",
|
|
calories=600,
|
|
protein=24,
|
|
carbs=70,
|
|
fats=26,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Tacos - 3 beef tacos with cheese and sour cream",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="3 corn tortillas (150 cal). Ground beef filling (250 cal - cooked with fat). "
|
|
"Cheese (110 cal). Sour cream (60 cal). Total ~570 cal.",
|
|
name="Beef Tacos",
|
|
calories=570,
|
|
protein=25,
|
|
carbs=45,
|
|
fats=30,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Ribeye steak (10oz) with mashed potatoes",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="10oz Ribeye (fatty cut) ~750 cal. "
|
|
"Mashed potatoes with butter/cream (1 cup) ~300 cal. Total ~1050 cal.",
|
|
name="Ribeye Steak Dinner",
|
|
calories=1050,
|
|
protein=60,
|
|
carbs=35,
|
|
fats=75,
|
|
),
|
|
).with_inputs("description"),
|
|
# --- Snacks/Others ---
|
|
dspy.Example(
|
|
description="Medium Banana",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Standard fruit size.", name="Banana", calories=105, protein=1.3, carbs=27, fats=0.3
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Protein Shake (Whey)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 scoop whey (120 cal). Water (0 cal).",
|
|
name="Whey Protein Shake",
|
|
calories=120,
|
|
protein=24,
|
|
carbs=3,
|
|
fats=1,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Apple with peanut butter",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 apple (95 cal). 2 tbsp peanut butter (190 cal). Total ~285 cal.",
|
|
name="Apple & PB",
|
|
calories=285,
|
|
protein=8,
|
|
carbs=30,
|
|
fats=16,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Bag of potato chips (small)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Standard vending machine size (1.5 oz/42g). Fried.",
|
|
name="Potato Chips",
|
|
calories=220,
|
|
protein=3,
|
|
carbs=22,
|
|
fats=14,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Hummus and carrot sticks",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1/4 cup hummus (150 cal). 2 carrots (50 cal). Total ~200 cal.",
|
|
name="Hummus Snack",
|
|
calories=200,
|
|
protein=5,
|
|
carbs=25,
|
|
fats=9,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Chocolate chip cookie (Subway style)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 large cookie, heavy on sugar/butter.",
|
|
name="Large Cookie",
|
|
calories=220,
|
|
protein=2,
|
|
carbs=30,
|
|
fats=10,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Blueberry Muffin (Bakery size)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Large bakery muffin is notoriously high cal. Flour, sugar, oil.",
|
|
name="Bakery Muffin",
|
|
calories=450,
|
|
protein=6,
|
|
carbs=65,
|
|
fats=18,
|
|
),
|
|
).with_inputs("description"),
|
|
# --- Add 25 more diverse items to reach 50 ---
|
|
dspy.Example(
|
|
description="Hard boiled egg",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="One large egg.", name="Egg", calories=78, protein=6, carbs=0.6, fats=5
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Slice of cheddar cheese",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="1 oz slice.", name="Cheddar", calories=110, protein=7, carbs=0.4, fats=9
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Glass of whole milk (8oz)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Full fat dairy.", name="Whole Milk", calories=150, protein=8, carbs=12, fats=8
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Coca Cola (12oz can)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="High sugar soda.", name="Coke", calories=140, protein=0, carbs=39, fats=0
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Orange Juice (8oz)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Natural sugars.", name="OJ", calories=110, protein=2, carbs=26, fats=0
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Kind Bar (Dark Chocolate Nuts)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Nut based bar.", name="Nut Bar", calories=200, protein=6, carbs=16, fats=13
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Bowl of Beef Chili (1 cup)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Ground beef, beans, tomato base.", name="Chili", calories=300, protein=20, carbs=25, fats=15
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Pork Chop (baked) with green beans",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="6oz pork chop (250 cal). Steam beans (30 cal). Total ~280.",
|
|
name="Pork Chop Meal",
|
|
calories=280,
|
|
protein=35,
|
|
carbs=10,
|
|
fats=12,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Clam Chowder Bowl",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Cream based soup (heavy cream). 1.5 cups.",
|
|
name="Clam Chowder",
|
|
calories=450,
|
|
protein=12,
|
|
carbs=40,
|
|
fats=28,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Philly Cheesesteak",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Roll (250 cal). Fatty steak (400 cal). Cheese whiz/provolone (150 cal). Oil (100 cal).",
|
|
name="Cheesesteak",
|
|
calories=900,
|
|
protein=40,
|
|
carbs=50,
|
|
fats=55,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Fish and Chips (3 pieces)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Deep fried batter fits + fried chips. Very high oil absorption.",
|
|
name="Fish and Chips",
|
|
calories=950,
|
|
protein=30,
|
|
carbs=90,
|
|
fats=55,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Cobb Salad with ranch",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Greens, bacon, egg, avocado, blue cheese, ranch dressing. Salad is low cal, toppings are high.",
|
|
name="Cobb Salad",
|
|
calories=750,
|
|
protein=35,
|
|
carbs=15,
|
|
fats=60,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Hot Dog with bun, mustard, ketchup",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Processed meat link (150 cal). Bun (120 cal). Condiments (20 cal).",
|
|
name="Hot Dog",
|
|
calories=290,
|
|
protein=10,
|
|
carbs=25,
|
|
fats=16,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Pad Thai with Shrimp",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Rice noodles stir fried in oil and sugar based sauce. Peanuts.",
|
|
name="Pad Thai",
|
|
calories=800,
|
|
protein=25,
|
|
carbs=110,
|
|
fats=30,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Burrito (Chipotle style - Chicken, Rice, Beans, Cheese, Guac)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Tortilla (300). Rice (200). Beans (150). Chicken (180). Cheese (100). Guac (230!).",
|
|
name="Burrito",
|
|
calories=1160,
|
|
protein=55,
|
|
carbs=110,
|
|
fats=55,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Smoothie (Berry, Banana, Yogurt)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Healthy but sugar dense fruits + yogurt.",
|
|
name="Fruit Smoothie",
|
|
calories=300,
|
|
protein=8,
|
|
carbs=60,
|
|
fats=2,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Falafel Wrap",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Fried chickpea balls (250), pita (150), tahini sauce (100).",
|
|
name="Falafel Wrap",
|
|
calories=550,
|
|
protein=15,
|
|
carbs=70,
|
|
fats=25,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Macaroni and Cheese (1 cup homemade)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Pasta + Roux + Milk + lots of Cheese.",
|
|
name="Mac & Cheese",
|
|
calories=500,
|
|
protein=18,
|
|
carbs=45,
|
|
fats=28,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Ice Cream (2 scoops vanilla)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Sugar and Cream.", name="Ice Cream", calories=350, protein=6, carbs=40, fats=20
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Cottage Cheese (1 cup)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Low fat high protein dairy.", name="Cottage Cheese", calories=180, protein=25, carbs=10, fats=5
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Beef Jerky (1 bag / 3oz)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Dried meat, lean protein.", name="Beef Jerky", calories=240, protein=35, carbs=15, fats=4
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Edamame (1 cup in pod)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Soybeans.", name="Edamame", calories=190, protein=17, carbs=15, fats=8
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Popcorn (movie theater small, buttered)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Corn + oil popping + butter topping.",
|
|
name="Movie Popcorn",
|
|
calories=600,
|
|
protein=6,
|
|
carbs=60,
|
|
fats=40,
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Veggie Pizza Slice",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Cheese + Dough + Veggies.", name="Veggie Pizza", calories=260, protein=10, carbs=32, fats=10
|
|
),
|
|
).with_inputs("description"),
|
|
dspy.Example(
|
|
description="Salmon Nigiri (2 pcs)",
|
|
nutritional_info=NutritionalInfo(
|
|
reasoning="Rice ball + Slice of raw fish.", name="Salmon Nigiri", calories=120, protein=10, carbs=15, fats=3
|
|
),
|
|
).with_inputs("description"),
|
|
]
|