Skip to content

grimgrimberg/invoice-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧾 Invoice Tracker

A sophisticated AI-powered invoice tracking system with OCR capabilities, intelligent categorization, and advanced RAG (Retrieval-Augmented Generation) analysis.

✨ Features

  • 📄 OCR Processing: Extract data from invoice images using Google Vision API
  • 🤖 AI Categorization: Automatic invoice categorization using Gemini AI
  • 🔍 Advanced RAG: Chain-of-thought reasoning for intelligent spending analysis
  • 📊 Vector Search: ChromaDB integration for semantic invoice search
  • 🎨 Modern UI: Clean Gradio interface with multiple tabs
  • 🔄 Duplicate Detection: Smart duplicate removal with Hebrew/multilingual support
  • 📈 Analytics: Comprehensive spending insights and trends
  • 💾 Database: Persistent storage with ChromaDB vector database

🛠️ Technology Stack

  • Backend: Python 3.8+
  • AI/ML: Google Gemini, Google Vision API
  • Database: ChromaDB (Vector Database)
  • Frontend: Gradio
  • OCR: Google Cloud Vision API
  • Environment: python-dotenv

📦 Installation

  1. Clone the repository

    git clone https://github.com/yourusername/invoice-tracker.git
    cd invoice-tracker
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variables Create a .env file in the src folder:

    GEMINI_API_KEY=your_gemini_api_key_here
    GOOGLE_CLOUD_PROJECT=your_google_cloud_project_id
  4. Get API Keys

🚀 Usage

  1. Start the application

    cd src
    python main.py
  2. Open your browser to the displayed URL (usually http://localhost:7860)

  3. Upload invoices via the "📄 Upload Invoices" tab

  4. Ask questions using the "🤖 AI Insights" tab with natural language:

    • "What's my total spending this month?"
    • "Which vendor do I spend the most on?"
    • "Show me my grocery expenses"

📁 Project Structure

invoice-tracker/
├── src/
│   ├── main.py                 # Application entry point
│   ├── services/
│   │   ├── ocr_service.py      # OCR processing
│   │   ├── categorization_service.py  # AI categorization
│   │   ├── rag_service.py      # RAG with chain-of-thought
│   │   └── chroma_service.py   # ChromaDB operations
│   ├── ui/
│   │   └── gradio_interface.py # Web interface
│   ├── utils/
│   │   ├── invoice_processor.py # Invoice processing
│   │   └── cleanup_duplicates.py # Duplicate detection
│   ├── data/
│   │   ├── invoices.json       # Invoice storage
│   │   └── chroma_db/          # Vector database
│   └── .env                    # Environment variables (not in repo)
├── requirements.txt            # Dependencies
├── .gitignore                 # Git ignore rules
└── README.md                  # This file

🔧 Features Overview

📄 OCR Processing

  • Extracts text from invoice images
  • Identifies vendors, amounts, dates, invoice numbers
  • Supports multiple image formats (PNG, JPG, PDF)

🤖 AI Categorization

  • Automatic spending category assignment
  • Smart vendor recognition
  • Context-aware categorization

🔍 Advanced RAG

  • Chain-of-Thought Reasoning: Structured 4-step analysis
  • Vector Similarity Search: Find relevant invoices using ChromaDB
  • Enhanced Context: Combines statistics with query-specific data
  • Natural Language Queries: Ask questions in plain English

📊 Analytics

  • Total spending analysis
  • Category breakdowns with percentages
  • Monthly/yearly trends
  • Top vendor identification
  • Spending pattern insights

🔄 Duplicate Detection

  • Multi-criteria duplicate detection
  • Hebrew/multilingual support
  • Semantic vendor matching
  • Date format normalization
  • Invoice number matching

🧠 Chain-of-Thought RAG Process

The RAG system follows a structured reasoning approach:

  1. Understanding the Question

    • Analyze what information is needed
    • Identify relevant time periods and categories
  2. Data Analysis Approach

    • Select relevant data points
    • Plan necessary calculations
  3. Calculations & Insights

    • Perform step-by-step analysis
    • Identify patterns and anomalies
  4. Final Answer

    • Provide clear, actionable insights
    • Include specific numbers and recommendations

🛠️ API Configuration

Gemini API Setup

  1. Go to Google AI Studio
  2. Create a new API key
  3. Add to .env file as GEMINI_API_KEY

Google Cloud Vision Setup

  1. Create project at Google Cloud Console
  2. Enable Vision API
  3. Create service account and download JSON key
  4. Set GOOGLE_APPLICATION_CREDENTIALS environment variable

📝 Example Queries

  • Total Spending: "What's my total spending this year?"
  • Category Analysis: "How much do I spend on groceries vs restaurants?"
  • Vendor Analysis: "Which vendor do I spend the most money on?"
  • Trends: "Show me my spending trends over the last 6 months"
  • Specific Items: "Find all invoices for technology purchases"

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Google AI for Gemini API
  • ChromaDB for vector database capabilities
  • Gradio for the web interface
  • Google Cloud Vision for OCR capabilities

🐛 Troubleshooting

Common Issues

  1. RAG not working: Check GEMINI_API_KEY in .env file
  2. OCR failing: Verify Google Cloud credentials
  3. ChromaDB errors: Ensure chromadb package is installed
  4. Import errors: Check Python path and package installations

Support

If you encounter issues:

  1. Check the console output for error messages
  2. Verify all environment variables are set correctly
  3. Ensure all dependencies are installed
  4. Check API key permissions and quotas

About

AI-powered invoice tracking with OCR, categorization, and RAG analysis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages