An end-to-end legal document analysis system that automatically classifies contract clauses and extracts legal entities using LegalBERT + NLP, wrapped in a clean Flask web application 🚀
-
✅ Upload PDF / TXT legal documents
-
✅ Automatic clause segmentation & classification
-
✅ Named Entity Recognition (NER) for legal entities
-
✅ Interactive UI
-
✅ Flask-based backend API
- 🤖 LegalBERT (fine-tuned)
- 🧪 NLP pipelines for clause classification
- 🔍 Entity extraction (NER)
- 🐍 Python + Flask backend
- 🎨 HTML / CSS / Vanilla JavaScript frontend
LegalBert/
│
├── backend/
│ ├── app.py # Flask backend
│ ├── models/ # Trained LegalBERT model
│ └── utils/
│ ├── inference.py # Model inference logic
│ └── pdf_extractor.py # PDF text extraction
│
├── frontend/
│ ├── templates/
│ │ ├── index.html # Home page
│ │ ├── analyze.html # Analyze page
│ │ └── about.html
│ │
│ └── static/
│ ├── styles.css # Global styles
│ ├── analyze.css # Analyze page styles
│ └── analyze.js # Frontend logic
│
├── uploads/ # Temporary uploaded files
└── README.md
Download the .pt file from this link
- Drag & drop or Choose File
- Supports
.pdfand.txt
- Total clauses
- Clauses with labels
- Total entities
- High-importance clauses
- Shows Top 10 clauses by default
- 🔘 View More → see all classified clauses
- 🔁 Toggle back to Top 10
- Entity label + text
-
Create virtual environment
python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Add the classifier checkpoint
Place the trained model at:
backend/models/best_legal_classifier.ptThis file is large and should be kept as a local artifact, not committed as a normal Git file.
-
Start the server
cd backend python app.py -
Open the app
Visit
http://127.0.0.1:5500.
Entity extraction uses Ollama at
http://localhost:11434withphi3:mini. If Ollama is not running, clause classification still works and entity extraction falls back to an empty list.
- 📜 Contract review
- ⚖️ Legal compliance analysis
- 📚 Academic legal NLP research
- 🏢 Enterprise contract intelligence
![]() |
![]() |
![]() |
![]() |



