Skip to content
Vansh-SharmaaPublic

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LexAI: Advanced AI-Driven Legal Document Intelligence βš–οΈπŸ€–

Python License CI/CD CodeQL Code Coverage Streamlit Hugging Face Spaces Stars

LexAI is a high-performance legal document analysis platform that leverages State-of-the-Art (SOTA) LLMs and Retrieval-Augmented Generation (RAG) to transform how legal professionals interact with complex contracts. Built with a focus on precision, security, and automation.


πŸš€ Key Features

Feature Description Technology
πŸ“„ Map-Reduce Summarization Process 10,000+ word documents into structured executive summaries LangChain LCEL, Parallel Processing
πŸ’¬ RAG-Powered Q&A Hallucination-free chat grounded in your documents FAISS, LLaMA 3.1, Sentence-Transformers
⚠️ Automated Risk Assessment Multi-dimensional risk scoring (Compliance, Financial, Operational) NLTK VADER, Keyword Frequency Analysis
πŸ”„ Side-by-Side Comparison Semantic & line-level document diffing for contract versions Custom Diff Algorithm, Embeddings
πŸ“‹ Compliance Classifier Automated regulatory domain identification (GDPR, HIPAA, IP, etc.) Multi-label Classification
πŸ“Š Report Generation Professional PDF reports with findings & recommendations FPDF, Jinja2 Templates

πŸ› οΈ Tech Stack

graph LR
    A[PDF Upload] --> B[PyMuPDF Extraction]
    B --> C[Recursive Chunking]
    C --> D[FAISS Vector Index]
    D --> E[LangChain LCEL Pipeline]
    E --> F[Groq LLaMA 3.1 8B/70B]
    F --> G[Structured Output]
    
    style A fill:#e3f2fd
    style D fill:#f3e5f5
    style E fill:#e8f5e9
    style F fill:#fff3e0
    style G fill:#e0f2f1
Loading
Category Technologies
LLM Engine Groq (LLaMA 3.1 8B/70B) - Sub-second inference
Frameworks LangChain (LCEL), Streamlit
Vector Database FAISS (local, no external dependencies)
Embeddings Sentence-Transformers (all-MiniLM-L6-v2)
NLP Utilities NLTK, PyMuPDF, Scikit-learn
Document Processing FPDF (PDF generation), python-docx

πŸ“ System Architecture

Information Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Upload    │───▢│  Extraction  │───▢│  Chunking &  │───▢│  FAISS Index β”‚
β”‚   (PDF)     β”‚    β”‚  (PyMuPDF)   β”‚    β”‚  Embedding   β”‚    β”‚  (Vector DB) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                   β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Output    │◀───│  Synthesis   │◀───│  Retrieval   │◀───│   Query      β”‚
β”‚   (Report)  β”‚    β”‚  (LLM Chain) β”‚    β”‚  + RAG       β”‚    β”‚   (User)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Analysis Modules

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    LEXAI ANALYSIS PIPELINE                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Summarizer  β”‚   Q&A RAG   β”‚ Risk Score  β”‚  Compliance Classifierβ”‚
β”‚ (Map-Reduce)β”‚  (FAISS+LLM)β”‚ (VADER+NLP) β”‚   (Multi-label)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Comparison Engine β”‚
                    β”‚ (Semantic + Line) β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Report Generator β”‚
                    β”‚    (PDF/MD)       β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Installation & Setup

Prerequisites

1. Clone & Install

git clone https://github.com/Vansh-Sharmaa/LexAI.git
cd LexAI
pip install -r requirements.txt

2. Configure Environment

cp .env.example .env
GROQ_API_KEY=your_groq_api_key_here
STREAMLIT_SERVER_PORT=8501

3. Run

Streamlit App:

streamlit run app.py

CLI Analysis:

python main.py --pdf contract.pdf --analyze all

🐳 Docker Deployment

docker build -t lexai .
docker run -p 8501:8501 -e GROQ_API_KEY=your_key lexai

πŸ“ Project Structure

LexAI/
β”œβ”€β”€ .github/workflows/ci.yml       # CI/CD Pipeline
β”œβ”€β”€ app.py                         # Streamlit Web App
β”œβ”€β”€ rag.py                         # RAG Pipeline (FAISS + LLM)
β”œβ”€β”€ summarization.py               # Map-Reduce Summarization
β”œβ”€β”€ risk_analysis.py               # Risk Scoring (VADER + Keywords)
β”œβ”€β”€ compliance.py                  # Compliance Classification
β”œβ”€β”€ comparison.py                  # Document Comparison Engine
β”œβ”€β”€ document_processing.py         # PDF Parsing & Chunking
β”œβ”€β”€ report_generation.py           # PDF/Markdown Report Generation
β”œβ”€β”€ utils.py                       # Shared Utilities
β”œβ”€β”€ requirements.txt               # Dependencies
β”œβ”€β”€ .env.example                   # Environment Template
β”œβ”€β”€ LexAI_Logo.png                 # Brand Assets
β”œβ”€β”€ mermaid-diagram.png            # Architecture Diagram
└── README.md

πŸ“Š Example Use Cases

1. Contract Review (M&A)

Input: 50-page acquisition agreement
Output: 
  β€’ 2-page executive summary
  β€’ 15 risk flags (5 High, 7 Medium, 3 Low)
  β€’ GDPR/CCPA compliance gaps identified
  β€’ Side-by-side vs. previous version

2. Regulatory Compliance Audit

Input: Policy documents + regulations
Output:
  β€’ Compliance scorecard per regulation
  β€’ Missing clauses checklist
  β€’ Remediation recommendations

3. Legal Research Assistant

Query: "What are the termination clauses in this contract?"
Output: Grounded answer with exact clause citations

πŸ§ͺ Testing

# Unit tests
pytest tests/ -v

# With coverage
pytest --cov=. --cov-report=html

πŸ“ˆ Performance Benchmarks

Metric Value
Summarization (10k words) ~12 seconds
RAG Query Latency ~800ms
Risk Analysis ~3 seconds
Comparison (2 docs) ~5 seconds
End-to-End Report ~25 seconds

Benchmarks on Groq LLaMA 3.1 70B, 16GB RAM


πŸ” Security & Privacy

  • No data persistence - Documents processed in-memory only
  • Local vector storage - FAISS index never leaves your machine
  • API keys via env - No hardcoded secrets
  • Groq privacy - No training on your data (per Groq policy)

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'feat: add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

MIT License - see LICENSE for details.


πŸ‘¨β€πŸ’» Author

Vansh Sharma - AI/ML Engineer | NLP | GenAI | LLMs

GitHub LinkedIn Email


πŸ™ Acknowledgments


⭐ Star this repo if you find it useful! ⭐

Live Demo HF Spaces

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages