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.
- 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.
- React 19 & Vite
- Tailwind CSS v4
- React Router v7
- Recharts (Data Visualization)
- Framer Motion (Animations)
- Axios (API Client)
- FastAPI (High-performance Python web framework)
- MongoDB (Motor/PyMongo) (NoSQL Database for fast queries)
- Pytest (Automated Testing)
- Pydantic v2 (Data Validation)
- PyTorch & Torchvision (Model architecture and training: EfficientNet-B0)
- OpenCV & Pillow (Image processing and transformation)
- Scikit-Learn (Evaluation metrics)
- Multimodal AI Integration (OpenAI / Gemini integration)
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
Ensure you have a MongoDB cluster (e.g. MongoDB Atlas) or a local MongoDB instance running.
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 .envFill in .env with your actual Database URIs and API credentials. Do NOT commit .env!
Run the seeder to populate nutritional data:
python seed_nutrition.pyNavigate into the frontend and install dependencies:
cd Frontend
npm install
cp .env.example .envEnsure VITE_API_URL is pointing to the backend (e.g., http://127.0.0.1:8000).
From the Backend directory with your virtual environment activated:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Swagger API docs available at http://localhost:8000/docs.
From the Frontend directory:
npm run devOpen http://localhost:5173 in your browser.
- Upload: User uploads an image through the frontend.
- Pre-processing: Image is resized, normalized, and transformed (OpenCV/Pillow).
- Inference: PyTorch
EfficientNet-B0predicts the food class (Top-1 and Top-3 probabilities). - Validation: Predictions below confidence threshold are rejected or deferred to a multimodal vision engine (Gemini/OpenAI).
- Nutrition Fetch: Class maps to the MongoDB database for base nutritional info (per 100g).
- Computation: Total macros and health scores are dynamically adjusted based on serving size.
- 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.
- 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.