Skip to content

Boombaybay12334/LAWREADER

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LAWREADER - AI-Powered Legal Document Analysis & Query System

Python React FastAPI License

A sophisticated legal AI system for Indian law, combining PDF document analysis with knowledge graph-based query resolution.

🌟 Key Features

οΏ½ PDF Document Analyzer (Tool 1)

  • Multi-format Support: Analyze court judgments, contracts, statutes, legal notices, and petitions
  • Intelligent Segmentation: AI-powered document-type-specific parsing
  • Citation Extraction: Automated extraction of case law, statutes, and legal principles
  • Plain-Language Summaries: Convert complex legal text into accessible explanations
  • PDF Report Generation: Comprehensive analysis reports in PDF format

πŸ€– Legal Query System (Tool 2)

  • Knowledge Graph Architecture: Pre-built graph of Indian legal scenarios, principles, and articles
  • Hybrid Approach: Graph matching with LLM fallback for comprehensive coverage
  • Semantic Search: InLegalBERT embeddings + FAISS for fast similarity matching
  • Dynamic Learning: Automatically updates knowledge graph with new scenarios
  • Context-Aware Answers: Expands legal context through graph traversal

🎨 Web Application

  • Modern React UI: Responsive, accessible interface with TypeScript
  • Real-time Processing: Live progress updates and streaming responses
  • Dual-Mode Interface: PDF upload and text query interfaces
  • Professional Design: Tailwind CSS with legal industry aesthetics

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Frontend (React + TypeScript)               β”‚
β”‚         PDFAnalyzer β”‚ LegalQuery β”‚ Home                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               Backend (FastAPI)                              β”‚
β”‚    /upload-pdf  β”‚  /legal-query  β”‚  /download/{id}         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                                   β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
    β”‚   Tool 1     β”‚                    β”‚   Tool 2     β”‚
    β”‚ PDF Analyzer β”‚                    β”‚ Graph Query  β”‚
    β”‚              β”‚                    β”‚  Resolver    β”‚
    β”‚ β€’ Parser     β”‚                    β”‚ β€’ Matcher    β”‚
    β”‚ β€’ Segmenter  β”‚                    β”‚ β€’ Traversal  β”‚
    β”‚ β€’ Summarizer β”‚                    β”‚ β€’ AutoLinker β”‚
    β”‚ β€’ Citations  β”‚                    β”‚ β€’ Simplifier β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.8+ with pip
  • Node.js 16+ with npm
  • Git

Installation

1. Clone Repository

git clone https://github.com/Boombaybay12334/LAWREADER.git
cd LAWREADER

2. Backend Setup

Create Environment Files:

backend/.env:

# Not required for backend itself, but tools need their own .env

tool1/.env:

OPENROUTER_API_KEY=your_openrouter_api_key_here
MISTRAL_MODEL=mistralai/mistral-7b-instruct

tool2/.env:

LLM_API_KEY=your_llm_api_key_here
GRAPH_PATH=law_graphTest.gpickle

Install Backend Dependencies:

cd backend
python -m venv venv
venv\Scripts\activate  # Windows
# source venv/bin/activate  # Linux/Mac

pip install -r requirements.txt
mkdir uploads processed

Setup Tool 1:

cd ../tool1
python -m venv venv
venv\Scripts\activate  # Windows
pip install -r requirements.txt

Setup Tool 2:

cd ../tool2
python -m venv venv
venv\Scripts\activate  # Windows
pip install -r requirements.txt

3. Frontend Setup

cd ..  # Back to root
npm install

Running the Application

Terminal 1 - Backend:

cd backend
venv\Scripts\activate
python main.py

API available at: http://localhost:8000

Terminal 2 - Frontend:

npm run dev

App available at: http://localhost:5173

πŸ“š Usage

PDF Analysis

  1. Navigate to "PDF Analyzer" page
  2. Upload a legal PDF document
  3. Wait for processing (typically 1-2 minutes)
  4. Download the analyzed report

Legal Queries

  1. Navigate to "Legal Query" page
  2. Enter your legal question in plain English
  3. Receive contextual answer with:
    • Relevant legal principles
    • Constitutional articles
    • Plain-language explanation

Example Queries

  • "Can police arrest me without a warrant during a protest?"
  • "What are my rights if my employer fires me without notice?"
  • "Is blocking internet during protests a violation of fundamental rights?"

πŸ› οΈ Technology Stack

Frontend

Tech Purpose
React 18 UI Framework
TypeScript Type Safety
Tailwind CSS Styling
Vite Build Tool
Axios API Client

Backend

Tech Purpose
FastAPI Web Framework
Python 3.8+ Runtime
Uvicorn ASGI Server

AI/ML Components

Tech Purpose
Mistral 7B LLM (via OpenRouter)
InLegalBERT Legal Embeddings
BART-large-MNLI Document Classification
FAISS Vector Similarity Search
NetworkX Graph Operations
pdfplumber PDF Parsing

πŸ“Š Project Structure

