Spaces:
Sleeping
Sleeping
Commit Β·
4bb1ecf
1
Parent(s): 05b69f8
Some Changes to Documentation
Browse files
LICENSE
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Spandan Mukherjee
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
| 22 |
+
|
| 23 |
+
----------------------------------------------------------------------------
|
| 24 |
+
Third-party data and model notices
|
| 25 |
+
----------------------------------------------------------------------------
|
| 26 |
+
|
| 27 |
+
This repository may include or reference the following third-party assets.
|
| 28 |
+
The MIT license above applies only to BankShield/DocSentry source code; the
|
| 29 |
+
following assets are governed by their own terms:
|
| 30 |
+
|
| 31 |
+
- AgamiAI Indian Bank Statements (Hugging Face) - Apache License 2.0
|
| 32 |
+
https://huggingface.co/datasets/AgamiAI/Indian-Bank-Statements
|
| 33 |
+
|
| 34 |
+
- IDRBT Cheque Image Dataset - Research-use license; citation required.
|
| 35 |
+
https://www.idrbt.ac.in/idrbt-cheque-image-dataset/
|
| 36 |
+
When using IDRBT data, cite the IDRBT paper as required by their terms.
|
| 37 |
+
|
| 38 |
+
- CASIA v2 image tampering dataset (referenced for optional CNN training) -
|
| 39 |
+
research use; see dataset page for terms.
|
| 40 |
+
|
| 41 |
+
- MobileNetV2 architecture / ImageNet pretrained weights (TensorFlow/Keras) -
|
| 42 |
+
Apache License 2.0.
|
| 43 |
+
|
| 44 |
+
- ReportLab, OpenCV, PyMuPDF, Pillow, scikit-learn, Streamlit and other
|
| 45 |
+
dependencies are governed by their respective open-source licenses (see
|
| 46 |
+
each project's repo).
|
| 47 |
+
|
| 48 |
+
Users redistributing this software or any derivative must preserve these
|
| 49 |
+
notices and comply with the upstream licenses of the data and models they
|
| 50 |
+
choose to bundle.
|
README.md
CHANGED
|
@@ -1,103 +1,269 @@
|
|
| 1 |
-
# DocSentry
|
| 2 |
|
| 3 |
-
|
| 4 |
-
[](https://www.python.org)
|
| 5 |
-
[](https://opensource.org/licenses/MIT)
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
##
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|---|---|
|
| 28 |
-
|
|
| 29 |
-
|
|
| 30 |
-
|
|
| 31 |
-
|
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
```
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
-
Each detector outputs a sub-score in [0, 1].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
-
|
| 50 |
-
-
|
| 51 |
-
-
|
| 52 |
-
-
|
| 53 |
-
- **PDF consumer-tool fingerprints** β iLovePDF, Smallpdf, PDFescape, Sejda producer flags
|
| 54 |
-
- **Inconsistent fonts** β embedded-font count anomaly
|
| 55 |
-
- **Date sequence violations** β monotonic check on extracted dates
|
| 56 |
-
- **Round-number anomalies** β suspicious mega-amounts
|
| 57 |
-
- **Missing IFSC with present account number** β bank-document validity rule
|
| 58 |
-
- **Cross-document identity mismatches** β name/DOB/address fuzzy match across 2+ docs
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
```bash
|
| 63 |
-
git clone https://github.com/
|
| 64 |
-
cd
|
| 65 |
pip install -r requirements.txt
|
| 66 |
streamlit run app.py
|
| 67 |
```
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
##
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
- [RUN_APP.md](RUN_APP.md) β Local run guide + demo flow
|
| 79 |
-
- [DATASETS.md](DATASETS.md) β Public datasets (CASIA v2, MICC-F220, CoMoFoD, etc.) with download instructions
|
| 80 |
-
- [COLAB_QUICKSTART.md](COLAB_QUICKSTART.md) β Google Colab usage
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
##
|
| 99 |
|
| 100 |
-
-
|
| 101 |
-
-
|
| 102 |
-
-
|
| 103 |
-
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# DocSentry
|
| 2 |
|
| 3 |
+
Document forensics and KYC compliance pipeline for bank underwriting workflows. Detects tampering and forgery in land records, legal documents, financial statements, and cheques. Validates KYC fields against RBI rules. Produces explainable risk scores and regulator-ready audit reports.
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
100% open-source. No paid APIs. No LLM calls. CPU-only by default.
|
| 6 |
|
| 7 |
+
---
|
| 8 |
|
| 9 |
+
## Repository layout
|
| 10 |
|
| 11 |
+
```
|
| 12 |
+
Doc-Sentry/
|
| 13 |
+
βββ app.py Streamlit web UI (4 tabs)
|
| 14 |
+
βββ forensics.py Core detection engine
|
| 15 |
+
βββ audit_report.py Bank-letterhead PDF report builder
|
| 16 |
+
βββ compliance.py KYC validators, PII redaction, RBI report builder
|
| 17 |
+
βββ docsentry_master.ipynb Single source-of-truth Jupyter notebook
|
| 18 |
+
β
|
| 19 |
+
βββ requirements.txt Python dependencies
|
| 20 |
+
βββ packages.txt System packages (Tesseract) for Streamlit Cloud
|
| 21 |
+
βββ .streamlit/config.toml Streamlit theme + server config
|
| 22 |
+
β
|
| 23 |
+
βββ sample_data/ 26 demo files for the live app
|
| 24 |
+
β βββ originals/ 12 genuine documents
|
| 25 |
+
β βββ tampered/ 12 tampered documents
|
| 26 |
+
β βββ pdfs/ 2 PDFs (1 genuine, 1 tampered)
|
| 27 |
+
β
|
| 28 |
+
βββ models/ Trained model artefacts
|
| 29 |
+
β βββ forgery_rf.joblib Random Forest classifier
|
| 30 |
+
β
|
| 31 |
+
βββ README.md DEPLOY.md RUN_APP.md DATASETS.md PUSH.md LICENSE
|
| 32 |
+
βββ data/ (gitignored) full training data + downloaded datasets
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## Module reference
|
| 38 |
|
| 39 |
+
### `forensics.py` β detection engine
|
| 40 |
|
| 41 |
+
The core analytical module. Stateless functions; all logic is independently testable.
|
| 42 |
|
| 43 |
+
| Function | Returns | Description |
|
| 44 |
+
|---|---|---|
|
| 45 |
+
| `analyse_document(path)` | dict | End-to-end pipeline. Auto-detects type (image vs PDF), runs all relevant detectors, blends Random Forest + CNN predictions when available. Primary entry point. |
|
| 46 |
+
| `score_image(path)` | (float, dict, list) | Composite forensic score for an image. Returns total, sub-scores by detector, and EXIF flags. |
|
| 47 |
+
| `error_level_analysis(path, quality=90)` | (PIL.Image, float) | ELA visualisation + scalar suspicion score. Re-saves at given JPEG quality; tampered regions diverge from the rest of the image. |
|
| 48 |
+
| `copy_move_detect(path)` | (np.ndarray, int, list) | Detects regions duplicated within the same image using ORB keypoint matching. Returns annotated visualisation, match count, and raw matches. |
|
| 49 |
+
| `noise_inconsistency(path, block=32)` | (np.ndarray, float) | Per-block Laplacian variance. Returns a heatmap of outlier blocks and a normalised ratio. Useful for splicing detection. |
|
| 50 |
+
| `exif_sanity(path)` | list of str | EXIF metadata audit. Flags missing EXIF, photo-editor signatures (Photoshop/GIMP/Snapseed), and timestamp inconsistencies. |
|
| 51 |
+
| `pdf_structural_audit(path)` | dict | Counts `%%EOF` markers (incremental edits), compares producer vs creator, flags consumer-tool fingerprints (iLovePDF, Smallpdf, etc.). |
|
| 52 |
+
| `pdf_font_audit(path)` | dict | Lists embedded fonts and flags unusually high font counts (a signal of inserted text). |
|
| 53 |
+
| `ocr_text(path)` | str | Tesseract OCR with auto-fallback. Returns empty string if Tesseract isn't installed. |
|
| 54 |
+
| `text_rule_checks(text)` | dict | Validates date monotonicity, amount sanity, IFSC format, account number patterns. |
|
| 55 |
+
| `extract_features(path)` | dict | Feature vector for the Random Forest: 11 features (ELA, copy-move count, noise ratio, EXIF flag, 4 GLCM texture features, 3 colour histogram entropies). |
|
| 56 |
+
| `predict_with_model(path)` | dict or None | Loads `models/forgery_rf.joblib` and returns tamper probability + verdict. None if model isn't present. |
|
| 57 |
+
| `predict_with_cnn(path)` | dict or None | Lazy-loads `models/forgery_cnn.keras` (TensorFlow). None if model isn't present, so the app starts fast without TF. |
|
| 58 |
+
| `extract_identity_fields(path)` | (dict, str) | Pulls name, DOB, address, account number, IFSC, and amounts from any document. |
|
| 59 |
+
| `cross_doc_consistency(paths)` | dict | Compares identity fields across 2+ documents using `difflib.SequenceMatcher`. Returns per-field match status and an aggregate consistency risk. |
|
| 60 |
+
| `generate_insights(score, sub, flags)` | dict | Converts numeric sub-scores into underwriter-readable bullets, risk band, and recommended action. |
|
| 61 |
+
| `band(score)` | str | Maps a float to LOW / MEDIUM / HIGH / CRITICAL. Boundaries at 0.25, 0.50, 0.75. |
|
| 62 |
|
| 63 |
+
Constants of interest: `WEIGHTS`, `INSIGHT_RULES`, `ACTIONS`, `MODEL_PATH`, `CNN_MODEL_PATH`, `TESSERACT_OK`.
|
| 64 |
|
| 65 |
+
### `app.py` β Streamlit UI
|
| 66 |
+
|
| 67 |
+
Four-tab web app. Imports `forensics`, `compliance`, and `audit_report`.
|
| 68 |
+
|
| 69 |
+
| Tab | Function |
|
| 70 |
|---|---|
|
| 71 |
+
| Single-document analysis | Drag-drop or pick a sample; shows risk band, sub-score breakdown, evidence list, ELA / copy-move / noise visualisations, PDF audit details, ML/CNN predictions, downloadable JSON + PDF reports. |
|
| 72 |
+
| Cross-document check | Upload 2β4 documents for one applicant; the system extracts identity fields and shows a coloured comparison table with similarity scores. |
|
| 73 |
+
| Batch audit | Point at a folder; scans every supported file and produces a sortable risk table + CSV. |
|
| 74 |
+
| Compliance & Audit Pack | Three sub-tabs: KYC field validation (manual or doc-extracted), PII auto-redaction (PDF + text), RBI-style compliance report generation. |
|
| 75 |
+
|
| 76 |
+
The sample picker auto-populates from `sample_data/`; useful for the deployed demo where users can't browse the local filesystem.
|
| 77 |
|
| 78 |
+
### `audit_report.py` β bank-letterhead PDF
|
| 79 |
+
|
| 80 |
+
Single public function: `build_pdf_report(report, source_path)` β `bytes`.
|
| 81 |
+
|
| 82 |
+
Generates a multi-page PDF with header letterhead, metadata table, coloured risk-verdict box, sub-score breakdown table (with ASCII bar chart), evidence list, embedded heatmaps for image documents, structural audit details for PDFs, ML model verdict block, and footer disclaimer. Uses ReportLab Platypus.
|
| 83 |
+
|
| 84 |
+
### `compliance.py` β KYC + regulatory
|
| 85 |
+
|
| 86 |
+
| Function | Description |
|
| 87 |
+
|---|---|
|
| 88 |
+
| `validate_ifsc(code)` | Format check (`^[A-Z]{4}0[A-Z0-9]{6}$`) + lookup against an embedded RBI bank-code list (~36 major Indian banks). Returns bank name and branch code on success. |
|
| 89 |
+
| `validate_pan(code)` | Format check (`^[A-Z]{5}\d{4}[A-Z]$`) + entity-type character validation (P=Individual, F=Firm, C=Company, etc.). |
|
| 90 |
+
| `validate_aadhaar(num)` | 12-digit format + UIDAI Verhoeff checksum verification. Aadhaar numbers cannot start with 0 or 1 per UIDAI spec. |
|
| 91 |
+
| `redact_text(text)` | Masks IFSC, PAN, Aadhaar, and account numbers in arbitrary text. |
|
| 92 |
+
| `redact_pdf(input_path, output_path)` | Renders each PDF page, locates PII bounding boxes via `page.search_for`, overlays opaque black rectangles. |
|
| 93 |
+
| `extract_pii_fields(path)` | Pulls all PII candidates from any document (PDF or image via OCR). |
|
| 94 |
+
| `build_compliance_report(forensic_report, source_path, kyc_results)` | Generates a 5-section regulator-ready PDF: document ID + SHA-256, KYC verification table, fraud-screening verdict, recommended RBI risk treatment, auditor sign-off block. References specific RBI Master Directions. |
|
| 95 |
+
|
| 96 |
+
### `docsentry_master.ipynb`
|
| 97 |
+
|
| 98 |
+
Single source of truth. Sections:
|
| 99 |
+
|
| 100 |
+
1. Environment auto-detection (Colab vs local)
|
| 101 |
+
2. Datasets (synthetic generator + Kaggle CASIA v2 hook + manual download references)
|
| 102 |
+
3. Image forensics
|
| 103 |
+
4. PDF forensics
|
| 104 |
+
5. OCR + text rules
|
| 105 |
+
6. Random Forest training + saving
|
| 106 |
+
7. (Optional) CNN training on Colab GPU
|
| 107 |
+
8. End-to-end pipeline
|
| 108 |
+
9. Cross-document consistency
|
| 109 |
+
10. Dashboard + batch audit
|
| 110 |
+
11. PDF report generator
|
| 111 |
+
12. Export cell β writes `forensics.py`, `app.py`, `audit_report.py` to disk for the Streamlit demo
|
| 112 |
+
13. Launch instructions
|
| 113 |
+
|
| 114 |
+
Edit the notebook, re-run section 12, and the `.py` files used by Streamlit regenerate automatically.
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## Pipeline architecture
|
| 119 |
|
| 120 |
```
|
| 121 |
+
ββββββββββββββββββββββββββββ
|
| 122 |
+
β Document (PNG/PDF/JPG) β
|
| 123 |
+
ββββββββββββββ¬ββββββββββββββ
|
| 124 |
+
β
|
| 125 |
+
ββββββββββββββββββββ¬ββββββ΄ββββββ¬βββββββββββββββββββ
|
| 126 |
+
βΌ βΌ βΌ βΌ
|
| 127 |
+
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
|
| 128 |
+
β ELA β β Copy- β β Noise β β EXIF β
|
| 129 |
+
β analysisβ β move β β heatmap β β audit β
|
| 130 |
+
ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ ββββββ¬βββββ
|
| 131 |
+
βββββββββ¬ββββββββββββ΄ββββββββββββ΄βββββββββββ¬βββββββββ
|
| 132 |
+
β (images) β
|
| 133 |
+
β βΌ
|
| 134 |
+
β βββββββββββββββββββββββ
|
| 135 |
+
β β OCR + text rules β
|
| 136 |
+
β β dates Β· IFSC Β· math β
|
| 137 |
+
β ββββββββββββ¬βββββββββββ
|
| 138 |
+
βΌ β
|
| 139 |
+
ββββββββββββββββββββββββββββββ β
|
| 140 |
+
β Feature vector (11-dim) β β
|
| 141 |
+
ββββββββββββββββ¬ββββββββββββββ β
|
| 142 |
+
βΌ β
|
| 143 |
+
ββββββββββββββββββββββββββββββ β
|
| 144 |
+
β Random Forest classifier β β
|
| 145 |
+
β (forgery_rf.joblib) β β
|
| 146 |
+
ββββββββββββββββ¬ββββββββββββββ β
|
| 147 |
+
β β
|
| 148 |
+
βΌ β
|
| 149 |
+
ββββββββββββββββββββββββββββββ β
|
| 150 |
+
β (Optional) CNN inference β β
|
| 151 |
+
β MobileNetV2 fine-tuned β β
|
| 152 |
+
β (forgery_cnn.keras) β β
|
| 153 |
+
ββββββββββββββββ¬ββββββββββββββ β
|
| 154 |
+
β β
|
| 155 |
+
ββββββββββββββββ¬ββββββββββββββββββ
|
| 156 |
+
βΌ
|
| 157 |
+
ββββββββββββββββββββββββββββββββ
|
| 158 |
+
β Weighted ensemble scorer β
|
| 159 |
+
β (rule + RF + CNN blend) β
|
| 160 |
+
ββββββββββββββββ¬ββββββββββββββββ
|
| 161 |
+
βΌ
|
| 162 |
+
ββββββββββββββββββββββββββββββββ
|
| 163 |
+
β Risk band + Evidence list β
|
| 164 |
+
β Recommended action β
|
| 165 |
+
β Audit JSON + PDF report β
|
| 166 |
+
ββββββββββββββββββββββββββββββββ
|
| 167 |
```
|
| 168 |
|
| 169 |
+
Each detector outputs a sub-score in `[0, 1]`. The default weight vector (in `forensics.WEIGHTS`) is `{ela: 0.20, copy_move: 0.25, noise: 0.15, exif: 0.10, pdf_struct: 0.15, text_rules: 0.10, math: 0.05}`. The Random Forest probability, when available, is blended 50/50 with the rule-based score. The CNN probability, when available, is blended at a weight between 0.4 and 0.7 depending on the CNN's reported validation AUC.
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
## Detection coverage
|
| 174 |
|
| 175 |
+
**Image tampering**
|
| 176 |
+
- Copy-move forgery β ORB keypoint matching with distance filter
|
| 177 |
+
- Image splicing β block-wise noise inconsistency via Laplacian variance
|
| 178 |
+
- Text edits / amount tampering β Error Level Analysis
|
| 179 |
+
- Photoshop / GIMP / Snapseed edits β EXIF Software-tag string match
|
| 180 |
+
- Timestamp inconsistencies β DateTime vs DateTimeOriginal comparison
|
| 181 |
|
| 182 |
+
**PDF tampering**
|
| 183 |
+
- Incremental edits β multi-`%%EOF` marker counting
|
| 184 |
+
- Consumer-tool fingerprints β iLovePDF, Smallpdf, PDFescape, Sejda, Foxit Phantom strings in producer/creator
|
| 185 |
+
- Producer/Creator mismatch β flags re-processed PDFs
|
| 186 |
+
- Inserted text β embedded font count anomalies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
**Text-level**
|
| 189 |
+
- Date sequence violations β monotonic check on extracted dates
|
| 190 |
+
- Round-number anomalies β counts mega-amounts that are multiples of βΉ1 lakh
|
| 191 |
+
- Missing IFSC with account number present β invalid bank document
|
| 192 |
+
|
| 193 |
+
**Cross-document**
|
| 194 |
+
- Name / DOB / address fuzzy match across multiple documents
|
| 195 |
+
- Per-field similarity scoring with green/yellow/red status
|
| 196 |
+
|
| 197 |
+
**KYC validation**
|
| 198 |
+
- IFSC: format + RBI bank-code list (36 banks)
|
| 199 |
+
- PAN: format + entity-type character (10 types per income-tax dept spec)
|
| 200 |
+
- Aadhaar: 12-digit format + UIDAI Verhoeff checksum
|
| 201 |
+
|
| 202 |
+
**PII redaction**
|
| 203 |
+
- Aadhaar, PAN, IFSC, account-number masking
|
| 204 |
+
- PDF redaction with black rectangle overlays via `page.search_for` bounding boxes
|
| 205 |
+
|
| 206 |
+
---
|
| 207 |
+
|
| 208 |
+
## Running locally
|
| 209 |
|
| 210 |
```bash
|
| 211 |
+
git clone https://github.com/SpandanM110/Doc-Sentry.git
|
| 212 |
+
cd Doc-Sentry
|
| 213 |
pip install -r requirements.txt
|
| 214 |
streamlit run app.py
|
| 215 |
```
|
| 216 |
|
| 217 |
+
Browser opens at `http://localhost:8501`.
|
| 218 |
+
|
| 219 |
+
For full OCR text-rule support, install Tesseract OCR:
|
| 220 |
+
- Windows: https://github.com/UB-Mannheim/tesseract/wiki
|
| 221 |
+
- macOS: `brew install tesseract`
|
| 222 |
+
- Linux: `sudo apt-get install tesseract-ocr`
|
| 223 |
+
|
| 224 |
+
The app auto-detects Tesseract on standard Windows install paths; no environment variable required.
|
| 225 |
+
|
| 226 |
+
See `RUN_APP.md` for a more detailed walkthrough.
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## Deployment
|
| 231 |
+
|
| 232 |
+
Push to GitHub, connect at https://share.streamlit.io, point at `app.py`, deploy. The `packages.txt` ensures Tesseract is installed on the Streamlit Cloud VM; `requirements.txt` covers Python dependencies.
|
| 233 |
+
|
| 234 |
+
See `DEPLOY.md` for step-by-step instructions including troubleshooting.
|
| 235 |
+
|
| 236 |
+
---
|
| 237 |
|
| 238 |
+
## Training your own model
|
| 239 |
|
| 240 |
+
Drop labelled data into `data/images/originals/` and `data/images/tampered/`, open `docsentry_master.ipynb`, run section 6. A Random Forest auto-trains on whatever you put there and saves to `models/forgery_rf.joblib`. The Streamlit app picks it up automatically on next restart β no code changes.
|
| 241 |
|
| 242 |
+
For a CNN upgrade, set `TRAIN_CNN = True` in section 7 and run on a Colab T4 GPU (free tier). Saves `models/forgery_cnn.keras` + `models/forgery_cnn.meta.json`. The app loads this lazily on first request.
|
| 243 |
|
| 244 |
+
See `DATASETS.md` for public datasets you can use.
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
---
|
| 247 |
|
| 248 |
+
## Dependencies
|
| 249 |
|
| 250 |
+
OpenCV (cv2), Pillow (PIL), scikit-image, scikit-learn, joblib, PyMuPDF (fitz), pdfplumber, pikepdf, pytesseract, python-dateutil, Streamlit, ReportLab, NumPy, pandas, matplotlib. Optional: TensorFlow (only required for the CNN path).
|
| 251 |
|
| 252 |
+
All pip-installable. No GPU required for the default pipeline.
|
| 253 |
|
| 254 |
+
---
|
| 255 |
|
| 256 |
+
## License
|
| 257 |
|
| 258 |
+
MIT β see `LICENSE`. The MIT license covers the source code in this repository. Third-party datasets and pretrained models bundled or referenced (CASIA v2, IDRBT cheque dataset, AgamiAI Indian Bank Statements, MobileNetV2 ImageNet weights, etc.) are governed by their own terms; those notices are reproduced in `LICENSE` below the MIT block.
|
| 259 |
|
| 260 |
+
---
|
| 261 |
|
| 262 |
+
## Acknowledgements
|
| 263 |
|
| 264 |
+
- **AgamiAI Indian Bank Statements** (Hugging Face) β Apache 2.0
|
| 265 |
+
- **IDRBT Cheque Image Dataset** β Institute for Development and Research in Banking Technology, India
|
| 266 |
+
- **CASIA v2** image tampering dataset β Chinese Academy of Sciences
|
| 267 |
+
- **MICC-F220** copy-move benchmark β University of Florence
|
| 268 |
+
- **CoMoFoD** dataset β University of Zagreb
|
| 269 |
+
- **Tobacco-3482** document corpus β University of Maryland
|