--- 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.*