How ck-rajput/invoice_information_application works
Project Type and Purpose
• This is a full-stack, single-page Streamlit application (“app.py”) providing an end-to‐end invoice extraction pipeline: from image upload and OCR through post-processing, ML-based field extraction, and visualization. It also supports model training/evaluation and writes results to a JSON store.
File Structure
• Top-Level
• app.py – Streamlit UI entrypoint
• config.yaml + .env (not checked in) – configuration for API keys, thresholds
• invoice_results.json – local storage for extracted results
• requirements.txt / setup.py – dependencies & packaging
• Source Modules (src/)
• data_processing/
– download_datasets.py – fetch or update raw invoice image sets
– preprocess.py – image cleaning, resizing, normalization
• extraction/
– ocr_engine.py – plugin‐style wrapper over Gemini API, Tesseract, EasyOCR, PaddleOCR
– extract.py – post-OCR parsing, regex or ML model for field extraction, confidence scoring
• model/
– train.py – training simulation, model evaluation / analytics pipeline
• utils/
– config_loader.py – reads config.yaml/.env, supplies API keys & thresholds
– logger.py – unified logging for traceability
README for Architecture Insights
• Frontend: Streamlit
• OCR Engines: multiple external services & libraries
• ML: simulated training in model/train.py
• Storage: local JSON output + in-app dashboards
• No external database: invoice_results.json acts as simple persistence
a. Main Components
1. User Interface Layer (Streamlit app)
2. Application Service Layer (Controller in app.py invoking utility modules)
3. Data Processing Module
4. OCR & Extraction Module
5. ML Training Module
6. Configuration & Logging (cross‐cutting)
7. Data Store (invoice_results.json)
8. External Services (Gemini API, Tesseract, EasyOCR, PaddleOCR)
b. Relationships & Data Flow
• UI → Config Loader (load API keys, thresholds)
• UI → Data Processing → Preprocessed Image Data
• Preprocessed Data → OCR Engine → Raw Text
• Raw Text → Extraction → Structured Fields + Confidence Scores
• Structured Output → JSON Store → UI Dashboard / Download
• “Train Model” UI action → Model Module → (optionally) update analytics dashboard
• All modules → Logger → Centralized logs
c. Architectural Patterns & Design Principles
• Layered Architecture: UI / Service / Processing / Storage
• Plugin Pattern: ocr_engine.py dynamically selects OCR backend
• Single Responsibility & Modularity: each script fulfills one clear role
• Configuration‐Driven: config_loader abstracts environment vs YAML
d. Key Technologies & Frameworks
• Streamlit (UI)
• Python packages: Pillow, OpenCV, Pandas
• OCR: Gemini API, Tesseract, EasyOCR, PaddleOCR
• Logging: custom logger in utils/logger.py
• Data storage: JSON file