Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🥗 AI Food Nutrition Analyzer

A full-stack, production-grade application that leverages Machine Learning (PyTorch) and Multimodal Computer Vision to analyze food images, identify dishes, and compute detailed nutritional metrics, health scores, and dietary recommendations.


✨ Main Features

  • Real-Time Image Recognition: Accurately classifies images using an EfficientNet-B0 PyTorch model and an advanced multimodal fallback (OpenAI/Gemini).
  • Nutritional Calculation: Connects to MongoDB to compute dynamic macronutrients (Calories, Protein, Carbs, Fats) based on estimated serving sizes.
  • Health Scoring Engine: Evaluates meals and provides actionable, personalized dietary suggestions.
  • Secure User Authentication: Uses JWT access tokens and bcrypt hashing for login and registration.
  • User Dashboard & History: Tracks previous meal scans, provides statistics on average calories, and aggregates historical data.
  • Responsive UI: A modern, clean frontend built with React and Tailwind CSS.

🛠️ Technologies Used

Frontend

  • React 19 & Vite
  • Tailwind CSS v4
  • React Router v7
  • Recharts (Data Visualization)
  • Framer Motion (Animations)
  • Axios (API Client)

Backend

  • FastAPI (High-performance Python web framework)
  • MongoDB (Motor/PyMongo) (NoSQL Database for fast queries)
  • Pytest (Automated Testing)
  • Pydantic v2 (Data Validation)

Machine Learning / Computer Vision

  • PyTorch & Torchvision (Model architecture and training: EfficientNet-B0)
  • OpenCV & Pillow (Image processing and transformation)
  • Scikit-Learn (Evaluation metrics)
  • Multimodal AI Integration (OpenAI / Gemini integration)

📐 Project Architecture

AI Food Nutrition Analyzer/
├── Backend/                 # FastAPI & PyTorch ML Engine
│   ├── app/                 # API Routes, Services, Auth, Models
│   ├── ml/                  # Model definition, training & evaluation scripts
│   │   ├── dataset/         # Dataset loaders
│   │   ├── evaluation/      # Model testing metrics
│   │   ├── models/          # Trained weights (food_classifier.pth)
│   │   └── training/        # Training pipeline
│   ├── tests/               # Backend integration and unit tests
│   ├── uploads/             # Image storage directory
│   ├── requirements.txt     # Python dependencies
│   ├── seed_nutrition.py    # Database seeder
│   └── .env                 # Backend Configuration (Local only)
├── Frontend/                # React Web Application
│   ├── src/                 # Components, Context, Layouts, Pages, Routes
│   ├── public/              # Static frontend assets
│   ├── package.json         # Node.js dependencies
│   ├── vite.config.js       # Vite bundler configuration
│   └── .env                 # Frontend Configuration (Local only)
└── README.md                # Project Overview

🚀 Installation Instructions

1. Database Setup

Ensure you have a MongoDB cluster (e.g. MongoDB Atlas) or a local MongoDB instance running.

2. Backend Setup

Navigate into the backend and set up the environment:

cd Backend
python -m venv venv
# Windows: .\venv\Scripts\Activate.ps1
# Mac/Linux: source venv/bin/activate

pip install -r requirements.txt
cp .env.example .env

Fill in .env with your actual Database URIs and API credentials. Do NOT commit .env!

Run the seeder to populate nutritional data:

python seed_nutrition.py

3. Frontend Setup

Navigate into the frontend and install dependencies:

cd Frontend
npm install
cp .env.example .env

Ensure VITE_API_URL is pointing to the backend (e.g., http://127.0.0.1:8000).


⚡ Running the Application

Backend Run Command

From the Backend directory with your virtual environment activated:

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Swagger API docs available at http://localhost:8000/docs.

Frontend Run Command

From the Frontend directory:

npm run dev

Open http://localhost:5173 in your browser.


🧠 ML Prediction Workflow & Information

  1. Upload: User uploads an image through the frontend.
  2. Pre-processing: Image is resized, normalized, and transformed (OpenCV/Pillow).
  3. Inference: PyTorch EfficientNet-B0 predicts the food class (Top-1 and Top-3 probabilities).
  4. Validation: Predictions below confidence threshold are rejected or deferred to a multimodal vision engine (Gemini/OpenAI).
  5. Nutrition Fetch: Class maps to the MongoDB database for base nutritional info (per 100g).
  6. Computation: Total macros and health scores are dynamically adjusted based on serving size.

Dataset & Model Metrics

  • Contains standard training, validation, and test datasets for 6 major food classes (biryani, burger, dosa, idli, pizza, samosa).
  • Overall Accuracy: 97.22%
  • Model Storage: Trained PyTorch weights are localized in Backend/ml/models/food_classifier.pth.

🔮 Future Improvements

  • Expand local PyTorch dataset to support hundreds of global cuisines.
  • Implement personalized diet plans based on user health profiles.
  • Introduce barcode scanning functionality for pre-packaged foods.
  • Create a mobile native application (React Native/Flutter).
  • Enhance multimodal vision pipeline for detailed ingredient breakdown.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages