SpandanM110 commited on
Commit
4bb1ecf
Β·
1 Parent(s): 05b69f8

Some Changes to Documentation

Browse files
Files changed (2) hide show
  1. LICENSE +50 -0
  2. README.md +230 -64
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 - Document Forensics for Bank Underwriting
2
 
3
- [![Built with Streamlit](https://img.shields.io/badge/Built%20with-Streamlit-FF4B4B.svg)](https://streamlit.io)
4
- [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
 
7
- **Real-time anomaly detection for land records, legal documents, and financial statements during loan underwriting.**
8
 
9
- > Detects tampering, edits, and forgery attempts in seconds. Generates explainable risk scores and underwriter-ready audit reports. 100% open-source, no paid APIs, no LLM calls. Runs on a laptop.
10
 
11
- ## :rocket: Live demo
12
 
13
- **Try it now:** [docsentry-yourname.streamlit.app](https://docsentry-yourname.streamlit.app) *(replace with your actual URL after deploying)*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- Pick a tampered land record from the dropdown and watch the forensic verdict appear in real time.
16
 
17
- ## :movie_camera: 3-minute demo flow
18
 
19
- 1. **Single-document analysis** β€” drop a PNG/PDF, see risk band (LOW/MEDIUM/HIGH/CRITICAL), heatmap overlays, evidence bullets
20
- 2. **Cross-document consistency** β€” upload 2-4 documents for the same applicant; system flags mismatches in name/DOB/address
21
- 3. **Batch audit** β€” point at a folder of documents; get a sortable risk table and CSV export
22
- 4. **Audit PDF** β€” one-click download of a bank-letterhead PDF report ready for the underwriting file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- ## :package: What's included
25
 
26
- | Component | What it does |
 
 
 
 
27
  |---|---|
28
- | `forensics.py` | Core detection engine: ELA, copy-move, noise inconsistency, EXIF audit, PDF structure analysis, OCR + text rules, Random Forest ML model loader, cross-document consistency check |
29
- | `app.py` | Streamlit web app with 3 tabs and a sample picker for instant cloud demos |
30
- | `audit_report.py` | ReportLab-based PDF report generator with bank letterhead, risk verdict, evidence, embedded heatmaps |
31
- | `anomaly_detection_banking.ipynb` | Jupyter notebook walking through every detector + how to train your own classifier |
32
- | `sample_data/` | 26 demo documents (12 genuine + 12 tampered + 2 PDFs) ready to play with |
 
33
 
34
- ## :brain: How it works
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  ```
37
- Document ─┬─► Image forensics (ELA, copy-move, noise, EXIF)
38
- ��─► PDF structure (EOF markers, fonts, producer/creator)
39
- β”œβ”€β–Ί OCR + text rules (date monotonicity, math, IFSC validation)
40
- β”œβ”€β–Ί Trained RF model (learned forgery signal blend)
41
- └─► Anomaly Scorer ─► Risk band + Insights + Audit JSON
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ```
43
 
44
- Each detector outputs a sub-score in [0, 1]. A weighted blend produces the final risk score, mapped to one of four bands. The trained Random Forest (when available) is blended 50/50 with the rule-based score. Every flag is explainable β€” no black-box "trust me, it's fraud."
 
 
 
 
45
 
46
- ## :white_check_mark: Detection capabilities
 
 
 
 
 
47
 
48
- - **Copy-move forgery** (duplicate region within image) β€” ORB keypoint matching
49
- - **Image splicing** (region pasted from another source) β€” block-wise noise inconsistency
50
- - **Text edits / amount tampering** β€” Error Level Analysis (ELA)
51
- - **Photoshop / GIMP edits** β€” EXIF software-tag check
52
- - **PDF incremental edits** β€” multi-`%%EOF` marker detection
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
- ## :wrench: Run locally
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  ```bash
63
- git clone https://github.com/YourName/docsentry.git
64
- cd docsentry
65
  pip install -r requirements.txt
66
  streamlit run app.py
67
  ```
68
 
69
- Opens at http://localhost:8501. Install Tesseract OCR separately for full text-rule support (https://github.com/UB-Mannheim/tesseract/wiki on Windows).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- ## :cloud: Deploy your own (free)
72
 
73
- Push to a public GitHub repo, then deploy on [Streamlit Community Cloud](https://share.streamlit.io). Detailed steps in [DEPLOY.md](DEPLOY.md). Takes ~10 minutes end to end.
74
 
75
- ## :books: Documentation
76
 
77
- - [DEPLOY.md](DEPLOY.md) β€” Streamlit Cloud deployment guide
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
- ## :test_tube: Train your own model
83
 
84
- Open `anomaly_detection_banking.ipynb`, drop your data into `data/images/originals/` and `data/images/tampered/`, run Section 7.5. The Random Forest auto-trains on whatever you put there. The app picks up the new `models/forgery_rf.joblib` automatically β€” no code changes.
85
 
86
- For a CNN upgrade, flip `TRAIN_CNN = True` in Section 7.6 and run on Google Colab with a free T4 GPU.
87
 
88
- ## :handshake: Tech stack
89
 
90
- OpenCV - PIL/Pillow - scikit-image - scikit-learn - PyMuPDF - pdfplumber - pikepdf - pytesseract - Streamlit - ReportLab - matplotlib - PyTorch/TensorFlow (optional)
91
 
92
- Everything pip-installable. No GPU required for the default pipeline.
93
 
94
- ## :scroll: License
95
 
96
- MIT. Use it, fork it, ship it. If you build something cool, send a screenshot.
97
 
98
- ## :pray: Acknowledgements
99
 
100
- - CASIA v2 image tampering dataset (Chinese Academy of Sciences)
101
- - MICC-F220 copy-move benchmark (University of Florence)
102
- - CoMoFoD dataset (University of Zagreb)
103
- - Tobacco-3482 document corpus (University of Maryland)
 
 
 
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