Update README.md
Browse files
README.md
CHANGED
|
@@ -10,121 +10,130 @@ app_file: app.py
|
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# โ๏ธ Automated Legal Document Digitization System
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
Image Upload โ Cloudinary Hosting โ Tesseract OCR โ NVIDIA Qwen 2.5 LLM โ Structured JSON
|
| 21 |
-
```
|
| 22 |
-
|
| 23 |
-
---
|
| 24 |
-
|
| 25 |
-
## Prerequisites
|
| 26 |
-
|
| 27 |
-
### 1. Install Tesseract OCR (System Binary)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
#### Windows
|
| 32 |
-
1. Download the installer from: https://github.com/UB-Mannheim/tesseract/wiki
|
| 33 |
-
2. Run the installer (default path: `C:\Program Files\Tesseract-OCR\`)
|
| 34 |
-
3. **Add to PATH** or uncomment the line in `app.py`:
|
| 35 |
-
```python
|
| 36 |
-
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
|
| 37 |
-
```
|
| 38 |
-
|
| 39 |
-
#### Linux (Debian / Ubuntu)
|
| 40 |
-
```bash
|
| 41 |
-
sudo apt-get update
|
| 42 |
-
sudo apt-get install tesseract-ocr
|
| 43 |
```
|
| 44 |
|
| 45 |
-
|
| 46 |
-
``
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
### 2. Verify Tesseract
|
| 51 |
-
```bash
|
| 52 |
-
tesseract --version
|
| 53 |
-
```
|
| 54 |
|
| 55 |
---
|
| 56 |
|
| 57 |
-
##
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
cd police
|
| 63 |
-
pip install -r requirements.txt
|
| 64 |
-
```
|
| 65 |
|
| 66 |
-
##
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
```env
|
| 71 |
-
# Cloudinary
|
| 72 |
CLOUDINARY_CLOUD_NAME=your_cloud_name
|
| 73 |
CLOUDINARY_API_KEY=your_api_key
|
| 74 |
CLOUDINARY_API_SECRET=your_api_secret
|
| 75 |
|
| 76 |
-
# NVIDIA API
|
| 77 |
NVIDIA_API_KEY=your_nvidia_api_key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
```
|
| 79 |
|
| 80 |
| Variable | Where to get it |
|
| 81 |
|---|---|
|
| 82 |
| `CLOUDINARY_*` | [Cloudinary Console](https://console.cloudinary.com/) โ Dashboard |
|
| 83 |
| `NVIDIA_API_KEY` | [NVIDIA Build](https://build.nvidia.com/) โ API Catalog โ Get API Key |
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
python app.py
|
| 89 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
---
|
| 94 |
|
| 95 |
-
##
|
| 96 |
|
| 97 |
-
The LLM
|
| 98 |
|
| 99 |
-
| Key | Description |
|
| 100 |
|---|---|
|
| 101 |
-
| `Case_FIR_Number` | FIR or case reference number |
|
| 102 |
-
| `Act_and_Sections` | Applicable legal acts and sections |
|
| 103 |
| `Type_of_Document` | Warrant, summon, notice, etc. |
|
| 104 |
| `Target_Police_Station` | Police station the document is addressed to |
|
| 105 |
| `IO_Name_and_Belt_No` | Investigating Officer's name and belt number |
|
| 106 |
| `IO_Mobile_Number` | IO's contact number |
|
| 107 |
-
| `Person_Name_To_Serve` | Name of the person to be served |
|
| 108 |
-
| `Person_Address` | Address of the person |
|
| 109 |
| `Court_Name` | Issuing court name |
|
| 110 |
-
| `Hearing_Date` | Scheduled hearing
|
| 111 |
|
| 112 |
---
|
| 113 |
-
|
| 114 |
-
## Project Structure
|
| 115 |
-
|
| 116 |
-
```
|
| 117 |
-
police/
|
| 118 |
-
โโโ app.py # Main application (single file)
|
| 119 |
-
โโโ requirements.txt # Python dependencies
|
| 120 |
-
โโโ .env # API keys (DO NOT commit)
|
| 121 |
-
โโโ README.md # This file
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
---
|
| 125 |
-
|
| 126 |
-
## Notes
|
| 127 |
-
|
| 128 |
-
- OCR accuracy depends on image quality. Clear, well-lit photos produce the best results.
|
| 129 |
-
- The LLM sets fields to `null` when they can't be extracted from the OCR text.
|
| 130 |
-
- All uploaded images are stored in the `warrants/` folder on your Cloudinary account.
|
|
|
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# โ๏ธ Automated Legal Document Digitization System (ALDDS)
|
| 14 |
|
| 15 |
+

|
| 16 |
+

|
| 17 |
+

|
| 18 |
+

|
| 19 |
|
| 20 |
+
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.
|
| 21 |
|
| 22 |
+
## ๐ Pipeline & Architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
```text
|
| 25 |
+
Image Upload โ Cloudinary Hosting โ Tesseract OCR โ NVIDIA LLMs โ MongoDB โ Telegram IO Alert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
```
|
| 27 |
|
| 28 |
+
1. **OCR Extraction**: Uses Tesseract to extract raw text from image uploads.
|
| 29 |
+
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.
|
| 30 |
+
3. **Secure Storage**: Automatically commits the digital record to a MongoDB database.
|
| 31 |
+
4. **Live Dashboard**: A real-time, searchable Police Dashboard built directly into the UI.
|
| 32 |
+
5. **Instant Notifications**: Dispatchers can ping Investigating Officers (IOs) via Telegram with the parsed data using a secure Frontend JavaScript bypass.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
---
|
| 35 |
|
| 36 |
+
## ๐ Features
|
| 37 |
|
| 38 |
+
- **Multi-Model Fallback**: The app cycles through a priority list of NVIDIA LLMs ensuring maximum uptime and reliability during the parsing phase.
|
| 39 |
+
- **๐ฎ 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.).
|
| 40 |
+
- **๐จ Frontend JS Telegram Alerts**: Send an automated markdown summary and document link to an IO via Telegram. The request executes directly in the browser using JavaScript to bypass restrictive institutional or cloud IP firewalls (like Hugging Face).
|
| 41 |
|
| 42 |
+
---
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
## ๐ Environment Setup
|
| 45 |
|
| 46 |
+
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).
|
| 47 |
|
| 48 |
```env
|
| 49 |
+
# Cloudinary (Image Hosting)
|
| 50 |
CLOUDINARY_CLOUD_NAME=your_cloud_name
|
| 51 |
CLOUDINARY_API_KEY=your_api_key
|
| 52 |
CLOUDINARY_API_SECRET=your_api_secret
|
| 53 |
|
| 54 |
+
# NVIDIA API (LLM Parsing)
|
| 55 |
NVIDIA_API_KEY=your_nvidia_api_key
|
| 56 |
+
|
| 57 |
+
# MongoDB (Database)
|
| 58 |
+
MONGODB_URI=mongodb+srv://username:password@cluster0.../?retryWrites=true&w=majority
|
| 59 |
+
|
| 60 |
+
# Telegram (IO Notifications)
|
| 61 |
+
TELEGRAM_BOT_TOKEN=your_bot_token_here
|
| 62 |
```
|
| 63 |
|
| 64 |
| Variable | Where to get it |
|
| 65 |
|---|---|
|
| 66 |
| `CLOUDINARY_*` | [Cloudinary Console](https://console.cloudinary.com/) โ Dashboard |
|
| 67 |
| `NVIDIA_API_KEY` | [NVIDIA Build](https://build.nvidia.com/) โ API Catalog โ Get API Key |
|
| 68 |
+
| `MONGODB_URI` | [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) โ Database โ Connect |
|
| 69 |
+
| `TELEGRAM_BOT_TOKEN` | [Telegram](https://core.telegram.org/bots) โ @BotFather |
|
| 70 |
|
| 71 |
+
---
|
| 72 |
+
|
| 73 |
+
## ๐ป Local Installation Guide
|
| 74 |
|
| 75 |
+
### 1. Install Tesseract OCR (System Binary)
|
| 76 |
+
Python's `pytesseract` requires the underlying Tesseract engine to be installed on your OS.
|
| 77 |
+
|
| 78 |
+
**Windows**
|
| 79 |
+
1. Download installer from: https://github.com/UB-Mannheim/tesseract/wiki
|
| 80 |
+
2. Run installer (default path: `C:\Program Files\Tesseract-OCR\`)
|
| 81 |
+
3. The app is hardcoded to look for this path on Windows.
|
| 82 |
+
|
| 83 |
+
**Linux (Debian/Ubuntu)**
|
| 84 |
+
```bash
|
| 85 |
+
sudo apt-get update
|
| 86 |
+
sudo apt-get install tesseract-ocr
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
**macOS**
|
| 90 |
```bash
|
| 91 |
+
brew install tesseract
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### 2. Run the App
|
| 95 |
+
```bash
|
| 96 |
+
# Clone repository
|
| 97 |
+
git clone https://huggingface.co/spaces/LovnishVerma/ALDDS
|
| 98 |
+
cd ALDDS
|
| 99 |
+
|
| 100 |
+
# Install Dependencies
|
| 101 |
+
pip install -r requirements.txt
|
| 102 |
+
|
| 103 |
+
# Run the Server
|
| 104 |
python app.py
|
| 105 |
```
|
| 106 |
+
The interface will launch at **http://127.0.0.1:7860**.
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## โ๏ธ Hugging Face Spaces Deployment
|
| 111 |
|
| 112 |
+
If you are deploying ALDDS to Hugging Face Spaces, follow these critical steps:
|
| 113 |
+
|
| 114 |
+
1. **Set Up Secrets**: Go to your Space **Settings** -> **Variables and secrets**. Add all variables from your `.env` file as **Secrets**.
|
| 115 |
+
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.
|
| 116 |
+
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.
|
| 117 |
+
4. **Restart**: Always click **Restart Space** after adding or modifying Secrets so the new environment variables are loaded into the container.
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
+
## ๐ Extracted JSON Schema
|
| 122 |
|
| 123 |
+
The LLM is strictly prompted to extract the following fields. If a field cannot be found, it defaults to `null`.
|
| 124 |
|
| 125 |
+
| JSON Key | Description |
|
| 126 |
|---|---|
|
| 127 |
+
| `Case_FIR_Number` | FIR or court case reference number |
|
| 128 |
+
| `Act_and_Sections` | Applicable IPC/CRPC legal acts and sections |
|
| 129 |
| `Type_of_Document` | Warrant, summon, notice, etc. |
|
| 130 |
| `Target_Police_Station` | Police station the document is addressed to |
|
| 131 |
| `IO_Name_and_Belt_No` | Investigating Officer's name and belt number |
|
| 132 |
| `IO_Mobile_Number` | IO's contact number |
|
| 133 |
+
| `Person_Name_To_Serve` | Name of the person to be served/arrested |
|
| 134 |
+
| `Person_Address` | Address of the target person |
|
| 135 |
| `Court_Name` | Issuing court name |
|
| 136 |
+
| `Hearing_Date` | Scheduled hearing or appearance date (DD-MM-YYYY) |
|
| 137 |
|
| 138 |
---
|
| 139 |
+
*Built to streamline station workflows, eliminate manual data entry, and instantly notify field officers.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|