NIVARAN bridges the gap between complex bureaucratic/legal documents and the common citizen using a Hybrid AI approach โ combining custom SpaCy NER + deterministic Rule-Based Logic (SQLite) โ to not just read, but AUDIT documents.
- Modules
- Tech Stack
- Project Structure
- Setup & Installation
- Running the App
- API Reference
- Training Custom NER Models
- Privacy & Ethics
Upload government notices (electricity bills, tax letters, bank notices). The system extracts actionable intent and converts it to a simple Hindi audio summary.
- OCR via Gemini 1.5 Flash โ SpaCy NER โ Hindi simplification โ gTTS audio
- High contrast UI with large buttons (min 48px tap targets)
- Hindi number localization: โน500 โ "Paanch Sau Rupaye"
Upload a rental agreement PDF/image. The system scans for predatory or illegal clauses, flags violations of the Model Tenancy Act, 2021, and outputs a Risk Score (0โ10).
- OCR โ NER โ SQLite Rule Engine โ Risk Score (Red/Amber/Green)
- 8 pre-loaded rules covering deposit limits, no-refund traps, lock-in periods, etc.
- Legal citations for every flagged clause
| Layer | Technology |
|---|---|
| Backend | Python 3.9+ / Flask 3.1 / Flask-SocketIO |
| Frontend | React 18 / Vite / React Router |
| NLP Engine | SpaCy 3.8 (custom NER + regex fallback) |
| OCR/Vision | Google Gemini 1.5 Flash API |
| Database | SQLite (raw SQL, no ORM) |
| Text-to-Speech | gTTS (Hindi) |
| Real-time | Flask-SocketIO + Socket.IO client |
Nivaran/
โโโ nivaran-backend/
โ โโโ app.py # Flask + SocketIO entry point
โ โโโ requirements.txt # Python dependencies
โ โโโ .env.example # Environment variables template
โ โโโ routes/
โ โ โโโ civic_ease.py # /api/civic-ease/upload
โ โ โโโ rent_right.py # /api/rent-right/upload
โ โโโ nlp/
โ โ โโโ ocr.py # Gemini 1.5 Flash OCR
โ โ โโโ ner_model.py # SpaCy NER + regex fallback
โ โ โโโ simplifier.py # Hindi simplification + gTTS
โ โโโ rules/
โ โ โโโ rule_engine.py # SQLite rule evaluator
โ โ โโโ schema.sql # Legal rules schema + seed data
โ โโโ scripts/
โ โ โโโ prepare_training_data.py # SpaCy annotation script
โ โโโ models/nivaran_ner/ # Trained SpaCy models (after training)
โ โโโ database/rules.db # SQLite database (auto-created)
โ โโโ temp_audio/ # Temporary audio files (auto-cleaned)
โ
โโโ nivaran-frontend/
โ โโโ package.json
โ โโโ vite.config.js
โ โโโ index.html
โ โโโ src/
โ โโโ main.jsx
โ โโโ App.jsx
โ โโโ index.css # Complete design system
โ โโโ pages/
โ โ โโโ Home.jsx # Landing + module selector
โ โ โโโ CivicEase.jsx # Elderly-friendly upload + audio
โ โ โโโ RentRight.jsx # Rental agreement scanner
โ โโโ components/
โ โ โโโ FileUploader.jsx # Drag-and-drop upload
โ โ โโโ ProgressStream.jsx # Real-time progress bar
โ โ โโโ RiskDial.jsx # Animated risk score dial
โ โ โโโ ClauseCard.jsx # Expandable clause card
โ โ โโโ AudioPlayer.jsx # Hindi audio playback
โ โ โโโ DisclaimerModal.jsx # Legal disclaimer modal
โ โโโ utils/
โ โโโ socket.js # Socket.IO client config
โ
โโโ README.md
- Python 3.9+ with pip
- Node.js 18+ with npm
- Google Gemini API Key โ Get one here
# Navigate to backend directory
cd nivaran-backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Download SpaCy base model
python -m spacy download en_core_web_sm
# Set up environment variables
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY# Navigate to frontend directory
cd nivaran-frontend
# Install dependencies
npm installcd nivaran-backend
source venv/bin/activate
python app.pyThe Flask server starts at http://localhost:5000.
The SQLite database is auto-initialized from schema.sql on first run.
cd nivaran-frontend
npm run devThe React dev server starts at http://localhost:3000. API calls are proxied to the backend via Vite config.
Open http://localhost:3000 in your browser.
GET /api/health
โ { status: "healthy", service: "NIVARAN Backend", version: "1.0.0" }
POST /api/civic-ease/upload
Content-Type: multipart/form-data
Body: document (file), sid (optional Socket.IO ID)
โ {
audio_url: "/audio/nivaran_abc123.mp3",
summary_text: "Namaste. BSES ki taraf se yeh suchna hai...",
extracted_entities: { dates, amounts, organizations, actions },
ocr_text: "...",
confidence: 0.92,
low_confidence_warning: false
}
POST /api/rent-right/upload
Content-Type: multipart/form-data
Body: document (file), sid (optional Socket.IO ID)
โ {
risk_score: 4.5,
risk_level: "AMBER",
flagged_clauses: [{ rule_name, severity, violation_description, legal_citation, ... }],
total_flags: 3,
severity_breakdown: { CRITICAL: 1, HIGH: 1, MEDIUM: 1, LOW: 0 },
extracted_entities: { rent_amount, deposit_amount, ... },
confidence: 0.88,
low_confidence_warning: false
}
Event: "analysis_progress"
Data: { stage, message, percent, module }
The app works out-of-the-box with regex-based fallback extraction. For improved accuracy, train custom SpaCy NER models:
cd nivaran-backend
# 1. Prepare training data
python scripts/prepare_training_data.py
# 2. Generate SpaCy config
python -m spacy init config config.cfg --lang en --pipeline ner --optimize efficiency
# 3. Train civic notice model
python -m spacy train training_data/civic_notice_ner_config.cfg \
--output models/nivaran_ner/civic_notice_ner \
--paths.train training_data/civic_notice_ner_train.spacy \
--paths.dev training_data/civic_notice_ner_train.spacy
# 4. Train rent agreement model
python -m spacy train training_data/rent_agreement_ner_config.cfg \
--output models/nivaran_ner/rent_agreement_ner \
--paths.train training_data/rent_agreement_ner_train.spacy \
--paths.dev training_data/rent_agreement_ner_train.spacyThe trained models are automatically loaded by ner_model.py when placed in the models/nivaran_ner/ directory.
| Principle | Implementation |
|---|---|
| Stateless Processing | Documents are processed in-memory only. Never written to disk permanently. |
| Algorithmic Fairness | Rule engine evaluates clause text only โ no names, gender, or location. |
| Explainability | Every flagged risk cites the specific legal section violated. |
| User Consent | Mandatory disclaimer modal before any analysis begins. |
| Confidence Scoring | Low OCR quality triggers a visible warning to the user. |
| DPDP Act 2023 | Compliant โ no personal data retention. |
| # | Rule Name | Severity | Legal Citation |
|---|---|---|---|
| 1 | Excessive Security Deposit | HIGH | Section 11(2), Model Tenancy Act, 2021 |
| 2 | No-Refund Clause | CRITICAL | Section 11(4), Model Tenancy Act, 2021 |
| 3 | Excessive Lock-in Period | HIGH | Section 21(1), Model Tenancy Act, 2021 |
| 4 | Insufficient Notice Period | MEDIUM | Section 21(2), Model Tenancy Act, 2021 |
| 5 | Unreasonable Penalty Clause | HIGH | Section 21(4), Model Tenancy Act, 2021 |
| 6 | Missing Termination Clause | HIGH | Section 21, Model Tenancy Act, 2021 |
| 7 | Uncapped Rent Escalation | MEDIUM | Section 9(2), Model Tenancy Act, 2021 |
| 8 | Unrestricted Landlord Entry | MEDIUM | Section 18, Model Tenancy Act, 2021 |
This project is for educational and informational purposes. It does not constitute legal advice.
Built with ๐ฎ๐ณ for Digital India