Skip to content

A fine-tuned legal QA system using Zephyr or LLaMA with GGUF support. Real-time inference via Hugging Face API or local model hosting.

License

Notifications You must be signed in to change notification settings

AdityaMogare/LurisQA

Repository files navigation

🧠 Legal QA System with Fine-Tuned LLMs and RAG

A scalable Legal Question Answering (QA) system that combines fine-tuned open-source Language Models (LLaMA, Mistral) with Retrieval-Augmented Generation (RAG) to deliver accurate, explainable answers from 100K+ U.S. legal documents.

🌐 Live Web Application: Access the system through a modern React frontend with FastAPI backend, connecting to the LurisQA model on Hugging Face.


πŸš€ Quick Start

Option 1: Deploy to Render (Recommended)

  1. Fork this repository
  2. Sign up at render.com
  3. Create a new Web Service from your GitHub repo
  4. Add your HUGGINGFACE_API_KEY as an environment variable
  5. Deploy! πŸŽ‰

Option 2: Local Development

# Clone the repository
git clone <your-repo-url>
cd Legal-QA-System-with-Fine-Tuned-LLMs-and-RAG

# Set up environment variables
cp backend/env.example backend/.env
# Edit backend/.env with your Hugging Face API key

# Run with Docker Compose
docker-compose up --build

# Or run manually:
# Backend: cd backend && pip install -r requirements.txt && python main.py
# Frontend: cd frontend && npm install && npm start

πŸ—οΈ Architecture

Frontend (React)

  • Framework: React 18 with Create React App
  • Styling: Tailwind CSS for modern, responsive design
  • Icons: Lucide React for beautiful icons
  • HTTP Client: Axios for API communication

Backend (FastAPI)

  • Framework: FastAPI for high-performance API
  • Model Integration: Hugging Face Inference API
  • CORS: Configured for cross-origin requests
  • Error Handling: Comprehensive error management

Model

  • LurisQA: 8.03B parameter LLaMA-based legal model
  • Hosting: Hugging Face Inference API
  • Access: Via API key authentication

🧰 Tech Stack

Module Technology
Frontend React 18, Tailwind CSS, Axios
Backend FastAPI, Python 3.11
Model Hosting Hugging Face Inference API
Language Models JurisPrae (LLaMA-based, 8.03B params)
Fine-Tuning LoRA (via PEFT, bitsandbytes)
Embeddings SentenceTransformers
Vector Store FAISS
Deployment Docker, Render, Vercel, Railway

πŸ“¦ Features

Web Application

  • ⚑ Real-time Chat Interface: Modern, responsive UI for legal Q&A
  • πŸ” Semantic Search: Powered by RAG technology
  • πŸ’¬ Chat History: Persistent conversation tracking
  • 🎨 Professional Design: Legal-themed UI with accessibility features
  • πŸ“± Mobile Responsive: Works on all devices
  • ⚠️ Legal Disclaimer: Built-in disclaimers for legal compliance

Core System

  • ⚑ 4Γ— Memory Efficient: LoRA tuning reduces GPU footprint
  • πŸ” Semantic Search: Real-time retrieval of relevant legal paragraphs
  • πŸ’¬ Answer Grounding: LLM outputs cite actual case law & statutory references
  • πŸ› οΈ End-to-End Pipeline: From document ingestion to user query generation

🌐 Deployment Options

1. Render (Full-Stack)

  • βœ… Automatic HTTPS
  • βœ… Global CDN
  • βœ… Auto-deploy on Git push
  • βœ… Free tier available

2. Vercel + Railway

  • βœ… Vercel for frontend hosting
  • βœ… Railway for backend API
  • βœ… Excellent performance

3. Hugging Face Spaces

  • βœ… Perfect for model showcase
  • βœ… Integrated with Hugging Face ecosystem
  • βœ… GPU support available

4. Local Development

  • βœ… Docker Compose setup
  • βœ… Hot reloading
  • βœ… Easy debugging

See DEPLOYMENT.md for detailed instructions.


πŸ§ͺ API Usage

Ask a Legal Question

curl -X POST http://localhost:8000/api/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "What are Miranda rights?"}'

Health Check

curl http://localhost:8000/health

Model Information

curl http://localhost:8000/api/model-info

πŸ”§ Configuration

Environment Variables

# Required
HUGGINGFACE_API_KEY=your_huggingface_api_key_here

# Optional
HOST=0.0.0.0
PORT=8000
LOG_LEVEL=INFO

CORS Settings

Update backend/main.py with your frontend domain:

allow_origins=["https://your-domain.com", "http://localhost:3000"]

πŸ“Š Example Usage

Web Interface

  1. Open the web application
  2. Type your legal question
  3. Get instant, AI-powered answers
  4. View chat history and citations

Programmatic Access

import requests

response = requests.post("http://localhost:8000/api/ask", 
                        json={"question": "What are Miranda rights?"})
print(response.json()["answer"])

πŸ”’ Security & Compliance

  • βœ… API Key Protection: Secure environment variable handling
  • βœ… CORS Configuration: Proper cross-origin request handling
  • βœ… Input Validation: Pydantic models for request validation
  • βœ… Error Handling: Comprehensive error management
  • βœ… Legal Disclaimer: Built-in disclaimers for legal compliance

πŸš€ Performance

  • Response Time: < 5 seconds for most queries
  • Concurrent Users: Supports multiple simultaneous users
  • Scalability: Horizontal scaling via Docker containers
  • Caching: Static asset optimization via nginx

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

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


πŸ™ Acknowledgments

  • Hugging Face for model hosting and inference API
  • The open-source community for the amazing tools and libraries

Ready to deploy? Check out the Deployment Guide! πŸš€

About

A fine-tuned legal QA system using Zephyr or LLaMA with GGUF support. Real-time inference via Hugging Face API or local model hosting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published