ZO
ZobayerAkib/AI-Invoice-Analyzer
An AI-powered invoice and receipt analyzer that extracts structured invoice data from images (JPG/PNG) and PDF documents using a Large Language Model (LLM).
๐งพ AI Invoice Analyzer (FastAPI + LLM + Vision + PDF)
An AI-powered invoice and receipt analyzer that extracts structured invoice data from images (JPG/PNG) and PDF documents using a Large Language Model (LLM).
The system supports vision-based parsing, PDF text extraction, and outputs validated JSON via a FastAPI backend.
๐น Demo Video
๐ Features
- ๐ธ Parse invoice images (JPG, PNG)
- ๐ Parse text-based PDFs
- ๐ค Uses GitHub-hosted LLM via OpenAI-compatible SDK
- ๐ง Smart vendor detection (logos, headers, prominent text)
- ๐งพ Extracts structured fields:
- Vendor
- Invoice number
- Invoice date
- Due date
- Total amount
- Currency
- Validation flag
- ๐ FastAPI REST API
- ๐งฉ Schema-safe & production-ready (no API crashes)
๐ Project Structure
ai-invoice-analyzer/
โ
โโโ main.py # FastAPI backend
โโโ requirements.txt # Python dependencies
โโโ .env # Environment variables (not committed)
โโโ .gitignore
โโโ README.md
โ๏ธ Tech Stack
Backend: FastAPI, Pydantic
AI Model: GitHub-hosted LLM (OpenAI SDK compatible)
Vision: Image-based invoice parsing
PDF Parsing: PyMuPDF
Deployment-ready: Uvicorn
๐ Environment Setup
Create a .env file in the project root:
BASE_URL=https://models.inference.ai.azure.com
API_KEY=your_github_model_api_key
MODEL_NAME=gpt-4o-mini
๐ฆ Installation
pip install -r requirements.txt
Required packages:
fastapi
uvicorn
openai
python-dotenv
python-multipart
pymupdf
โถ๏ธ Run the Application
uvicorn main:app --reload
๐ค API Usage
Upload Invoice (Image or PDF)
curl -X POST http://127.0.0.1:8000/analyze-invoice \
-H "accept: application/json" \
-F "file=@invoice.jpg"
๐ฅ Example Response
{
"vendor": "ABC Seller",
"invoice_number": "INV-2025-019",
"invoice_date": "2025-12-20",
"due_date": null,
"total_amount": "530.00",
"currency": "BDT",
"valid": true
}
๐ง How It Works
Image Invoices
- Invoice image is base64 encoded.
- Sent to a vision-capable LLM.
- Vendor extracted from logo/header.
- Structured JSON returned with fields:
vendorinvoice_numberinvoice_datedue_datetotal_amountcurrencyvalid
PDF Invoices
- Text extracted using PyMuPDF.
- Extracted text sent to LLM.
- Invoice fields parsed from content into structured JSON.
๐ Author
Md. Zobayer Ibna Kabir
CSE Graduate | AI & ML Enthusiast
GitHub: https://github.com/ZobayerAkib
โญ If you find this project useful, consider giving it a star!