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.
.
βββ 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
/product-name
Purpose: Extract product name from an uploaded image.
POST
{
"name": "quaker oats"
}
/nutrition
Purpose: Get nutritional information for a given product name.
POST
{
"product": "quaker oats"
}
{
"heading": "Quaker Oats Nutritional Summary",
"data": {
"Calories": "150 kcal",
"Protein": "5g",
"Carbs": "27g",
"Fat": "3g"
}
}
[Image Upload] ββ
βββ> OCR (EasyOCR) ββ> Product Name βββ
β
Google Search API (SERP)
β
Groq LLM (via prompt)
β
Structured JSON Table of Nutrients
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
# 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.
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 |
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.