AI-powered Intelligent Document Processing (IDP) System for Bills & Invoices
Extract structured information from bills, automatically categorize expenses, store them in a database, and interact with your expenses using natural language.
Managing receipts manually is time-consuming.
ScanX Expense automates the complete workflow by combining:
- Computer Vision
- OCR
- Local LLMs
- SQLite
- Streamlit
The system converts unstructured invoice images into structured records and allows users to chat with their expense database.
β Process invoices automatically
β Extract structured data
β Categorize expenses
β Store in database
β Query using Natural Language
β Run completely offline using Ollama
- Image cleaning
- Noise removal
- Grayscale conversion
- Thresholding
- Batch processing
- Reads receipts
- Supports multiple invoices
- Batch OCR
- Generates raw text
Local LLM extracts
- Invoice Number
- Vendor
- Customer
- Date
- Amount
- Total
- Line Items
Returns structured JSON.
Each line item is classified into
- Food
- Grocery
- Travel
- Logistic
- Utilities
- Drinks
- Other
Stores
- invoice
- line items
- totals
- categories
using SQLite.
Interactive Streamlit dashboard
Supports
- Search
- Filters
- Invoice lookup
- Category lookup
Ask questions like
How much did I spend on food?
Show invoices from Amazon.
Highest spending category.
The LLM generates SQL automatically.
Bill Images
β
βΌ
Image Preprocessing
(OpenCV)
β
βΌ
OCR Engine
(Tesseract OCR)
β
βΌ
Raw OCR Text Output
β
βΌ
βββββββββββββββββββββββ
β Agent 1 (Ollama) β
β Invoice Extraction β
βββββββββββββββββββββββ
β
βΌ
Structured Invoice JSON
β
βΌ
βββββββββββββββββββββββ
β Agent 2 (Ollama) β
β Expense Category β
βββββββββββββββββββββββ
β
βΌ
SQLite Database
β
βΌ
βββββββββββββββββββββββ
β Streamlit Dashboard β
βββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β Agent 3 (Ollama) β
β NL β SQL β
βββββββββββββββββββββββ
β
βΌ
Chat with Bills
ScanX_Expense/
β
βββ bill_images/
β
βββ image_cleaning.py
βββ ocr_processor.py
βββ parser.py
βββ data_insertion.py
βββ table_creation.py
β
βββ ollama1.py
βββ ollama2.py
βββ ollama3.py
β
βββ prompt1.py
βββ prompt2.py
βββ prompt3.py
β
βββ frontend1.py
βββ frontend2.py
β
βββ extracted_text.txt
βββ ocr_master.db
β
βββ README.md
| Layer | Technology |
|---|---|
| Language | Python |
| Image Processing | OpenCV |
| OCR | Tesseract OCR |
| LLM | Ollama |
| Model | Gemma 3 / Phi-3 |
| Database | SQLite |
| Dashboard | Streamlit |
| Data | Pandas |
git clone https://github.com/<your-username>/ScanX_Expense.git
cd ScanX_Expensepip install -r requirements.txtDownload
https://github.com/UB-Mannheim/tesseract/wiki
Update
pytesseract.tesseract_cmd = r"YOUR_PATH"ollama pull gemma3:4bor
ollama pull phi3:3.8bPut receipts inside
bill_images/
Image Cleaning
python image_cleaning.pyOCR
python ocr_processor.pyCreate Database
python table_creation.pyExtract + Categorize + Store
python data_insertion.pyLaunch Dashboard
streamlit run frontend2.pyInvoice Extraction
Input
OCR Text
Output
{
Invoice_No,
Vendor,
Customer,
Description,
Amount
}Expense Categorization
Input
Description
Output
Food
Travel
etc.
Natural Language β SQL
Input
How much did I spend on food?
Output
SELECT SUM(amount)Table
ocr_line_items
Stores
- Invoice Number
- Vendor
- Customer
- Amount
- Category
- Description
- Total
- Source Image
)
- Uses Tesseract OCR, which struggles with noisy or low-quality receipts.
- OCR accuracy drops on handwritten notes, skewed images, and faded receipts.
- Image preprocessing is basic and may not handle all receipt conditions.
- Local LLMs can occasionally return malformed JSON that requires validation.
- SQLite is suitable for local usage but not for multi-user or production deployments.
- Replace Tesseract with PaddleOCR
- Add TrOCR support
- EasyOCR benchmark
- Google Vision OCR support
- Azure Document Intelligence integration
- CLAHE enhancement
- Deskew receipts automatically
- Perspective correction
- Adaptive thresholding
- Morphological filtering
- Shadow removal
- Reflection removal
- Blur detection
- Receipt edge detection
- Auto crop
- Multi-Agent Workflow
- LLM Output Validation
- Retry Strategy
- JSON Schema Validation
- Confidence Score
- Vendor Normalization
- Duplicate Bill Detection
- PostgreSQL support
- MongoDB support
- Vector Database
- Semantic Search
- Embeddings
- RAG Pipeline
- Memory
- Charts
- Spending Trends
- Monthly Reports
- PDF Export
- Excel Export
- User Authentication
- Multi-user Support
- REST API
- Docker Deployment
- Cloud Deployment
Contributions are welcome!
If you'd like to improve OCR accuracy, image preprocessing, LLM prompts, or the dashboard, feel free to open an issue or submit a pull request.
MIT License