Spaces:
Sleeping
Sleeping
|
Download README.md from Manini-Dhakare/contract-simplifier: direct link, hf CLI and curl.
- Browser
- Download file 9.15 kB
-
https://huggingface.co/spaces/Manini-Dhakare/contract-simplifier/resolve/main/README.md
- Command line
-
hf download hf://spaces/Manini-Dhakare/contract-simplifier/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Manini-Dhakare/contract-simplifier/resolve/main/README.md
9.15 kB
metadata
title: Contract Language Simplifier
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: AI tool that simplifies legal contract language
Contract Language Simplifier
AI-powered tool that transforms complex legal documents into plain, easy-to-understand English.
π Milestone 4 Completed β Multi-level Simplification, Key Term Highlighting & Admin Dashboard
Date: March 7, 2026
π οΈ Tech Stack
| Layer | Technology |
|---|---|
| Backend | Python 3.12+, Flask 3.0.0, Flask-CORS 4.0.0, Flask-Session 0.6.0 |
| AI / NLP | HuggingFace Transformers (FLAN-T5), PyTorch, SpaCy, NLTK |
| Readability | Textstat (Flesch-Kincaid, Gunning Fog) |
| Database | MongoDB (Local / Atlas) via PyMongo 4.6.1 |
| Auth | bcrypt 4.1.2, Flask Sessions |
| Frontend | HTML5, CSS3, Vanilla JavaScript, Inter font |
β¨ Features β All Milestones
π΅ Milestone 1 β User Authentication
- β Registration β Secure signup with name, email, phone & password validation
- β Login / Logout β bcrypt password hashing, secure session management
- β Dashboard β View and manage all uploaded documents
π΅ Milestone 2 β NLP & Readability Analysis
- β Text Preprocessing β Cleaning, sentence segmentation (SpaCy), tokenization (NLTK)
- β Readability Scores β Flesch-Kincaid Grade Level & Gunning Fog Index
- β
Word Complexity Heatmap β Visual difficulty map directly on the text:
- π΄ Complex (3+ syllables)
- π‘ Medium (7+ chars)
- π’ Simple vocabulary
π΅ Milestone 3 β AI Model Integration (FLAN-T5)
- β Text Simplification β FLAN-T5 model rewrites legal text in plain English
- β Adjustable Level β Interactive slider (1β100) dynamically maps to model prompt intensity
- β Hybrid Summarization β AI summary with NLTK extractive fallback
- β Readability Bar Chart β Live JS bar chart showing grade drop after simplification
- β
Document Upload β Supports
.txtfile uploads up to 50 MB
π’ Milestone 4 β NEW: Advanced Features
1. Multi-level Simplification Mode
- β
Three distinct modes selectable via large card buttons:
- π Basic β Minimal changes, preserves legal structure
- π Intermediate β Balanced (default) β replaces jargon with everyday language
- π Advanced β Maximum simplification, suitable for anyone
- β
The selected mode is sent to the backend API (
simplification_modefield) - β A mode badge appears on the simplified text card after processing
- β Processing metrics displayed: time, grade reduction, original/simplified word count
2. Key Term Highlighting & Legal Glossary
- β 80+ legal terms detected automatically in uploaded documents
- β Detected terms are highlighted in amber in the Original Text pane
- β Hover tooltips show plain-English definitions instantly
- β Searchable Legal Terms Glossary panel β collapsible, with live search filter
- β Custom glossary terms (added by admin) are merged into results
- β
API endpoint:
POST /api/highlight_terms
3. Admin Dashboard (/admin)
- β
Sidebar navigation with 4 tabs:
Tab What it shows π Overview Stat cards (total requests, avg time, avg grade reduction, docs, users) + mode breakdown bar chart + 7-day daily activity chart π Requests Paginated table of every simplification log (date, document, mode, level, grades, time) π Document Review All documents across all users β click any row to open inline correction editor, save corrected simplified text π Glossary Management Add / delete custom legal term definitions that merge into highlighting results - β All simplification requests are automatically logged to MongoDB
- β Admin access: first registered user automatically becomes admin
- β
One-time setup endpoint
POST /api/setup-adminfor existing users
π Project Structure
contract-language-simplifier/
βββ app.py # Main Flask app β all routes & logic
βββ models.py # MongoDB models:
β # User, Document, SimplificationLog, GlossaryTerm
βββ requirements.txt # All Python dependencies
βββ .env # Environment config (not in repo)
β
βββ nlp/
β βββ model.py # FLAN-T5 simplification & summarization
β βββ legal_terms.py # 80+ term glossary, highlighting & tooltip HTML β NEW
β βββ readability.py # Flesch-Kincaid & Gunning Fog scoring
β βββ preprocessing.py # SpaCy/NLTK text cleaning pipeline
β βββ chunking.py # Large document chunking for FLAN-T5
β
βββ templates/
β βββ view_document.html # Document viewer β mode cards, highlighted text,
β β # glossary panel, metrics, bar chart β REDESIGNED
β βββ admin.html # Admin dashboard with 4 tabs β NEW
β βββ dashboard.html # User dashboard
β βββ login.html # Login page
β βββ register.html # Registration page
β
βββ static/
βββ css/
β βββ style.css # Dashboard styles
β βββ auth.css # Login/Register styles
βββ js/ # Frontend logic
π Setup Instructions
Prerequisites
- Python 3.8+
- MongoDB installed and running locally (or MongoDB Atlas URI)
Step 1: Clone Repository
git clone https://github.com/Fathima-Parli/contract-language-simplifier
cd contract-language-simplifier
Step 2: Create Virtual Environment
python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activate
Step 3: Install Dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm
Step 4: Configure Environment
Create a .env file in the project root:
SECRET_KEY=your_secret_key_here
MONGODB_URI=mongodb://localhost:27017/contract_simplifier
Step 5: Run Application
python app.py
Open your browser at http://localhost:8000
π API Endpoints
Auth
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/register |
Register new user |
POST |
/api/login |
Authenticate user |
GET |
/logout |
Clear session & logout |
Documents
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/upload |
Upload a document (text or .txt file) |
GET |
/document/<doc_id> |
View document with highlighting & tools |
POST |
/simplify/<doc_id> |
Simplify text β accepts level (1-100) & simplification_mode (basic/intermediate/advanced) |
POST |
/summarize/<doc_id> |
Generate hybrid AI summary |
POST |
/api/analyze |
Analyze text for readability scores |
POST |
/api/highlight_terms |
Detect & highlight legal terms in text |
Admin (π Admin only)
| Method | Endpoint | Description |
|---|---|---|
GET |
/admin |
Admin dashboard UI |
GET |
/api/admin/stats |
Aggregated usage statistics |
GET |
/api/admin/requests |
Paginated simplification request logs |
GET |
/api/admin/documents |
All documents (all users) |
POST |
/api/admin/document/<id>/correct |
Save admin-corrected simplified text |
GET |
/api/admin/glossary |
List custom glossary terms |
POST |
/api/admin/glossary |
Add custom legal term |
DELETE |
/api/admin/glossary/<id> |
Delete custom term |
POST |
/api/setup-admin |
One-time: grant admin to logged-in user |
π Admin Access
The first user to register is automatically granted admin privileges.
Already registered before admin was added? Run this in the browser console while logged in:
fetch('/api/setup-admin', {method:'POST'})
.then(r=>r.json())
.then(d=>{ alert(d.message); if(d.redirect) window.location=d.redirect; })
πΈ UI Overview
| Screen | Description |
|---|---|
| Document View | Blue gradient header, User View / Admin Dashboard tabs, 3 simplification mode cards, side-by-side original & simplified text, legal term highlighting with tooltips, searchable glossary panel |
| Admin Dashboard | Navy sidebar, 4-tab layout, stat cards, mode breakdown & activity charts, document correction editor, glossary CRUD |
π¦ Dependencies
flask==3.0.0
flask-cors==4.0.0
flask-session==0.6.0
pymongo==4.6.1
python-dotenv==1.0.0
bcrypt==4.1.2
email-validator==2.1.0
transformers
torch
spacy
nltk
textstat
=======
title: Contract Simplifier emoji: π colorFrom: red colorTo: gray sdk: docker pinned: false license: mit short_description: AI tool simplify complex legal contract language using NLP
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference