---
title: Morocco Traffic Law RAG
emoji: 🇲🇦
colorFrom: red
colorTo: yellow
sdk: streamlit
sdk_version: 1.55.0
app_file: src/app.py
pinned: false
---
# Morocco Traffic Law RAG
This project implements a Retrieval-Augmented Generation (RAG) system for the Moroccan traffic law.
The system processes the official traffic law PDF, extracts structured legal articles, stores them in a SQLite database, builds a FAISS vector index, and answers user questions with citations to the relevant legal provisions.
The project demonstrates how to build a production-style AI application combining document processing, semantic search, large language models, and containerized deployment.
System Architecture
Document ingestion (PDF)
↓
Text extraction and preprocessing
↓
Structured storage in SQLite (chapters → articles)
↓
Vector embeddings generation
↓
FAISS vector index construction
↓
Hybrid retrieval (vector search + keyword search)
↓
LLM answer generation (Gemini)
↓
FastAPI backend
↓
Streamlit web interface
The entire system can be deployed using Docker.
Key Features
Structured extraction of Moroccan traffic law articles
Hybrid retrieval using FAISS vector search and SQLite FTS keyword search
Multilingual query support (Arabic and French)
LLM-generated answers grounded in legal text
Citation of relevant articles in responses
FastAPI backend API
Streamlit interactive interface
Dockerized deployment
Project Structure
morocco-traffic-law-rag/
artifacts/
traffic_law.db
law.index
law_meta.json
data/
52_05_traffic_law.pdf
docker/
Dockerfile.api
Dockerfile.ui
src/
api.py
app.py
build_db.py
build_index.py
chat.py
ingest_pdf_ocr.py
docker-compose.yml
Makefile
requirements.txt
README.md
.env.example
Requirements
The recommended way to run the project is using Docker.
You will also need a Gemini API key.
Create the environment file:
cp .env.example .env
Then edit .env and add your key:
GEMINI_API_KEY=your_api_key_here
Running with Docker
Build and start the system:
d …