CoolFace
Apppublic

ramouch/Tunisian-Encoder

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
README.md181 linesDownload Raw Back to root
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