kvc-ocr / README.md
WofoAI's picture
Upload 2 files
d8021ae verified
|
Raw
History Blame Contribute Delete
3.61 kB
---
title: KYC OCR (India)
emoji: ๐Ÿ“„
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: "5.0.0"
python_version: "3.12"
app_file: app.py
pinned: false
license: mit
short_description: Extract fields from Indian PAN cards and cheques on CPU
---
# ๐Ÿ‡ฎ๐Ÿ‡ณ KYC Document OCR
A lightweight, CPU-friendly pipeline for extracting structured fields from
Indian KYC documents (PAN card, cheque) from images or PDFs.
Built on [RapidOCR](https://github.com/RapidAI/RapidOCR) โ€” ONNX-runtime
deployment of PaddleOCR PP-OCRv4 models. No GPU needed.
## What it does
- **PDF or image input** (PyMuPDF rasterises PDFs at 300 DPI)
- **Document type auto-detection** via keyword + regex scoring
- **Cheque rotation correction** โ€” detects sideways-scanned cheques (text
spans more vertically than horizontally) and rotates before MICR extraction
- **Format-spec validation** โ€” PAN regex with 4th-character entity-type
lookup, IFSC regex, date normalisation, MICR positional parse
## Supported documents
| Document | Fields extracted |
|---|---|
| **PAN card** | PAN number, name, father's name (individual) / company name, DOB / date of incorporation, entity type (Individual / Company / HUF / Firm / Trust / etc.) |
| **Cheque** | Bank name, branch address, IFSC code, account number, 9-digit MICR code, cheque number, transaction code |
| **Aadhaar** | _Coming soon โ€” recommended path: read the secure QR code via `pyzbar` rather than OCR_ |
| **Passport** | _Coming soon โ€” recommended path: parse the MRZ via `passporteye`_ |
## How to use the Space
1. Drop a PDF or image into the upload box
2. Click **Extract fields**
3. View the structured output and raw OCR (for debugging)
The included example is a synthetic PAN with fake data so you can try it
without uploading real documents.
## Running locally
```bash
git clone <this-space-url>
cd <repo>
pip install -r requirements.txt
python app.py
```
Then open `http://127.0.0.1:7860`.
## Using `kyc_extract.py` directly as a library
```python
from kyc_extract import process, RapidOCR
engine = RapidOCR()
results = process("path/to/document.pdf", engine)
for page in results:
print(page["detected_type"]) # 'pan' or 'cheque'
print(page["fields"]) # structured dict
```
## Privacy
This is a public Space. **Do not upload real personal documents.** For
production KYC pipelines, fork this repo and deploy on your own private
infrastructure (DPDP Act and UIDAI guidelines require it for Aadhaar in
particular).
## Architecture notes
- All extraction is rule-based โ€” no model is hardcoded to specific names,
banks, PANs, or addresses. The same script handles any PAN or any bank's
cheque.
- Document classification uses keyword + regex scoring; if confidence is
low, type is `unknown` and no extractor runs.
- For cheques in portrait-orientation PDFs (common when phones are held
vertically), the pipeline detects the layout anomaly and re-OCRs the
rotated image, merging text from both passes so address and IFSC don't
get lost in the rotation.
## Limitations
- English-only OCR โ€” Hindi label text (`เคจเคพเคฎ/Name`) comes out garbled but
the pipeline has shape-based fallbacks so this doesn't break field
extraction. For full Hindi extraction, add `lang='hi'` to RapidOCR.
- MICR fonts are E-13B and not perfectly read by general OCR. The pipeline
reconstructs the 9-digit MICR from OCR fragments via positional parsing,
which works on most cheques but degrades on poor scans.
- Aadhaar and passport extractors are stubs. The proper approach uses QR
and MRZ respectively, not pure OCR.