CoolFace
Apppublic

arunSeervi/offline-ai-docs

sourceHugging Facegpl-3.0updated 3mo agoView on Hugging Face
0likes
App README

CPU-First Offline AI Document Intelligence Platform

An offline-first document processing pipeline that transforms unstructured documents (PDFs, DOCXs, and images) into structured, validated relational database profiles. All operations run entirely on local CPU resources with zero network dependencies.

[!IMPORTANT] Offline Compliance: This application does not connect to external APIs (no OpenAI, no Anthropic, no Gemini). All OCR, embeddings, vector indexing, and LLM inference run locally on the host's CPU.

๐Ÿš€ Key Features

  • โ€”100% Offline execution: Zero HTTP calls to third-party services.
  • โ€”CPU-Optimized Inference: Utilizes quantized GGUF models via llama.cpp and onnxruntime CPU threads.
  • โ€”Decoupled AI Pipeline: Swap components (OCR, embedder, vector store, LLM) without altering business logic.
  • โ€”Strict JSON Outputs: Validated against configurable Pydantic schemas with a single-retry recovery mechanism.
  • โ€”Relational Storage: SQLite database for documents, chunk relationships, extracted entities, and metadata.
  • โ€”Interactive Side-by-Side Canvas: React/Vite dashboard illustrating text block maps alongside extracted database fields.

๐Ÿ› ๏ธ Tech Stack & Constraints

LayerTechnologyVersion / Configuration
Backend FrameworkFastAPI + UvicornPython 3.13.5
Dependency ManageruvExclusive package manager (pyproject.toml / uv.lock)
Local LLM Runtimellama.cpp (llama-cpp-python)Qwen2.5-1.5B-Instruct GGUF Q4KM
Local Embeddingonnxruntime (CPU)all-MiniLM-L6-v2 ONNX Model
Vector SearchFAISS (CPU)Local index storage
OCR FallbackTesseractUsed when native digital text extraction fails
DatabaseSQLite + SQLAlchemyStrict foreign keys and cascaded deletions
FrontendReact + Vite + TypeScriptTailwind CSS styling with dark glassmorphism

๐Ÿ“‚ Project Architecture

The repository enforces a clean, modular structure:

text
offline_first/
โ”œโ”€โ”€ .specify/                   # GitHub Spec Kit templates and constitution
โ”‚   โ””โ”€โ”€ memory/
โ”‚       โ”œโ”€โ”€ constitution.md     # Engineering principles and coding standards
โ”‚       โ”œโ”€โ”€ specification.md    # Product features specification
โ”‚       โ””โ”€โ”€ plan.md             # Technical implementation blueprints
โ”œโ”€โ”€ backend/                    # FastAPI python app
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ””โ”€โ”€ v1/
โ”‚   โ”‚       โ””โ”€โ”€ endpoints/      # REST API route handlers
โ”‚   โ”œโ”€โ”€ core/                   # Single-responsibility AI and DB modules
โ”‚   โ”‚   โ”œโ”€โ”€ config/             # System settings and environment variables
โ”‚   โ”‚   โ”œโ”€โ”€ ocr/                # Native layout parsing and Tesseract engine
โ”‚   โ”‚   โ”œโ”€โ”€ chunking/           # Recursive text splitting logic
โ”‚   โ”‚   โ”œโ”€โ”€ embedding/          # ONNX model loader and vector computation
โ”‚   โ”‚   โ”œโ”€โ”€ rag/                # FAISS vector database and retriever
โ”‚   โ”‚   โ”œโ”€โ”€ llm/                # llama.cpp client and prompt grammar
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/            # Pydantic structures for validation
โ”‚   โ”‚   โ”œโ”€โ”€ storage/            # Local file persistence
โ”‚   โ”‚   โ”œโ”€โ”€ services/           # Decoupled processing pipelines
โ”‚   โ”‚   โ””โ”€โ”€ database/           # Relational models and session managers
โ”‚   โ”œโ”€โ”€ tests/                  # Pytest unit suites
โ”‚   โ””โ”€โ”€ main.py                 # Backend Entrypoint
โ”œโ”€โ”€ frontend/                   # React + Vite client app
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/         # Reusable canvas widgets (DocumentViewer)
โ”‚   โ”‚   โ”œโ”€โ”€ pages/              # Views (Upload, Status, Search)
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx             # Root page containing layout rules
โ”‚   โ”‚   โ””โ”€โ”€ index.css           # Styling entrypoint with Tailwind directives
โ”‚   โ”œโ”€โ”€ postcss.config.js       # PostCSS config with @tailwindcss/postcss
โ”‚   โ””โ”€โ”€ tailwind.config.js      # Tailwind scan paths configuration
โ”œโ”€โ”€ docs/                       # Architectural specs and API documentation
โ”œโ”€โ”€ scripts/                    # Command utilities
โ”‚   โ”œโ”€โ”€ setup.sh                # Install and synchronize packages
โ”‚   โ””โ”€โ”€ run.sh                  # Run dev servers
โ””โ”€โ”€ models/                     # Weight store for GGUF and ONNX models

๐Ÿ”ง Prerequisites & Setup

1. System Requirements

  • โ€”Python: 3.13.*
  • โ€”Node.js: >= 20.0.0
  • โ€”uv: Python packaging CLI
  • โ€”Tesseract: Local OCR binaries (required only for image files/scanned PDFs)
  • โ€”Debian/Ubuntu: sudo apt-get install tesseract-ocr
  • โ€”macOS: brew install tesseract

2. Initialization

Run the project bootstrap script:

bash
./scripts/setup.sh

This script will build the Python virtual environment using uv sync and install frontend npm packages.

3. Placing Model Weights

Download and copy required local model weights to the models/ directory before starting the application:

  1. 1.Qwen2.5-1.5B-Instruct-GGUF (Q4KM): Download the weights from HuggingFace and place them as models/qwen2.5-1.5b-instruct-q4_k_m.gguf.
  2. 2.all-MiniLM-L6-v2 ONNX: Execute the download script to automatically fetch and configure ONNX weights:
bash
   uv run scripts/download_models.py

๐Ÿƒ Running the Application

Option A: Running Both Servers Simultaneously (Recommended)

Start both frontend and backend development environments together:

bash
./scripts/run.sh

Option B: Running the Servers Separately

If you prefer to run or debug the components individually, open two terminal sessions:

Terminal 1: Backend Server

Start the FastAPI application on port 8000:

bash
uv run uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reload
Terminal 2: Frontend Server

Start the Vite dev server on port 5173:

bash
cd frontend
npm run dev

๐Ÿงช Static Quality Gates & Testing

We enforce strict validation checks. Run these before pushing changes:

bash
# Apply code styling
uv run black backend
uv run isort backend

# Run linters and checks
uv run ruff check backend
uv run mypy backend

# Run security checks
uv run bandit -r backend --exclude backend/tests

# Run unit test suites
uv run pytest

# Execute all pre-commit hooks manually
uv run pre-commit run --all-files

๐Ÿ“ License

This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.