smart-nutrition-api

🧠 Smart Nutrition API

πŸ“Œ Overview

It is an intelligent OCR and LLM-powered API that automates the extraction of nutritional data for branded, packaged food products using just an image. The system leverages Optical Character Recognition (OCR), web search, and Large Language Models (LLMs) to infer and structure health-related information in JSON format, helping health-conscious users understand what they consume and developers building nutrition-focused applications.
This project is designed purely as an API layer and can be seamlessly integrated into any custom frontend UI (web/mobile) to deliver end-to-end functionality.

πŸ“ Directory Structure

.
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ easyocr_model/             # EasyOCR pre-trained models (downloaded manually)
β”‚   β”œβ”€β”€ utility/
β”‚   β”‚   β”œβ”€β”€ google_api.py          # Uses Google Gemini to fetch nutritional product info
β”‚   β”‚   β”œβ”€β”€ llm.py                 # Interfaces with LLM for structured JSON output
β”‚   β”‚   β”œβ”€β”€ nutrition_data.py      # Core logic to fetch and clean nutrition data
β”‚   β”‚   └── ocr.py                 # Extracts product name from image using EasyOCR
β”‚   └── main.py                    # Flask API entry point
β”œβ”€β”€ .gitignore
β”œβ”€β”€ Dockerfile
└── requirements.txt

πŸ”Œ API Endpoints

  1. /product-name Purpose: Extract product name from an uploaded image.
    • Method: POST
    • Payload: Form-data with key β€œproduct” as the image file.
    • Returns:
      {
        "name": "quaker oats"
      }
      
  2. /nutrition Purpose: Get nutritional information for a given product name.
    • Method: POST
    • Payload (JSON):
        {
          "product": "quaker oats"
        }
      
    • Returns:
      {
        "heading": "Quaker Oats Nutritional Summary",
        "data": {
          "Calories": "150 kcal",
          "Protein": "5g",
          "Carbs": "27g",
          "Fat": "3g"
        }
      }
      

πŸ”„ Flow Overview

[Image Upload] ─┐
                └──> OCR (EasyOCR) ──> Product Name ──┐
                                                      ↓
                                           Google Search API (SERP)
                                                      ↓
                                            Groq LLM (via prompt)
                                                      ↓
                                      Structured JSON Table of Nutrients

πŸ“¦ Setup Instructions

βœ… Requirements

βš™οΈ Installation

git clone https://github.com/tuhindutta/smart-nutrition-api
cd smart-nutrition-api

# Install dependencies
pip install -r requirements.txt

# Run the API
cd app
python main.py

🐳 Docker Support (Optional)

# Build docker image
docker build -t nutrition-api .

# Run the container
docker run -p 8000:8000 \
  -e GOOGLE_API_KEY=your_key \
  -e GROQ_API_KEY=your_key \
  nutrition-api

The already built image in dockerhub can also be used instead, using the commands/steps mentioned in the dockerhub repository.

πŸ› οΈ Tech Stack

Component Tool/Service
OCR EasyOCR
Image Processing Pillow, NumPy
LLM Interface llama-3.3-70b-versatile
Search API gemini-2.5-flash-lite
Web API Flask
Containerization Docker

🀝 Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes. For more details and updates, visit the GitHub Repository.