---
title: Modrik
emoji: π΅
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 8501
pinned: false
---
## β¦ Built at SDA Himmah Hackathon 2026
> Participated β Modrik Team
---
```
ββββββββββββββββββββββββββββββββββββββββββββ
β β
β M O D R I K β
β Ω
Ψ―Ψ±Ω β
β β
β Every worker deserves to know their β
β rights. β
β β
ββββββββββββββββββββββββββββββββββββββββββββ
```
**An Arabic-first AI legal assistant for Saudi Labor Law.**
Ask in plain Arabic. Upload your contract. Get an answer cited by article.





---
## β¦ What is Modrik?
Saudi Labor Law spans hundreds of articles across three states β active, amended, and repealed β and most workers never open it until they're already in a dispute.
**Modrik (Ω
Ψ―Ψ±Ω)** lets anyone ask about their rights in plain Arabic, upload their actual contract or case file, and get a personal answer grounded in the specific article that applies β not a generic summary.
> *"ΩΩ ΨΉΩΨ―Ω ΩΨ·Ψ§Ψ¨Ω ΩΨΈΨ§Ω
Ψ§ΩΨΉΩ
ΩΨ"*
> Modrik reads your contract, retrieves the relevant articles β whether still in force, amended, or repealed β and tells you exactly where you stand, citing the law instead of guessing.
---
## β¦ How a question gets answered
```
USER ASKS A QUESTION (+ optional contract / case file)
β
βΌ
βββββββββββββββββββββ
β PII GUARD β redacts Saudi ID / IBAN
β (regex) β before anything is sent
βββββββββββ¬ββββββββββ
β
βββββββββββββββββ΄ββββββββββββββββ
βΌ βΌ
UPLOADED FILE FAISS RETRIEVAL
(txt / pdf extracted) query embedded with
multilingual-e5-large
β top-k matching Labor
Law articles, local
βββββββββββββββββ¬ββββββββββββββββ
βΌ
βββββββββββββββββββββ
β GPT-4o-mini β streamed response,
β (streamed) β cites article numbers,
βββββββββββ¬ββββββββββ flags amended/repealed
βΌ
ANSWER + SOURCES POPOVER
(article matches with similarity %)
```
| Step | What happens |
|------|---------------|
| **Input** | User types in Arabic (or English) and may attach a `.txt`/`.pdf` contract or case document |
| **Privacy guard** | Saudi National ID/Iqama numbers and IBANs are regex-redacted before anything leaves the session |
| **Retrieval** | The query is embedded locally with `multilingual-e5-large` and FAISS searches the Labor Law index (active + amended + repealed) for the top-k matching articles |
| **Generation** | GPT-4o-mini streams a personalized answer, always citing the article number and flagging amended/repealed status |
| **Transparency** | A sources popover shows the exact retrieved articles with similarity scores, plus the contract excerpt actually used |
---
## β¦ Tech stack
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND / UI β
β Streamlit Β· RTL Arabic chat interface β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β core/ β
β β
β ββββββββββββββ βββββββββββββββββ βββββββββββββββ β
β β pii_guard β β file_service β β vector_storeβ β
β β regex β β PyMuPDF β β FAISS, β β
β β redaction β β txt / pdf β β local, free β β
β ββββββββββββββ βββββββββββββββββ ββββββββ¬βββββββ β
β β β
β βββββββββΌββββββββ β
β β ai_service β β
β β OpenAI streamβ β
β βββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
| Layer | Technology |
|-------|-----------|
| LLM | OpenAI GPT-4o-mini, streamed token-by-token |
| Embeddings | `intfloat/multilingual-e5-large`, run locally (see below) |
| Vector store | FAISS (`IndexFlatIP` over normalized vectors) |
| PDF / text extraction | PyMuPDF (`fitz`) |
| Law ingestion | pandas + openpyxl β Excel β smart-chunked articles |
| Privacy | regex-based PII redaction (Saudi ID/Iqama, IBAN) |
| UI | Streamlit, RTL layout, custom CSS, IBM Plex Sans Arabic |
| Deployment | Docker / docker-compose, Hugging Face Spaces |
---
## β¦ Why this embedding model
Most RAG demos default straight to an embedding API. Modrik instead runs `multilingual-e5-large` **locally** β the multilingual E5 model β picked after comparing leading multilingual embedding models against published Arabic retrieval benchmarks (MIRACL, MTEB), where it consistently ranks among the strongest open models for Arabic semantic search. That matters here specifically: Saudi Labor Law articles are dense, formal legal Arabic, not casual text.
The practical upside: embedding has zero per-query API cost, and the index β active, amended, and repealed articles β is pre-warmed at container startup, so retrieval is instant from the first question.
---
## β¦ Smart law ingestion
Saudi Labor Law isn't one flat document β articles get amended or repealed, and the old text still matters for context. `scripts/ingest_labor_law.py` ingests three separate sources and tags each one:
| Source | Tag shown to the model |
|--------|------------------------|
| `labor_law_active.xlsx` | β
ΩΨΈΨ§Ω
ΩΨ΄Ψ· ΩΨ³Ψ§Ψ±Ω ΨΨ§ΩΩΨ§Ω |
| `labor_law_amended.xlsx` | β οΈ ΩΨ°Ω Ψ§ΩΩ
Ψ§Ψ―Ψ© Ω
ΨΉΨ―ΩΩΨ© |
| `labor_law_repealed.xlsx` | π« ΩΨ°Ω Ψ§ΩΩ
Ψ§Ψ―Ψ© Ω
ΩΨΊΨ§Ψ© ΩΩΨ§ ΨͺΩΨ·Ψ¨ΩΩΩ ΨΨ§ΩΩΨ§Ω |
Articles longer than 600 characters are split on definition markers or paragraph breaks first, then merged back up to the chunk limit β so no sub-chunk ever loses its article header or keyword context.
---
## β¦ Project structure
```
Modrik/
β
βββ app.py β Streamlit entry point (chat UI, RTL Arabic)
βββ core/
β βββ ai_service.py β OpenAI streaming + system prompt
β βββ file_service.py β txt/pdf extraction + chunking
β βββ pii_guard.py β Saudi ID / IBAN redaction
β βββ vector_store.py β FAISS index, embed/retrieve
βββ scripts/
β βββ ingest_labor_law.py β builds the FAISS index from Excel sources
βββ tests/
β βββ test_pipeline.py β full unit test suite
βββ data/ β active / amended / repealed Labor Law (Excel)
βββ index/ β FAISS index + chunks (generated)
βββ assets/ β logo
βββ Dockerfile / docker-compose.yml / entrypoint.sh
βββ requirements.txt
```
---
## β¦ Tests
Every public function ships with a test: chunking edge cases, `.txt`/`.pdf` extraction (PDF mocked via `fitz`), the OpenAI streaming contract, vector store retrieval, and every PII redaction pattern.
```bash
python -m pytest tests/ -v
```
---
## β¦ Privacy by default
Before any text β typed or uploaded β reaches OpenAI or gets logged, `core/pii_guard.py` strips Saudi National ID/Iqama numbers and IBANs with a regex pass, replaces them with `[Ψ±ΩΩ
ΩΩΩΨ©]` / `[Ψ±ΩΩ
IBAN]`, and tells the user how many were redacted. No opt-in required, no configuration needed.
---
## β¦ Quick start
### Requirements
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running
- An OpenAI API key
### 1 β Copy the env file and add your key
```bash
cp .env.example .env
```
Open `.env` and fill in your key:
```
OPENAI_API_KEY=sk-...
```
### 2 β Build and start
```bash
docker-compose up --build
```
On first run, the FAISS index is built automatically (~1-2 minutes). Subsequent starts are instant.
### 3 β Open in browser
```
http://localhost:8501
```
### SSL error on corporate / university networks
```
SSLError: certificate verify failed
```
This is caused by a firewall or SSL-inspecting proxy. The fix is already included in the `Dockerfile` β no extra steps needed.
### Useful commands
```bash
# Stream logs
docker-compose logs -f
# Stop the project
docker-compose down
# Rebuild after code or requirements.txt changes
docker-compose up --build
# Run the test suite
python -m pytest tests/ -v
```
---
## β¦ Roadmap
| Status | Feature |
|--------|---------|
| β
| RAG over active / amended / repealed Labor Law articles |
| β
| Contract & case file upload (`.txt`/`.pdf`) with personalized analysis |
| β
| Automatic PII redaction (Saudi ID, IBAN) |
| β
| Source transparency β article + similarity score popover |
| β
| Full automated test suite |
| β
| Dockerized, one-command run |
| π | More legal domains beyond Labor Law |
| π | Multi-turn case memory across sessions |
| π | Export consultation as PDF |
---
*Every worker deserves to know where they stand.*