Spaces:
Sleeping
Download src/README.md from Mehreen44/PK_LegalAssitant: direct link, hf CLI and curl.
- Browser
- Download file 4.05 kB
-
https://huggingface.co/spaces/Mehreen44/PK_LegalAssitant/resolve/main/src/README.md
- Command line
-
hf download hf://spaces/Mehreen44/PK_LegalAssitant/src/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Mehreen44/PK_LegalAssitant/resolve/main/src/README.md
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:
- Constitution of Pakistan (Articles on Fundamental Rights, Equality, Fair Trial)
- Pakistan Penal Code (PPC) (e.g., Qatl-i-amd/Murder, Theft, Cheating/Fraud)
- Code of Criminal Procedure (CrPC) (e.g., FIR filing, Arrest without warrant, Bail rules)
- Code of Civil Procedure (CPC) (e.g., Injunctions, Appeals)
- Muslim Family Laws Ordinance 1961 (e.g., Polygamy, Talaq/Divorce, Maintenance)
- Industrial Relations Act 2012 (e.g., Redress of worker grievances)
- 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
βββ 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:
pip install -r requirements.txt
2. Generate Demo Legal PDFs
If you want to run the system with mock legal data immediately, run:
python generate_dummy_pdfs.py
3. Build Vector Database
Process, chunk, and embed the documents into your local FAISS vector store:
python build_vector_db.py
4. Run the Streamlit Application
Start the local web server:
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.
π₯ 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.