CoolFace
Apppublic

anshul32/legal-summarizer

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

⚖️ Legal Contract Summarizer

Hybrid Computer Vision + NLP Legal Contract Analysis System

Fine-tuned T5-small on LEDGAR · ROUGE-1: 0.93 · EasyOCR · OpenCV

🚀 Features

FeatureDescription
🤖 Structured AI Summary6-section legal report: Overview, Financial, Clauses, Risks, AI narrative, Assessment
📑 Agreement ClassificationAuto-detects NDA, Employment, Service, Lease, and 8+ agreement types
🎯 Risk DashboardRule-based 0–100 score with categorized severity flags
📋 18+ Clause TypesTermination, NDA, IP, Arbitration, Indemnity, Force Majeure, and more
🔬 CV Pipeline8-panel visualization — Units 1, 2, 4, 5, 6 (perspective + bilateral filter)
👁️ OCR + HeatmapEasyOCR with colour-coded confidence bounding boxes
✍️ Signature DetectionContour solidity analysis
🔵 Stamp DetectionHough circles + HSV color ink detection
📐 Skew CorrectionHough line angle estimation + affine warp
⬇️ JSON ExportFull structured export of analysis results

🧠 NLP Pipeline

Contract Text / OCR Output
    ↓
Text Cleaning + Normalization
    ↓
Chunked Summarization (T5-small, max 400 words/chunk)
    ↓
Regex Field Extraction (parties, dates, payment, governing law...)
    ↓
Clause Detection (18 clause types via regex patterns)
    ↓
Risk Scoring (missing clauses + red flag language)
    ↓
HTML Report + JSON Export

🔬 Computer Vision Pipeline

StepOpenCV OperationSyllabus Unit
RGB → GrayscalecvtColor(COLOR_RGB2GRAY)Unit 5
Perspective CorrectionContour quad + warpPerspectiveUnit 2
Skew CorrectionHough lines + warpAffineUnit 2
Histogram EqualizationequalizeHist()Unit 1
Noise RemovalbilateralFilter + GaussianBlurUnit 1
Binarizationthreshold(THRESH_OTSU)Unit 6
Edge DetectionCanny(50, 150)Unit 6
Contour SegmentationfindContours()Unit 6
Harris CornerscornerHarris()Unit 4
HOG FeaturesHOGDescriptorUnit 4
Signature DetectionContour solidity heuristicsUnit 6
Stamp DetectionHough circles + HSV maskingUnit 5, 6
OCREasyOCR + bbox confidenceMultimodal

📥 Input Formats

  • —Tab 1: Paste raw contract text directly
  • —Tab 2: Upload .txt or digital .pdf
  • —Tab 3: Upload scanned contract image (.jpg, .png) — runs full CV → OCR → NLP

🏗️ Architecture

                    ┌─────────────────────────────────┐
                    │   Gradio Web Interface (3 tabs)  │
                    └───────────┬─────────────────────┘
                                │
              ┌─────────────────┼─────────────────┐
              ▼                 ▼                  ▼
       [Text Input]      [File Upload]     [Image Upload]
              │                 │                  │
              │                 │           CV Pipeline
              │                 │          (8 steps, OpenCV)
              │                 │                  │
              └─────────────────┴──────────────────┘
                                │
                         EasyOCR (if image)
                                │
                         NLP Pipeline
                         (T5 + Regex)
                                │
                    ┌───────────┴───────────┐
                    ▼                       ▼
              HTML Report              JSON Export

🛠️ Tech Stack

  • —Model: anshul32/t5-legal-summarizer (T5-small fine-tuned on LEDGAR)
  • —OCR: EasyOCR
  • —CV: OpenCV (opencv-python-headless)
  • —UI: Gradio 4+
  • —PDF: PyMuPDF (fitz)
  • —Visualization: Matplotlib

⚠️ Disclaimer

This tool is for educational and informational purposes only. It is not a substitute for professional legal advice. Always consult a qualified attorney for legal matters.


👤 Author

Anshul Kumar · HuggingFace · Kaggle

Computer Vision + NLP Academic Project