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.
- Fork this repository
- Sign up at render.com
- Create a new Web Service from your GitHub repo
- Add your
HUGGINGFACE_API_KEYas an environment variable - Deploy! π
# 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- 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
- Framework: FastAPI for high-performance API
- Model Integration: Hugging Face Inference API
- CORS: Configured for cross-origin requests
- Error Handling: Comprehensive error management
- LurisQA: 8.03B parameter LLaMA-based legal model
- Hosting: Hugging Face Inference API
- Access: Via API key authentication
| 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 |
- β‘ 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
- β‘ 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
- β Automatic HTTPS
- β Global CDN
- β Auto-deploy on Git push
- β Free tier available
- β Vercel for frontend hosting
- β Railway for backend API
- β Excellent performance
- β Perfect for model showcase
- β Integrated with Hugging Face ecosystem
- β GPU support available
- β Docker Compose setup
- β Hot reloading
- β Easy debugging
See DEPLOYMENT.md for detailed instructions.
curl -X POST http://localhost:8000/api/ask \
-H "Content-Type: application/json" \
-d '{"question": "What are Miranda rights?"}'curl http://localhost:8000/healthcurl http://localhost:8000/api/model-info# Required
HUGGINGFACE_API_KEY=your_huggingface_api_key_here
# Optional
HOST=0.0.0.0
PORT=8000
LOG_LEVEL=INFOUpdate backend/main.py with your frontend domain:
allow_origins=["https://your-domain.com", "http://localhost:3000"]- Open the web application
- Type your legal question
- Get instant, AI-powered answers
- View chat history and citations
import requests
response = requests.post("http://localhost:8000/api/ask",
json={"question": "What are Miranda rights?"})
print(response.json()["answer"])- β 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
- 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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- 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! π