mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 12:28:46 +01:00
Add AI-powered nutrition and plan modules
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.
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import litellm
|
||||
import dspy
|
||||
from typing import Any
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
|
||||
from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.ai.nutrition import NutritionalInfo, analyze_nutrition_from_image, nutrition_module
|
||||
from app.api import deps
|
||||
from app.ai.nutrition import nutrition_module, NutritionalInfo
|
||||
from app.core.security import create_access_token # Just ensuring we have auth imports if needed later
|
||||
from app.models.user import User
|
||||
from app.models.food import FoodLog # Added FoodItem
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class AnalyzeRequest(BaseModel):
|
||||
description: str
|
||||
|
||||
from app.models.food import FoodLog, FoodItem
|
||||
from app.api.deps import get_session
|
||||
from app.core.security import get_password_hash # Not needed
|
||||
from app.config import settings
|
||||
|
||||
@router.post("/analyze", response_model=NutritionalInfo)
|
||||
def analyze_food(
|
||||
@@ -30,6 +30,24 @@ def analyze_food(
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/analyze/image", response_model=NutritionalInfo)
|
||||
async def analyze_food_image(
|
||||
file: UploadFile = File(...),
|
||||
description: str = Form(""),
|
||||
) -> Any:
|
||||
"""
|
||||
Analyze food image and return nutritional info.
|
||||
"""
|
||||
try:
|
||||
contents = await file.read()
|
||||
return analyze_nutrition_from_image(contents, description)
|
||||
except litellm.exceptions.BadRequestError as e:
|
||||
raise HTTPException(status_code=400, detail=f"Invalid image or request: {str(e)}")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/log", response_model=FoodLog)
|
||||
def log_food(
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user