Spaces:
Sleeping

PK_LegalAssitant / src /README.md
Mehreen44's picture
Upload 9 files
38c052b verified
|
Raw History Blame Contribute Delete
4.05 kB
---
title: Pakistan Legal Assistant
emoji: βš–οΈ
colorFrom: green
colorTo: gold
sdk: streamlit
sdk_version: 1.35.0
app_file: app.py
pinned: true
license: mit
short_description: Grounded Pakistani law Q&A in English and Roman Urdu
---
# βš–οΈ Pakistan Legal Assistant
Pakistan Legal Assistant is an AI-powered legal Q&A platform built using **Retrieval-Augmented Generation (RAG)**. The assistant answers legal questions based strictly on retrieved official Pakistani legal documents, avoiding hallucinations and ensuring high-fidelity guidance.
It supports querying in both **English** and **Roman Urdu** (e.g. *"FIR kya hoti hai?"*).
---
## πŸ“š Supported Laws & Acts
The system indices and retrieves sections from the following statutory texts:
1. **Constitution of Pakistan** (Articles on Fundamental Rights, Equality, Fair Trial)
2. **Pakistan Penal Code (PPC)** (e.g., Qatl-i-amd/Murder, Theft, Cheating/Fraud)
3. **Code of Criminal Procedure (CrPC)** (e.g., FIR filing, Arrest without warrant, Bail rules)
4. **Code of Civil Procedure (CPC)** (e.g., Injunctions, Appeals)
5. **Muslim Family Laws Ordinance 1961** (e.g., Polygamy, Talaq/Divorce, Maintenance)
6. **Industrial Relations Act 2012** (e.g., Redress of worker grievances)
7. **Punjab Rented Premises Act 2009 / Rent Restriction Ordinance** (e.g., Eviction grounds, Landlord/Tenant obligations)
---
## πŸ› οΈ Tech Stack & Pipeline
- **Frontend**: Streamlit (with custom legal emerald/gold styling)
- **Backend**: Python 3.11
- **Retrieval Engine**: LangChain & FAISS (local Vector Store)
- **Semantic Embeddings**: `sentence-transformers/paraphrase-multilingual-mpnet-base-v2` (for cross-lingual retrieval)
- **Large Language Model (LLM)**: `Qwen/Qwen2.5-1.5B-Instruct` (run locally with automated GPU/CPU fallback)
---
## πŸ“‚ Project Structure
```text
β”œβ”€β”€ app.py # Streamlit frontend dashboard
β”œβ”€β”€ requirements.txt # Project dependencies
β”œβ”€β”€ build_vector_db.py # Document parsing, cleaning, chunking, & vectorization pipeline
β”œβ”€β”€ generate_dummy_pdfs.py # Programmatic generator for mock legal files (testing)
β”œβ”€β”€ DEPLOYMENT.md # Production deployment manual (Hugging Face Spaces & Streamlit Cloud)
β”œβ”€β”€ data/ # PDF storage folder
β”‚ β”œβ”€β”€ constitution.pdf
β”‚ β”œβ”€β”€ ppc.pdf
β”‚ └── ...
β”œβ”€β”€ legal_faiss/ # Local FAISS index files
β”‚ β”œβ”€β”€ index.faiss
β”‚ └── index.pkl
└── utils/ # Modular helper utilities
β”œβ”€β”€ pdf_loader.py # PyMuPDF text extractor
β”œβ”€β”€ text_cleaner.py # Whitespace and line formatting cleaner
β”œβ”€β”€ retriever.py # Cached semantic search query engine
β”œβ”€β”€ llm_loader.py # Cached causal LM pipeline wrapper
└── prompt.py # Strict system prompt templates
```
---
## πŸš€ Local Setup & Installation
### 1. Install Dependencies
Ensure you have Python 3.11 installed. Clone the repository and install:
```bash
pip install -r requirements.txt
```
### 2. Generate Demo Legal PDFs
If you want to run the system with mock legal data immediately, run:
```bash
python generate_dummy_pdfs.py
```
### 3. Build Vector Database
Process, chunk, and embed the documents into your local FAISS vector store:
```bash
python build_vector_db.py
```
### 4. Run the Streamlit Application
Start the local web server:
```bash
streamlit run app.py
```
---
## ☁️ Deployment
For step-by-step instructions on deploying the application to **Hugging Face Spaces** or **Streamlit Community Cloud**, please refer to [DEPLOYMENT.md](file:///d:/Projects_deploy/LegalAssitant/DEPLOYMENT.md).
---
## πŸ‘₯ Authorship & Disclaimer
Developed by **Mehreen Siddique** β€” ML Engineer.
*Disclaimer: This system is built for research and educational purposes. The answers are generated from static legal text sources and do not replace professional legal advice from qualified practitioners.*