WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
Project Overview
AI-Powered Legal Document Summarization System using NLP, RAG (Retrieval-Augmented Generation), and transformer models (BERT, T5, BART, LexT5) for forensic and legal document analysis.
Common Commands
Backend
Install Dependencies:
cd backend
pip install -r requirements.txt
Download Required Models:
python -m spacy download en_core_web_sm
python -c "import nltk; nltk.download('stopwords')"
Run Flask API Server:
cd backend
python app.py
Server runs on http://127.0.0.1:5000
Test NLP Pipeline:
cd backend
python test_nlp_pipeline.py
Frontend
Run Streamlit UI:
cd frontend
streamlit run streamlit_app.py
Note: Both backend (Flask on port 5000) and frontend (Streamlit) must run simultaneously for full functionality.
Architecture Overview
Backend Structure
backend/app.py — Main Flask API server
ForensicDocumentAnalyzerclass: Core document analysis orchestrator- Lazy-loads heavy models (LexT5) to optimize startup time
- Key endpoints:
/api/test- Health check/api/analyze- PDF upload & summarization (extractive/hybrid modes)/api/query- RAG-based semantic search and answer generation
backend/nlp_module/ — NLP Processing Pipeline
text_preprocessing.py- SpaCy-based entity extraction (PERSON, ORG, DATE, GPE, CASE_ID) + custom legal patternsextractive_summarization.py- Hybrid TextRank + TF-IDF with legal document boosting (handles long legal sentences)abstractive_summarization.py- LexT5 (Legal T5) for refinement with chunking strategysentiment_risk_analyzer.py- Forensic intelligence extractionmodel_wrapper.py- Model abstraction layer
backend/rag_module/ — RAG Engine
rag_engine.py- FAISS-based vector store withsentence-transformers/all-MiniLM-L6-v2embeddings- Uses
pszemraj/led-large-book-summaryfor answer generation - Persists index to
vector_store/legal_faiss.indexandvector_store/legal_metadata.json
Frontend Structure
frontend/streamlit_app.py — Glassmorphic web interface
- Two-tab design: Document Analysis and RAG Query
- Communicates with Flask backend via HTTP POST
- Custom CSS with glassmorphism and animations
Data Flow
- Document Upload → PDF extracted with PyMuPDF (
fitz) - Text Preprocessing → SpaCy sentence splitting + entity recognition
- Extractive Summarization → Hybrid scoring (TextRank + TF-IDF)
- Optional Abstractive Refinement → LexT5 model compresses extractive output
- RAG Indexing → Document chunks embedded and stored in FAISS
- Query Processing → Semantic search → Context retrieval → LED model generates answer
Key Design Patterns
Lazy Model Loading:
get_abstractive_model()function defers LexT5 loading until hybrid mode is requested- Reduces memory footprint for extractive-only workflows
Singleton Pattern:
get_analyzer()ensures singleForensicDocumentAnalyzerinstancerag_engineinstantiated as global inapp.py
Legal Text Handling:
- Custom sentence splitting for long legal sentences (40-50 words/sentence)
- Legal markers (
<HD>,Section,held that) receive 20% score boost in extractive summarization - Corruption detection for scanned PDFs (single-letter patterns, repetition)
Chunking Strategy:
- Extractive summary fed to abstractive model to prevent context loss
- LexT5 uses 512-token chunks with sentence boundary preservation
- Compression ratio maintained at 50-70% to preserve legal detail
Data Directory
data/ contains 85 legal case files (LNIND_1951_CAL_*.txt) from 1951 Calcutta High Court - used for testing and RAG indexing.
Model Information
Extractive Models:
- SpaCy:
en_core_web_sm - TextRank via NetworkX PageRank
- TF-IDF via scikit-learn
Abstractive Models:
- Primary:
santoshtyss/lt5-small(LexT5 - Legal T5) - RAG Generator:
pszemraj/led-large-book-summary(LED model)
Embedding Models:
sentence-transformers/all-MiniLM-L6-v2(384-dim vectors)
Testing Approach
Use backend/test_nlp_pipeline.py to test individual NLP modules with sample legal text. No formal test framework detected - tests are manual via sample inputs.
Important Notes
- Windows Environment: This project uses PowerShell commands (adjust for Unix if needed)
- GPU Acceleration: Models auto-detect CUDA; CPU fallback available
- PDF Requirements: Only accepts
.pdffiles; scanned PDFs are detected and rejected - FAISS Persistence: Vector store automatically saves after each document addition
- File Cleanup: Uploaded PDFs are deleted after analysis (see
finallyblock in/api/analyze) - CORS: Backend enables CORS for all origins on
/api/*routes
Requirements
Key dependencies:
- Flask + flask-cors
- spacy + en_core_web_sm model
- nltk
- transformers + torch
- sentence-transformers
- scikit-learn
- faiss-cpu or faiss-gpu
- pymupdf (fitz)
- streamlit + streamlit-lottie
Related Documents
SUMMARY
permalink: ai-implementation
Retrieval & Prompts
Retrieval quality depends on two things: **what the extraction prompt produces**, and **how Vector Storage is configured**. Most people start with Vector Storage settings — but the bigger lever is the prompt. A well-structured memory block retrieves accurately even with default settings. A poorly structured one won't retrieve well no matter how much you tune.
App Review Support Guide — Switch2Go
Switch2Go is an **AAC (Augmentative and Alternative Communication)** app designed specifically for users with **Cerebral Visual Impairment (CVI)**. It allows non-verbal or communication-impaired users to compose and speak phrases entirely hands-free using:
RFC-BLite: High-Performance Embedded Document Database for .NET
**Status:** Draft (living document)