--- title: ALDDS emoji: 💻 colorFrom: indigo colorTo: red sdk: gradio sdk_version: 6.14.0 python_version: '3.13' app_file: app.py pinned: false --- # ⚖️ Automated Legal Document Digitization System (ALDDS) ![Python](https://img.shields.io/badge/Python-3.13-blue.svg) ![Gradio](https://img.shields.io/badge/Gradio-6.14.0-orange.svg) ![MongoDB](https://img.shields.io/badge/MongoDB-Atlas-green.svg) ![Hugging Face](https://img.shields.io/badge/Deploy-Hugging%20Face-yellow.svg) 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. ## 🚀 Pipeline & Architecture ```text Image Upload → Cloudinary Hosting → Tesseract OCR → NVIDIA LLMs → MongoDB → WhatsApp Alert ``` 1. **OCR Extraction**: Uses Tesseract to extract raw text from image uploads. 2. **AI Parsing**: Leverages advanced NVIDIA models (`qwen/qwen3-coder-480b-a35b-instruct`, Llama 3) to parse the unstructured OCR text into a strict 10-field JSON schema. 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 - **Multi-Model Fallback**: The app cycles through a priority list of NVIDIA LLMs ensuring maximum uptime and reliability during the parsing phase. - **👮 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. --- ## 🔑 Environment Setup To run ALDDS locally or in the cloud, you need the following API keys configured in a `.env` file (or as Secrets on Hugging Face). ```env # Cloudinary (Image Hosting) CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret # NVIDIA API (LLM Parsing) NVIDIA_API_KEY=your_nvidia_api_key # 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 | | `NVIDIA_API_KEY` | [NVIDIA Build](https://build.nvidia.com/) → API Catalog → Get API Key | | `MONGODB_URI` | [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) → Database → Connect | --- ## 💻 Local Installation Guide ### 1. Install Tesseract OCR (System Binary) Python's `pytesseract` requires the underlying Tesseract engine to be installed on your OS. **Windows** 1. Download installer from: https://github.com/UB-Mannheim/tesseract/wiki 2. Run installer (default path: `C:\Program Files\Tesseract-OCR\`) 3. The app is hardcoded to look for this path on Windows. **Linux (Debian/Ubuntu)** ```bash sudo apt-get update sudo apt-get install tesseract-ocr ``` **macOS** ```bash brew install tesseract ``` ### 2. Run the App ```bash # Clone repository git clone https://huggingface.co/spaces/LovnishVerma/ALDDS cd ALDDS # Install Dependencies pip install -r requirements.txt # Run the Server python app.py ``` The interface will launch at **http://127.0.0.1:7860**. --- ## ☁️ Hugging Face Spaces Deployment If you are deploying ALDDS to Hugging Face Spaces, follow these critical steps: 1. **Set Up Secrets**: Go to your Space **Settings** -> **Variables and secrets**. Add all variables from your `.env` file as **Secrets**. 2. **System Dependencies**: Hugging Face runs Debian Linux. The repository includes a `packages.txt` file telling Hugging Face to install `tesseract-ocr` and `libtesseract-dev` during the Docker build. 3. **CRLF Warning**: Ensure that `packages.txt` is saved with Unix (`LF`) line endings. If it has Windows (`CRLF`) line endings, the Hugging Face Docker build will fail with a `Package not found` error. 4. **Restart**: Always click **Restart Space** after adding or modifying 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 found, 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.*