A voice-based AI legal assistant that helps Palestinian citizens understand their rights under the Palestinian Basic Law (2003, amended 2005), auto-fill legal forms, and find nearby legal aid clinics β available in Arabic and English.
Most people who face legal problems β eviction, labor disputes, custody issues β have no access to a lawyer. This project puts a legal expert in their pocket, for free.
The system works like this:
legal-aid-palestine/
β
βββ data/
β βββ raw/
β β βββ palestine_basic_law_en.txt # Full text from constituteproject.org
β βββ processed/
β β βββ articles.jsonl # Parsed articles (id, title, text)
β β βββ training_qa.jsonl # Fine-tuning Q&A pairs
β β βββ rag_chunks.jsonl # RAG vector store chunks
β βββ forms/
β βββ templates/ # PDF form templates
β
βββ pipeline/
β βββ palestine_law_pipeline.py # Fetch β parse β generate Q&A + RAG chunks
β
βββ model/
β βββ finetune.py # QLoRA fine-tuning script
β βββ inference.py # Local inference wrapper
β βββ rag.py # ChromaDB vector store + retrieval
β
βββ app/
β βββ main.py # FastAPI backend
β βββ transcribe.py # Whisper speech-to-text
β βββ intent.py # Legal intent classifier
β βββ form_filler.py # PDF auto-fill
β βββ referral.py # Nearby clinic lookup
β
βββ frontend/
β βββ index.html # Simple voice UI (Arabic + English)
β
βββ requirements.txt
βββ .env.example
βββ README.md
| Layer | Technology | Why |
|---|---|---|
| Speech-to-text | faster-whisper | Best Arabic transcription, runs offline |
| Legal reasoning | SaulLM-7B or Mistral-7B (QLoRA fine-tuned) | Open source, no API dependency |
| Vector store | ChromaDB | Lightweight, local, easy to set up |
| Embeddings | sentence-transformers/paraphrase-multilingual-mpnet-base-v2 | Arabic + English support |
| Backend | FastAPI | Fast, async, easy to deploy |
| PDF forms | reportlab + pypdf | Generate and fill Arabic-ready PDFs |
| Frontend | Plain HTML + JS | Works on any device, low bandwidth |
git clone https://github.com/your-username/legal-aid-palestine
cd legal-aid-palestine
pip install -r requirements.txt
# Fetch, parse, and generate training data from the Palestinian Basic Law
python pipeline/palestine_law_pipeline.py
# Output files:
# data/processed/articles.jsonl β structured articles
# data/processed/training_qa.jsonl β Q&A pairs for fine-tuning
# data/processed/rag_chunks.jsonl β chunks for vector DB
python model/rag.py --build
# Embeds all RAG chunks into ChromaDB
# Stored locally at: ./chroma_db/
Only needed if you want a fully custom model. Skip this for a quick demo β just use SaulLM-7B directly with RAG.
python model/finetune.py \
--base_model "Equall/Saul-7B-Instruct-v1" \
--data "data/processed/training_qa.jsonl" \
--output_dir "./legal-model-lora" \
--epochs 3
Requires a GPU with 8GB+ VRAM. Works on Google Colab T4.
uvicorn app.main:app --reload --port 8000
# Open: http://localhost:8000
The Palestinian Basic Law (2003, amended 2005) is sourced from:
These are public domain government texts. No copyright restrictions.
constituteproject.org
β
βΌ
fetch_constitution()
β Raw HTML/text
βΌ
parse_articles()
β List of {id, title, text}
βΌ
ββββββ΄βββββ
βΌ βΌ
generate_ generate_
qa_pairs() rag_chunks()
β β
βΌ βΌ
training_ rag_
qa.jsonl chunks.jsonl
{"instruction": "Under Palestinian law, what are my rights regarding personal freedom and unlawful arrest?", "response": "Under Article 11 of the Palestinian Basic Law: Personal freedom is a natural right, shall be guaranteed and may not be violated. It is unlawful to arrest, search, imprison, restrict the freedom, or prevent the movement of any person, except by judicial order in accordance with the provisions of the law. Note: This is general legal information. For specific legal advice, please consult a qualified Palestinian lawyer.", "source": "Palestine Basic Law 2003 (rev. 2005)", "article": "Article 11"}
{"instruction": "What does Article 14 of the Palestinian Basic Law say about presumption of innocence and right to a lawyer?", "response": "According to Article 14 of the Palestinian Basic Law (2003, amended 2005): An accused person is considered innocent until proven guilty in a court of law. Any person accused in a criminal case shall be represented by a lawyer.", "source": "Palestine Basic Law 2003 (rev. 2005)", "article": "Article 14"}
{"id": "palestine_basic_law_Article_11", "text": "Article 11 (TITLE TWO β PUBLIC RIGHTS AND LIBERTIES): Personal freedom is a natural right, shall be guaranteed and may not be violated...", "metadata": {"source": "Palestine Basic Law 2003", "article": "Article 11", "title": "TITLE TWO β PUBLIC RIGHTS AND LIBERTIES", "keywords": ["arrest", "freedom", "detention", "judicial order"]}}
Use SaulLM-7B-Instruct directly. Feed it the relevant Basic Law articles at inference time via RAG. No training needed.
# model/inference.py
from transformers import pipeline
from model.rag import retrieve
llm = pipeline("text-generation", model="Equall/Saul-7B-Instruct-v1")
def answer(user_question):
chunks = retrieve(user_question, top_k=3)
context = "\n\n".join(chunks)
prompt = f"""[INST]
You are a legal aid assistant for Palestinian citizens.
Use ONLY the following legal articles to answer. Always add a note to consult a real lawyer.
Legal context:
{context}
User question: {user_question}
[/INST]"""
return llm(prompt, max_new_tokens=400, temperature=0.2)[0]["generated_text"]
QLoRA fine-tune on data/processed/training_qa.jsonl using the script in model/finetune.py. See Setup step 4.
Recommended base models:
| Model | Best for |
|---|---|
Equall/Saul-7B-Instruct-v1 | English legal text, strong base |
mistralai/Mistral-7B-Instruct-v0.2 | General multilingual, easy fine-tune |
inceptionai/jais-13b-chat | Arabic-first, best for Arabic users |
FreedomIntelligence/AceGPT-7B | Arabic-optimized alternative |
The model is trained on all 121 articles of the Basic Law. High-priority articles for the legal aid use case:
| Article | Topic |
|---|---|
| 9 | Equality before the law β no discrimination |
| 11 | Personal freedom β unlawful arrest |
| 12 | Rights of detained persons β right to a lawyer |
| 13 | Prohibition of torture β confessions under duress are void |
| 14 | Presumption of innocence |
| 15 | No collective punishment |
| 17 | Home is inviolable β search warrants required |
| 21 | Property rights β expropriation only with fair compensation |
| 23 | Right to housing |
| 24 | Right to free education |
| 25 | Right to work β labor protections |
| 30 | Right to access courts |
| 110β113 | State of emergency rights |
The most powerful demo scenario:
"My landlord verbally told me I have 3 days to leave. What are my rights?"
Expected flow:
evictionYou are a legal aid assistant helping Palestinian citizens understand their rights
under the Palestinian Basic Law (2003, amended 2005).
Rules:
- Answer ONLY based on the provided legal context
- Use plain, simple language (Grade 8 reading level)
- Always end with: "This is general legal information. For your specific situation, consult a licensed Palestinian lawyer or visit a legal aid center."
- Never give advice that could harm the user
- If the answer is not in the provided articles, say so clearly
- Support both Arabic and English responses
The pipeline is designed to be extended. To add a new law:
data/raw/parse_articles() in the pipeline to handle its formatARTICLE_TOPICSRecommended next laws to add:
transformers>=4.40.0
peft>=0.10.0
trl>=0.8.0
bitsandbytes>=0.43.0
accelerate>=0.29.0
sentence-transformers>=2.7.0
chromadb>=0.5.0
faster-whisper>=1.0.0
fastapi>=0.111.0
uvicorn>=0.29.0
reportlab>=4.1.0
pypdf>=4.2.0
datasets>=2.19.0
torch>=2.2.0
requests>=2.31.0
python-multipart>=0.0.9
This system provides general legal information only, not legal advice. It is not a substitute for a qualified Palestinian lawyer. Always direct users to professional legal help for serious matters.
MIT License β free to use, modify, and distribute.
A voice-based AI legal assistant that helps Palestinian citizens understand their rights under the Palestinian Basic Law (2003, amended 2005), auto-fill legal forms, and find nearby legal aid clinics β available in Arabic and English.
Most people who face legal problems β eviction, labor disputes, custody issues β have no access to a lawyer. This project puts a legal expert in their pocket, for free.
The system works like this:
legal-aid-palestine/
β
βββ data/
β βββ raw/
β β βββ palestine_basic_law_en.txt # Full text from constituteproject.org
β βββ processed/
β β βββ articles.jsonl # Parsed articles (id, title, text)
β β βββ training_qa.jsonl # Fine-tuning Q&A pairs
β β βββ rag_chunks.jsonl # RAG vector store chunks
β βββ forms/
β βββ templates/ # PDF form templates
β
βββ pipeline/
β βββ palestine_law_pipeline.py # Fetch β parse β generate Q&A + RAG chunks
β
βββ model/
β βββ finetune.py # QLoRA fine-tuning script
β βββ inference.py # Local inference wrapper
β βββ rag.py # ChromaDB vector store + retrieval
β
βββ app/
β βββ main.py # FastAPI backend
β βββ transcribe.py # Whisper speech-to-text
β βββ intent.py # Legal intent classifier
β βββ form_filler.py # PDF auto-fill
β βββ referral.py # Nearby clinic lookup
β
βββ frontend/
β βββ index.html # Simple voice UI (Arabic + English)
β
βββ requirements.txt
βββ .env.example
βββ README.md
| Layer | Technology | Why |
|---|---|---|
| Speech-to-text | faster-whisper | Best Arabic transcription, runs offline |
| Legal reasoning | SaulLM-7B or Mistral-7B (QLoRA fine-tuned) | Open source, no API dependency |
| Vector store | ChromaDB | Lightweight, local, easy to set up |
| Embeddings | sentence-transformers/paraphrase-multilingual-mpnet-base-v2 | Arabic + English support |
| Backend | FastAPI | Fast, async, easy to deploy |
| PDF forms | reportlab + pypdf | Generate and fill Arabic-ready PDFs |
| Frontend | Plain HTML + JS | Works on any device, low bandwidth |
git clone https://github.com/your-username/legal-aid-palestine
cd legal-aid-palestine
pip install -r requirements.txt
# Fetch, parse, and generate training data from the Palestinian Basic Law
python pipeline/palestine_law_pipeline.py
# Output files:
# data/processed/articles.jsonl β structured articles
# data/processed/training_qa.jsonl β Q&A pairs for fine-tuning
# data/processed/rag_chunks.jsonl β chunks for vector DB
python model/rag.py --build
# Embeds all RAG chunks into ChromaDB
# Stored locally at: ./chroma_db/
Only needed if you want a fully custom model. Skip this for a quick demo β just use SaulLM-7B directly with RAG.
python model/finetune.py \
--base_model "Equall/Saul-7B-Instruct-v1" \
--data "data/processed/training_qa.jsonl" \
--output_dir "./legal-model-lora" \
--epochs 3
Requires a GPU with 8GB+ VRAM. Works on Google Colab T4.
uvicorn app.main:app --reload --port 8000
# Open: http://localhost:8000
The Palestinian Basic Law (2003, amended 2005) is sourced from:
These are public domain government texts. No copyright restrictions.
constituteproject.org
β
βΌ
fetch_constitution()
β Raw HTML/text
βΌ
parse_articles()
β List of {id, title, text}
βΌ
ββββββ΄βββββ
βΌ βΌ
generate_ generate_
qa_pairs() rag_chunks()
β β
βΌ βΌ
training_ rag_
qa.jsonl chunks.jsonl
{"instruction": "Under Palestinian law, what are my rights regarding personal freedom and unlawful arrest?", "response": "Under Article 11 of the Palestinian Basic Law: Personal freedom is a natural right, shall be guaranteed and may not be violated. It is unlawful to arrest, search, imprison, restrict the freedom, or prevent the movement of any person, except by judicial order in accordance with the provisions of the law. Note: This is general legal information. For specific legal advice, please consult a qualified Palestinian lawyer.", "source": "Palestine Basic Law 2003 (rev. 2005)", "article": "Article 11"}
{"instruction": "What does Article 14 of the Palestinian Basic Law say about presumption of innocence and right to a lawyer?", "response": "According to Article 14 of the Palestinian Basic Law (2003, amended 2005): An accused person is considered innocent until proven guilty in a court of law. Any person accused in a criminal case shall be represented by a lawyer.", "source": "Palestine Basic Law 2003 (rev. 2005)", "article": "Article 14"}
{"id": "palestine_basic_law_Article_11", "text": "Article 11 (TITLE TWO β PUBLIC RIGHTS AND LIBERTIES): Personal freedom is a natural right, shall be guaranteed and may not be violated...", "metadata": {"source": "Palestine Basic Law 2003", "article": "Article 11", "title": "TITLE TWO β PUBLIC RIGHTS AND LIBERTIES", "keywords": ["arrest", "freedom", "detention", "judicial order"]}}
Use SaulLM-7B-Instruct directly. Feed it the relevant Basic Law articles at inference time via RAG. No training needed.
# model/inference.py
from transformers import pipeline
from model.rag import retrieve
llm = pipeline("text-generation", model="Equall/Saul-7B-Instruct-v1")
def answer(user_question):
chunks = retrieve(user_question, top_k=3)
context = "\n\n".join(chunks)
prompt = f"""[INST]
You are a legal aid assistant for Palestinian citizens.
Use ONLY the following legal articles to answer. Always add a note to consult a real lawyer.
Legal context:
{context}
User question: {user_question}
[/INST]"""
return llm(prompt, max_new_tokens=400, temperature=0.2)[0]["generated_text"]
QLoRA fine-tune on data/processed/training_qa.jsonl using the script in model/finetune.py. See Setup step 4.
Recommended base models:
| Model | Best for |
|---|---|
Equall/Saul-7B-Instruct-v1 | English legal text, strong base |
mistralai/Mistral-7B-Instruct-v0.2 | General multilingual, easy fine-tune |
inceptionai/jais-13b-chat | Arabic-first, best for Arabic users |
FreedomIntelligence/AceGPT-7B | Arabic-optimized alternative |
The model is trained on all 121 articles of the Basic Law. High-priority articles for the legal aid use case:
| Article | Topic |
|---|---|
| 9 | Equality before the law β no discrimination |
| 11 | Personal freedom β unlawful arrest |
| 12 | Rights of detained persons β right to a lawyer |
| 13 | Prohibition of torture β confessions under duress are void |
| 14 | Presumption of innocence |
| 15 | No collective punishment |
| 17 | Home is inviolable β search warrants required |
| 21 | Property rights β expropriation only with fair compensation |
| 23 | Right to housing |
| 24 | Right to free education |
| 25 | Right to work β labor protections |
| 30 | Right to access courts |
| 110β113 | State of emergency rights |
The most powerful demo scenario:
"My landlord verbally told me I have 3 days to leave. What are my rights?"
Expected flow:
evictionYou are a legal aid assistant helping Palestinian citizens understand their rights
under the Palestinian Basic Law (2003, amended 2005).
Rules:
- Answer ONLY based on the provided legal context
- Use plain, simple language (Grade 8 reading level)
- Always end with: "This is general legal information. For your specific situation, consult a licensed Palestinian lawyer or visit a legal aid center."
- Never give advice that could harm the user
- If the answer is not in the provided articles, say so clearly
- Support both Arabic and English responses
The pipeline is designed to be extended. To add a new law:
data/raw/parse_articles() in the pipeline to handle its formatARTICLE_TOPICSRecommended next laws to add:
transformers>=4.40.0
peft>=0.10.0
trl>=0.8.0
bitsandbytes>=0.43.0
accelerate>=0.29.0
sentence-transformers>=2.7.0
chromadb>=0.5.0
faster-whisper>=1.0.0
fastapi>=0.111.0
uvicorn>=0.29.0
reportlab>=4.1.0
pypdf>=4.2.0
datasets>=2.19.0
torch>=2.2.0
requests>=2.31.0
python-multipart>=0.0.9
This system provides general legal information only, not legal advice. It is not a substitute for a qualified Palestinian lawyer. Always direct users to professional legal help for serious matters.
MIT License β free to use, modify, and distribute.