This project is a web-based platform for uploading invoice/receipt images, extracting key information using OCR and AI (LLM), and allowing users to view the results.
- File Upload: Upload receipt/invoice images (.png, .jpg) via a React frontend.
- OCR Processing: Tesseract OCR runs asynchronously via Celery to extract text from images.
- AI Data Extraction: Uses a Large Language Model (LLM) - configurable for cloud (OpenAI GPT) or local (Ollama) - to extract structured data (Merchant, Date, Total) from the OCR text.
- Database Storage: Stores receipt metadata, OCR text, and extracted fields in a PostgreSQL database.
- Status Check: View the processing status and extracted data for each uploaded receipt via the UI or API.
- Dockerized: Fully containerized using Docker and Docker Compose for easy setup and deployment.
- Backend: FastAPI (Python)
- Frontend: React
- Async Tasks: Celery + Redis
- Database: PostgreSQL + SQLAlchemy + Alembic (for migrations)
- OCR: Tesseract (via pytesseract) + Pillow
- AI Extraction: OpenAI API or Local LLM (e.g., Ollama)
- Containerization: Docker, Docker Compose
- Web Server (Frontend): Nginx
- Docker
- Docker Compose
- (Optional) Ollama: If you want to use a local LLM for data extraction. Install from ollama.com.
-
Clone the Repository:
git clone <your-repository-url> cd invoice_reader
-
Create
.envFile: Create a file named.envin the project root directory (invoice_reader/) and add the following content:# .env # --- Database & Celery (Defaults should work with Docker Compose) --- DATABASE_URL=postgresql://postgres:postgres@db:5432/invoice_db CELERY_BROKER_URL=redis://redis:6379/0 CELERY_RESULT_BACKEND=redis://redis:6379/0 # --- LLM Configuration --- # Set LLM_MODE to 'cloud' or 'local' LLM_MODE=cloud # Only needed if LLM_MODE=cloud and using OpenAI OPENAI_API_KEY=your_openai_api_key_here # Only needed if LLM_MODE=local # Use host.docker.internal for Docker on Mac/Windows to reach Ollama on host # For Linux host, you might need to find the Docker bridge IP or use --network="host" OLLAMA_BASE_URL=http://host.docker.internal:11434 # Example for LM Studio: OLLAMA_BASE_URL=http://host.docker.internal:1234/v1
- Important: Replace
your_openai_api_key_herewith your actual OpenAI API key if usingLLM_MODE=cloud.
- Important: Replace
-
(Optional) Setup Local LLM (Ollama): If you set
LLM_MODE=localin.env:- Make sure the Ollama application is running on your host machine.
- Pull the model specified in
app/celery_worker.py(default isllama3):ollama pull llama3
-
Build Docker Images:
docker-compose build
-
Start Services:
docker-compose up -d
This will start the FastAPI backend, React frontend, Celery worker, PostgreSQL database, and Redis broker.
-
Access Frontend: Open your web browser and navigate to: http://localhost:3000
-
Upload Receipt:
- Click "Choose File" and select an invoice/receipt image (.png, .jpg).
- Click "Upload".
- You will see the assigned Receipt ID upon successful upload.
-
Check Status:
- Enter the Receipt ID obtained after uploading into the "Check Receipt Status" section.
- Click "Check".
- The status ("pending", "processed", "error_...") and extracted data (Merchant, Date, Total) will be displayed.
POST /receipts/upload: Upload a receipt file (multipart/form-data with 'file' field).GET /receipts/{receipt_id}: Get status and details of a specific receipt.GET /health: Health check endpoint for the backend.
- LLM Mode (
.envfile):LLM_MODE=cloud: Uses the OpenAI API (requiresOPENAI_API_KEY).LLM_MODE=local: Uses a local LLM server specified byOLLAMA_BASE_URL(requires Ollama or similar running on the host).
docker-compose downTo remove the database volume as well:
docker-compose down -v