LAWREADER/
β”œβ”€β”€ frontend/           # React application
β”‚   └── src/
β”‚       β”œβ”€β”€ components/ # Reusable UI components
β”‚       β”œβ”€β”€ pages/      # Route pages
β”‚       β”œβ”€β”€ services/   # API client
β”‚       └── types/      # TypeScript definitions
β”‚
β”œβ”€β”€ backend/           # FastAPI server
β”‚   β”œβ”€β”€ main.py        # Application entry
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ tool1/             # PDF Analyzer
β”‚   └── pipeline/
β”‚       β”œβ”€β”€ main.py
β”‚       β”œβ”€β”€ parser.py
β”‚       β”œβ”€β”€ segmenter.py
β”‚       β”œβ”€β”€ summarizer.py
β”‚       └── citation_extractor.py
β”‚
β”œβ”€β”€ tool2/             # Query Resolver
β”‚   β”œβ”€β”€ lawreader_main.py
β”‚   β”œβ”€β”€ semantic_matcher.py
β”‚   β”œβ”€β”€ traversal.py
β”‚   β”œβ”€β”€ auto_linker.py
β”‚   └── answer_simplifier.py
β”‚
└── data/              # Knowledge graphs & indices
    └── law_graphTest.gpickle

πŸ“– Documentation

  • Codebase Analysis Report - Comprehensive workflow analysis and recommendations
  • Tool 1 README - PDF Analyzer documentation
  • API Documentation - Available at http://localhost:8000/docs when backend is running

πŸ”§ Development

Running Tests

# Backend tests
cd backend
pytest

# Tool 1 tests
cd tool1
pytest tests/

# Tool 2 tests
cd tool2
pytest

Code Quality

# Format code
black backend/ tool1/ tool2/

# Lint
flake8 backend/ tool1/ tool2/

🚨 Known Issues & Limitations

  1. Hardcoded Font Path in tool1/pipeline/main.py - Needs relative path
  2. Subprocess Architecture - Backend launches tools as subprocesses (inefficient)
  3. Single-threaded Processing - No concurrent request handling
  4. No Authentication - Open API (not production-ready)
  5. Limited Error Recovery - Failures require manual intervention

See CODEBASE_ANALYSIS_REPORT.md for detailed recommendations.

πŸ—ΊοΈ Roadmap

  • Refactor to monolithic FastAPI app (remove subprocess calls)
  • Implement caching layer (Redis)
  • Add user authentication (JWT)
  • Background task processing (Celery)
  • Real-time progress updates (WebSockets)
  • Multi-language support
  • Mobile application
  • Deployment guides (Docker, Kubernetes)

🀝 Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

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

πŸ“„ License

This project is licensed under the MIT License - see LICENSE file for details.

πŸ‘₯ Authors

  • Abhin - Initial work

πŸ™ Acknowledgments

  • InLegalBERT for legal domain embeddings
  • OpenRouter for LLM API access
  • Indian legal community for domain knowledge

πŸ“ž Support

For issues and questions:


Made with ❀️ for the Indian legal community

API Endpoints

Health Check

  • GET /health - Server health status

PDF Analysis

  • POST /upload-pdf - Upload and analyze PDF documents
  • GET /download/{file_id} - Download processed documents

Legal Queries

  • POST /legal-query - Process legal questions

Project Structure

legal-document-analyzer/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py              # FastAPI application
β”‚   β”œβ”€β”€ requirements.txt     # Python dependencies
β”‚   β”œβ”€β”€ .env                 # Environment variables
β”‚   β”œβ”€β”€ uploads/             # Temporary upload directory
β”‚   └── processed/           # Processed files directory
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ Layout.tsx
β”‚   β”‚   β”œβ”€β”€ LoadingSpinner.tsx
β”‚   β”‚   β”œβ”€β”€ ErrorMessage.tsx
β”‚   β”‚   └── SuccessMessage.tsx
β”‚   β”œβ”€β”€ pages/              # Page components
β”‚   β”‚   β”œβ”€β”€ Home.tsx
β”‚   β”‚   β”œβ”€β”€ PDFAnalyzer.tsx
β”‚   β”‚   └── LegalQuery.tsx
β”‚   β”œβ”€β”€ services/           # API services
β”‚   β”‚   └── api.ts
β”‚   β”œβ”€β”€ types/              # TypeScript types
β”‚   β”‚   └── index.ts
β”‚   └── App.tsx             # Main application component
β”œβ”€β”€ package.json
└── README.md

Configuration

Environment Variables (Backend)

Create a .env file in the backend directory:

API_HOST=0.0.0.0
API_PORT=8000
DEBUG=True
LOG_LEVEL=INFO
MAX_FILE_SIZE=10485760
UPLOAD_DIR=uploads
PROCESSED_DIR=processed

Security Features

  • File type validation (PDF only)
  • File size limits (10MB maximum)
  • Automatic file cleanup (files older than 1 hour)
  • CORS configuration for frontend integration
  • Input sanitization and validation

Tool Integration

Tool 1: PDF Document Analyzer

Replace the simulation code in main.py with actual tool execution:

# Replace the simulation with:
result = subprocess.run([
    "python", "-m", "pipeline.main", "--file", str(input_path)
], capture_output=True, text=True, timeout=300)

Tool 2: Legal Query System

Replace the simulation code in main.py with actual tool execution:

# Replace the simulation with:
result = subprocess.run([
    "python", "lawreader_main.py", "-q", query.question
], capture_output=True, text=True, timeout=120)

Development

Running Tests

# Backend tests (if implemented)
cd backend
python -m pytest

# Frontend tests
npm test

Building for Production

# Build frontend
npm run build

# Start production server
npm run preview

Deployment

Backend Deployment

# Using uvicorn directly
uvicorn main:app --host 0.0.0.0 --port 8000

# Using gunicorn for production
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000

Frontend Deployment

npm run build
# Deploy the dist/ directory to your hosting service

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors