Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,87 +1,126 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: π
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
-
short_description:
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# π
|
| 13 |
|
| 14 |
-
A
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
---
|
| 19 |
|
| 20 |
-
##
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
| **NLLB 600M** | `facebook/nllb-200-distilled-600M` | ~600 MB | Fast general translation (200+ languages) |
|
| 25 |
-
| **NLLB 1.3B** | `facebook/nllb-200-distilled-1.3B` | ~1.4 GB | Higher quality general translation |
|
| 26 |
-
| **MADLAD 3B** | `google/madlad400-3b-mt` | ~3.1 GB | Multilingual translation across 400+ languages |
|
| 27 |
-
| **Sunbird NLLB 3.3B** | `Sunbird/translate-nllb-3.3b-salt` | ~3.8 GB | Ugandan & East African languages (Luganda, Acholi, Runyankole, Swahili, etc.) |
|
| 28 |
|
| 29 |
---
|
| 30 |
|
| 31 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
###
|
| 42 |
```bash
|
| 43 |
GET /
|
| 44 |
```
|
| 45 |
|
| 46 |
-
### Translate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
```bash
|
| 48 |
POST /translate
|
| 49 |
Content-Type: application/json
|
| 50 |
|
| 51 |
{
|
| 52 |
-
"
|
| 53 |
-
"text": "
|
| 54 |
-
"
|
| 55 |
-
"
|
|
|
|
| 56 |
}
|
| 57 |
```
|
| 58 |
|
| 59 |
---
|
| 60 |
|
| 61 |
-
##
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
-
```
|
| 66 |
-
#
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
|
|
|
|
| 71 |
```
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
This
|
| 76 |
|
|
|
|
| 77 |
```bibtex
|
| 78 |
@inproceedings{moslem-etal-2026-afrinllb,
|
| 79 |
title = "{A}fri{NLLB}: Efficient Translation Models for African Languages",
|
| 80 |
author = "Moslem, Yasmin and Wassie, Aman Kassahun and Gizachew, Amanuel",
|
| 81 |
booktitle = "Proceedings of the Seventh Workshop on African Natural Language Processing (AfricaNLP)",
|
| 82 |
-
month = mar,
|
| 83 |
year = "2026",
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Translation Engine API
|
| 3 |
emoji: π
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
+
short_description: Multi-model Translation API powered by CTranslate2
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# π Translation Engine API
|
| 13 |
|
| 14 |
+
A high-performance, multi-engine Translation API built with **FastAPI** and **Scalar**.
|
| 15 |
|
| 16 |
+
This Space serves local CPU-optimized machine learning models alongside cloud API providers. It is designed to act as the primary translation backend for an upcoming **Django web application**, but functions completely as a **standalone REST API**.
|
| 17 |
|
| 18 |
---
|
| 19 |
|
| 20 |
+
## Interactive API Documentation
|
| 21 |
|
| 22 |
+
Interactive Scalar documentation is hosted directly on the root endpoint:
|
| 23 |
+
π **[Open API Docs & Sandbox](/scalar)**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
---
|
| 26 |
|
| 27 |
+
## Available Translation Engines
|
| 28 |
+
|
| 29 |
+
### 1. Local CPU Models (Offline & Private)
|
| 30 |
+
Local models are automatically downloaded, quantized to **INT8 / GGUF** format, and cached in ephemeral storage for fast CPU execution with minimal RAM footprint.
|
| 31 |
+
|
| 32 |
+
| Model ID | Provider Name | Base Weights | Precision | Target Languages / Features |
|
| 33 |
+
| :--- | :--- | :--- | :--- | :--- |
|
| 34 |
+
| `nllb` | **NLLB-200 (600M)** | Meta `nllb-200-distilled-600M` | `int8` | Fast general translation (200+ languages) |
|
| 35 |
+
| `nllb_1_3b` | **NLLB-200 (1.3B)** | Meta `nllb-200-distilled-1.3B` | `int8` | Higher accuracy general translation |
|
| 36 |
+
| `afrinllb` | **AfriNLLB (600M)** | `AfriNLP/AfriNLLB-12enc-12dec-full-ft-kd` | `int8` | Knowledge-distilled for 15+ African languages |
|
| 37 |
+
| `madlad` | **MADLAD-400 (3B)** | `google/madlad400-3b-mt` | `int8` | Multilingual translation across 400+ languages |
|
| 38 |
+
| `swahili_gemma` | **Swahili Gemma (1B)** | `CraneAILabs/swahili-gemma-1b-GGUF` | `Q4_K_M` | Fine-tuned for English β Swahili translation |
|
| 39 |
|
| 40 |
+
### 2. Cloud API Engines (Bring-Your-Own-Key)
|
| 41 |
+
Cloud API providers allow accessing large language models. You can either configure environment variables on the server or pass your API key dynamically in the JSON payload per request.
|
| 42 |
+
|
| 43 |
+
| Provider ID | Provider Name | Default Model | Required Client Key |
|
| 44 |
+
| :--- | :--- | :--- | :--- |
|
| 45 |
+
| `gemini` | **Google Gemini** | `gemini-1.5-flash` | `api_key` (Gemini API Key) |
|
| 46 |
+
| `groq` | **Groq LLaMA** | `llama-3.3-70b-versatile` | `api_key` (Groq API Key) |
|
| 47 |
+
| `groq_qwen` | **Groq Qwen** | `qwen-2.5-coder-32b` | `api_key` (Groq API Key) |
|
| 48 |
|
| 49 |
---
|
| 50 |
|
| 51 |
+
## How to Use the API
|
| 52 |
|
| 53 |
+
### 1. Check Available Engines
|
| 54 |
```bash
|
| 55 |
GET /
|
| 56 |
```
|
| 57 |
|
| 58 |
+
### 2. Translate via Local Model (e.g., AfriNLLB)
|
| 59 |
+
```bash
|
| 60 |
+
POST /translate
|
| 61 |
+
Content-Type: application/json
|
| 62 |
+
|
| 63 |
+
{
|
| 64 |
+
"text": "Is it not a beautiful Tuesday morning?",
|
| 65 |
+
"source": "eng_Latn",
|
| 66 |
+
"target": "swh_Latn",
|
| 67 |
+
"engine": "afrinllb"
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### 3. Translate via Cloud API (Passing API Key dynamically)
|
| 72 |
+
If no server-side API key is set, clients can supply their own key directly:
|
| 73 |
+
|
| 74 |
```bash
|
| 75 |
POST /translate
|
| 76 |
Content-Type: application/json
|
| 77 |
|
| 78 |
{
|
| 79 |
+
"provider": "gemini",
|
| 80 |
+
"text": "Good morning, how can I help you today?",
|
| 81 |
+
"src": "en",
|
| 82 |
+
"tgt": "sw",
|
| 83 |
+
"api_key": "YOUR_GEMINI_API_KEY_HERE"
|
| 84 |
}
|
| 85 |
```
|
| 86 |
|
| 87 |
---
|
| 88 |
|
| 89 |
+
## Environment Variables Configuration
|
| 90 |
|
| 91 |
+
If you are hosting this Space yourself or running it locally, you can set optional environment keys in Space Settings:
|
| 92 |
|
| 93 |
+
```env
|
| 94 |
+
# Optional Cloud Keys (If set, clients do not need to provide their own keys)
|
| 95 |
+
GEMINI_API_KEY=your_gemini_key
|
| 96 |
+
GROQ_API_KEY=your_groq_key
|
| 97 |
|
| 98 |
+
# CTranslate2 / CPU Threading Controls
|
| 99 |
+
OMP_NUM_THREADS=8
|
| 100 |
+
CT2_COMPUTE_TYPE=int8
|
| 101 |
```
|
| 102 |
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## π Citations & Credits
|
| 106 |
|
| 107 |
+
This project builds upon open-source research and model checkpoints from the AI community:
|
| 108 |
|
| 109 |
+
### AfriNLLB
|
| 110 |
```bibtex
|
| 111 |
@inproceedings{moslem-etal-2026-afrinllb,
|
| 112 |
title = "{A}fri{NLLB}: Efficient Translation Models for African Languages",
|
| 113 |
author = "Moslem, Yasmin and Wassie, Aman Kassahun and Gizachew, Amanuel",
|
| 114 |
booktitle = "Proceedings of the Seventh Workshop on African Natural Language Processing (AfricaNLP)",
|
|
|
|
| 115 |
year = "2026",
|
| 116 |
+
publisher = "Association for Computational Linguistics"
|
| 117 |
+
}
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### Swahili Gemma
|
| 121 |
+
* Fine-tuned and quantized GGUF weights provided by [Crane AI Labs](https://huggingface.co/CraneAILabs/swahili-gemma-1b-GGUF).
|
| 122 |
+
|
| 123 |
+
### Meta NLLB-200 & Google MADLAD-400
|
| 124 |
+
* Meta AI: *No Language Left Behind: Scaling Human-Centered Machine Translation*
|
| 125 |
+
* Google Research: *MADLAD-400: A Multilingual Machine Translation Dataset and Model*
|
| 126 |
+
```
|