Metadata-Version: 2.4
Name: tejas-label-ocr
Version: 0.1.2
Summary: OCR extraction and text grouping for product/nutrition label images
Project-URL: Homepage, https://github.com/tpncoder/tejas-label-ocr
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
Requires-Dist: opencv-python
Requires-Dist: easyocr
Requires-Dist: numpy
Requires-Dist: mistralai
Requires-Dist: python-dotenv

tejas-label-ocr
===============

**Lightweight, stateless Python library for extracting structured data from product packaging labels using OCR and LLM-based parsing.**

|PyPI version| |Python 3.8+| |License: MIT|

---

Features
--------

- **Stateless & In-Memory**: Processes raw image bytes—no disk I/O, ideal for serverless (FastAPI/Flask).
- **OCR + LLM Powered**: Uses **EasyOCR** for text extraction and **Mistral AI** (`mistral-small-latest`) for structured parsing.
- **Noise Filtering**: Automatically cleans low-confidence OCR text and groups spatial blocks (rows/columns/proximity).
- **Flexible Auth**: Pass ``api_key`` directly or via ``MISTRAL_API_KEY`` environment variable.
- **Structured JSON Output**: Extracts brand, product name, ingredients, nutrition facts, allergens, and more.

---

Installation
------------

.. code-block:: bash

    pip install tejas-label-ocr

---

Usage
-----

Front Label Processing
~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    from label_ocr import process_front_label

    with open("product_label.jpg", "rb") as f:
        image_bytes = f.read()

    result = process_front_label(image_bytes, api_key="your-mistral-api-key")
    print(result)
    # Output: {"brand": "Nestlé", "product_name": "Organic Oats", "claims": ["Gluten-Free", "Non-GMO"], ...}

Nutrition Label Processing
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    from label_ocr import process_nutrition_label

    with open("nutrition_panel.jpg", "rb") as f:
        image_bytes = f.read()

    result = process_nutrition_label(image_bytes, api_key="your-mistral-api-key")
    print(result)
    # Output: {"serving_size": "30g", "nutrients": [{"name": "Calories", "value": 120, "unit": "kcal", "%RDA": 6}], ...}

---
Notes
-----

- Requires a **Mistral AI API key** (sign up at `Mistral AI <https://mistral.ai/>`_).
- For best results, use high-resolution images of labels with clear text.

.. |PyPI version| image:: https://badge.fury.io/py/tejas-label-ocr.svg
   :target: https://badge.fury.io/py/tejas-label-ocr

.. |Python 3.8+| image:: https://img.shields.io/badge/python-3.8+-blue.svg
   :target: https://www.python.org/downloads/

.. |License: MIT| image:: https://img.shields.io/badge/license-MIT-green.svg
   :target: https://opensource.org/licenses/MIT
