ramouch/Tunisian-Encoder
0
1---2title: Tunisian Arabic Encoder API3emoji: π§¬4colorFrom: indigo5colorTo: purple6sdk: docker7app_file: app.py8pinned: false9---10 11# πΉπ³ Tunisian Arabic Sentence Encoder API12 13This Space serves an embedding API for Tunisian Arabic medical dialogue using a fine-tuned version of AraBERT. It is designed to encode Tunisian dialect text into vector embeddings suitable for downstream NLP tasks such as similarity search or classification.14 15---16 17## π Features18 19- π₯ Fast inference with a fine-tuned Arabic BERT (`original_model.pt`)20- π¦ REST API with `/encode` endpoint21- π³ Deployable via Docker on Hugging Face Spaces22- π©Ί Designed for semantic search, text matching, and classification in **Tunisian Arabic**23 24---25 26## π Project Structure27 28```29 30.31βββ app.py # FastAPI app with /encode endpoint32βββ encoder.py # Loads and wraps the SentenceTransformer model33βββ original\_model.pt # Fine-tuned SentenceTransformer model34βββ requirements.txt # Python dependencies35βββ Dockerfile # Dockerfile for Hugging Face Spaces36 37```38 39---40 41## π API Endpoints42 43### β
Health Check44 45```46 47GET /48 49````50 51**Response**52```json53{"status": "ok"}54````55 56---57 58### π€ Embedding Text59 60```61POST /encode62Content-Type: application/json63```64 65**Example Request:**66 67```json68{69 "text": "Ψ΄ΩΩΨ© Ψ£ΨΉΨ±Ψ§ΨΆ Ψ’ΩΨ§Ω
Ψ§ΩΨ±ΩΨ¨Ψ©Ψ"70}71```72 73**Example Response:**74 75```json76{77 "embedding": [0.234, -0.982, ...]78}79```80 81---82 83## π¦ Requirements84 85Installed automatically via `requirements.txt`:86 87```txt88fastapi89uvicorn90torch91numpy92sentence-transformers93```94 95---96 97## π§ About the Model98 99The model is a fine-tuned version of [`aubmindlab/bert-base-arabertv2`](https://huggingface.co/aubmindlab/bert-base-arabertv2) using the [SentenceTransformers](https://www.sbert.net/) framework. It was trained on a **Tunisian Arabic medical dialogue dataset**, making it ideal for:100 101* π©Ί Doctor-patient chatbot embedding102* π§ Semantic similarity and clustering103* π Intent recognition and search104 105**Embedding size:** 768106**Format:** PyTorch serialized model (`original_model.pt`)107 108---109 110## π³ Deploy on Hugging Face Spaces (Docker)111 112This app is deployed on Hugging Face Spaces with Docker:113 114```dockerfile115# Use a minimal base image116FROM python:3.9-slim117 118# Create a non-root user for security119RUN useradd -m user120USER user121 122# Set environment variables123ENV HOME=/home/user \124 PATH=/home/user/.local/bin:$PATH \125 PORT=7860126 127# Set the working directory128WORKDIR $HOME/app129 130# Copy requirements and install dependencies in a single RUN command131COPY --chown=user requirements.txt ./132RUN pip install --upgrade pip && \133 pip install -r requirements.txt134 135# Copy application files and the model136COPY --chown=user ./ $HOME/app137 138# Expose the correct port for Hugging Face Spaces139EXPOSE 7860140 141# Run the FastAPI app with uvicorn directly for lightweight deployment142CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]143```144 145---146 147## π§ Local Testing148 149To test locally with Docker:150 151```bash152docker build -t arabic-bert-api .153docker run -p 7860:7860 arabic-bert-api154```155 156---157 158## π Example Python Client159 160```python161import requests162 163url = "http://localhost:7860/encode"164response = requests.post(url, json={"text": "ΨΉΩΨ―Ω ΩΨ¬ΩΨΉΨ© ΩΩ ΨΈΩΨ±Ω"})165print(response.json())166```167 168---169 170## π©βπ» Maintainer171 172**Inherited Games Studio**173π§ [contact@inheritedgames.com](mailto:contact@inheritedgames.com)174π [github.com/inheritedgames](https://github.com/inheritedgames)175π [github.com/RAMA012001](https://github.com/RAMA012001)176 177---178 179## π License180 181MIT License