| --- |
| title: ALDDS |
| emoji: ๐ป |
| colorFrom: purple |
| colorTo: red |
| sdk: docker |
| pinned: false |
| --- |
| |
| # โ๏ธ Automated Legal Document Digitization System (ALDDS) |
|
|
|  |
|  |
|  |
|  |
|
|
| Upload a photo of a legal document (bailable warrant, summon, etc.) and seamlessly convert it into structured JSON data. ALDDS handles the OCR, AI parsing, secure storage, and live dispatcher notifications in a single streamlined pipelineโ**100% locally and offline**. |
|
|
| ## ๐ Pipeline & Architecture |
|
|
| ```text |
| Image Upload โ Cloudinary Hosting โ PaddleOCR โ Local Qwen2.5-1.5B LLM โ MongoDB โ WhatsApp Alert |
| ``` |
|
|
| 1. **OCR Extraction**: Uses **PaddleOCR** to extract raw text from image uploads with high accuracy on complex legal layouts. |
| 2. **AI Parsing**: Leverages a quantized **Local Qwen2.5-1.5B GGUF** model via `llama-cpp-python` to parse the unstructured OCR text into a strict 10-field JSON schema. *Zero API costs, 100% data privacy.* |
| 3. **Secure Storage**: Automatically commits the digital record to a MongoDB database. |
| 4. **Live Dashboard**: A real-time, searchable Police Dashboard built directly into the UI. |
| 5. **Instant Notifications**: Dispatchers can notify Investigating Officers (IOs) instantly via zero-cost WhatsApp `wa.me` links populated from an internal CSV database. |
|
|
| --- |
|
|
| ## ๐ Features |
|
|
| - **100% Offline Local AI**: Uses `llama-cpp-python` to run a highly optimized Qwen2.5-1.5B model directly on CPU. No external API keys (like OpenAI or NVIDIA) are needed, guaranteeing zero data leaks and no per-request costs. |
| - **HF Free Tier Optimized**: Specifically configured (non-streaming, 1.5B model, capped threads) to run quickly on Hugging Face's free 2 vCPU tier without timing out. |
| - **Auto-Healing OCR**: Includes an automated fix that detects and downgrades broken PaddlePaddle 3.x versions to the stable v2.6.2 runtime during startup, preventing CPU crashes. |
| - **๐ฎ Live Police Dashboard**: A dedicated tab for station dispatchers to monitor incoming warrants. Includes a real-time MongoDB search filter (by Case No, IO Name, Station, etc.). |
| - **๐ฌ WhatsApp Integration**: Zero-API-cost notifications. Selecting an officer from the dropdown dynamically pulls their phone number from `officers.csv` and opens a pre-filled WhatsApp window for the dispatcher to send manually. |
| - **Strict Hallucination Guard**: Custom Python post-processing runs regex checks to ensure the LLM didn't fabricate names, dates, or case numbers that aren't explicitly in the OCR text. |
|
|
| --- |
|
|
| ## ๐ Environment Setup |
|
|
| To run ALDDS locally or in the cloud, you only need the following API keys configured in a `.env` file (or as Secrets on Hugging Face). **No LLM API key is required.** |
|
|
| ```env |
| # Cloudinary (Image Hosting) |
| CLOUDINARY_CLOUD_NAME=your_cloud_name |
| CLOUDINARY_API_KEY=your_api_key |
| CLOUDINARY_API_SECRET=your_api_secret |
| |
| # MongoDB (Database) |
| MONGODB_URI=mongodb+srv://username:password@cluster0.../?retryWrites=true&w=majority |
| ``` |
|
|
| | Variable | Where to get it | |
| |---|---| |
| | `CLOUDINARY_*` | [Cloudinary Console](https://console.cloudinary.com/) โ Dashboard | |
| | `MONGODB_URI` | [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) โ Database โ Connect | |
|
|
| --- |
|
|
| ## ๐ป Local Installation Guide |
|
|
| ALDDS handles all OCR and AI natively in Python. You do **not** need to install Tesseract or any system-level C++ compilers. |
|
|
| ```bash |
| # 1. Clone repository |
| git clone https://huggingface.co/spaces/LovnishVerma/ALDDS |
| cd ALDDS |
| |
| # 2. Install Dependencies |
| pip install -r requirements.txt |
| |
| # 3. Run the Server |
| python app.py |
| ``` |
| The interface will launch at **http://127.0.0.1:7860**. |
|
|
| > **Note:** The first launch automatically downloads the Qwen2.5-1.5B GGUF model (~1.1 GB) and the PaddleOCR weights. Subsequent launches will use the cached files. |
|
|
| --- |
|
|
| ## โ๏ธ Hugging Face Spaces Deployment |
|
|
| If you are deploying ALDDS to Hugging Face Spaces, follow these steps: |
|
|
| 1. **Set Up Secrets**: Go to your Space **Settings** โ **Variables and secrets**. Add `CLOUDINARY_CLOUD_NAME`, `CLOUDINARY_API_KEY`, `CLOUDINARY_API_SECRET`, and `MONGODB_URI`. |
| 2. **Ensure `officers.csv`**: Upload your `officers.csv` file (with `Officer_Name` and `Phone_Number` columns) to the root of the repository. |
| 3. **Restart**: Always click **Factory Rebuild** or **Restart Space** after adding Secrets so the new environment variables are loaded into the container. |
|
|
| --- |
|
|
| ## ๐ Extracted JSON Schema |
|
|
| The LLM is strictly prompted to extract the following fields. If a field cannot be explicitly found in the text, it defaults to `null`. |
|
|
| | JSON Key | Description | |
| |---|---| |
| | `Case_FIR_Number` | FIR or court case reference number | |
| | `Act_and_Sections` | Applicable IPC/CRPC legal acts and sections | |
| | `Type_of_Document` | Warrant, summon, notice, etc. | |
| | `Target_Police_Station` | Police station the document is addressed to | |
| | `IO_Name_and_Belt_No` | Investigating Officer's name and belt number | |
| | `IO_Mobile_Number` | IO's contact number | |
| | `Person_Name_To_Serve` | Name of the person to be served/arrested | |
| | `Person_Address` | Address of the target person | |
| | `Court_Name` | Issuing court name | |
| | `Hearing_Date` | Scheduled hearing or appearance date (DD-MM-YYYY) | |
|
|
| --- |
|
|
| *Built to streamline station workflows, eliminate manual data entry, and instantly notify field officersโall while keeping sensitive legal data entirely offline and private.* |
|
|