CoolFace
Apppublic

fathima-ai01/contract-simplifier

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

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

LayerTechnology
BackendPython 3.12+, Flask 3.0.0, Flask-CORS 4.0.0, Flask-Session 0.6.0
AI / NLPHuggingFace Transformers (FLAN-T5), PyTorch, SpaCy, NLTK
ReadabilityTextstat (Flesch-Kincaid, Gunning Fog)
DatabaseMongoDB (Local / Atlas) via PyMongo 4.6.1
Authbcrypt 4.1.2, Flask Sessions
FrontendHTML5, 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

bash
git clone https://github.com/Fathima-Parli/contract-language-simplifier
cd contract-language-simplifier

Step 2: Create Virtual Environment

bash
python -m venv venv

# Windows
venv\Scripts\activate

# Mac/Linux
source venv/bin/activate

Step 3: Install Dependencies

bash
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:

env
SECRET_KEY=your_secret_key_here
MONGODB_URI=mongodb://localhost:27017/contract_simplifier

Step 5: Run Application

bash
python app.py

Open your browser at http://localhost:8000


๐Ÿ“‹ API Endpoints

Auth

MethodEndpointDescription
POST/api/registerRegister new user
POST/api/loginAuthenticate user
GET/logoutClear session & logout

Documents

MethodEndpointDescription
POST/api/uploadUpload 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/analyzeAnalyze text for readability scores
POST/api/highlight_termsDetect & highlight legal terms in text

Admin (๐Ÿ” Admin only)

MethodEndpointDescription
GET/adminAdmin dashboard UI
GET/api/admin/statsAggregated usage statistics
GET/api/admin/requestsPaginated simplification request logs
GET/api/admin/documentsAll documents (all users)
POST/api/admin/document/<id>/correctSave admin-corrected simplified text
GET/api/admin/glossaryList custom glossary terms
POST/api/admin/glossaryAdd custom legal term
DELETE/api/admin/glossary/<id>Delete custom term
POST/api/setup-adminOne-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:

javascript
fetch('/api/setup-admin', {method:'POST'})
  .then(r=>r.json())
  .then(d=>{ alert(d.message); if(d.redirect) window.location=d.redirect; })

๐Ÿ“ธ UI Overview

ScreenDescription
Document ViewBlue 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 DashboardNavy 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