contract-simplifier / README.md
fathima-ai01's picture
fix short description length
f1e2bd9
|
Raw History Blame Contribute Delete
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 .txt file 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_mode field)
  • βœ… 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-admin for 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