arindae commited on
Commit
43d1ec9
Β·
verified Β·
1 Parent(s): d90a0af

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +76 -37
README.md CHANGED
@@ -1,87 +1,126 @@
1
  ---
2
- title: Translator Model API
3
  emoji: 🌍
4
  colorFrom: indigo
5
  colorTo: green
6
  sdk: docker
7
  app_port: 7860
8
  pinned: false
9
- short_description: Fast CPU-optimized Translation API powered by CTranslate2
10
  ---
11
 
12
- # 🌍 Translator Model API
13
 
14
- A lightweight, high-performance Translation API built with **FastAPI** and powered by **CTranslate2 (INT8)** for fast, memory-efficient CPU inference.
15
 
16
- Models are automatically fetched from Hugging Face on container startup and converted to CTranslate2 INT8 format to minimize RAM consumption and maximize CPU execution throughput.
17
 
18
  ---
19
 
20
- ## πŸš€ Supported Models
21
 
22
- | Model Name | Original Source | CT2 INT8 Size | Primary Use Case |
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
- ## ⚑ Performance Highlights
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- - **CTranslate2 INT8 Quantization:** Reduces weight footprint by ~75% and speeds up token generation by up to 4–8x on CPU compared to standard PyTorch FP32/FP16 models.
34
- - **OpenMP Multi-threading:** Configured to parallelize generation across available CPU cores.
35
- - **Safetensors Support:** Automatically handles Hugging Face `.safetensors` weights during startup conversion.
 
 
 
 
 
36
 
37
  ---
38
 
39
- ## πŸ› οΈ API Usage
40
 
41
- ### Health Check
42
  ```bash
43
  GET /
44
  ```
45
 
46
- ### Translate Text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  ```bash
48
  POST /translate
49
  Content-Type: application/json
50
 
51
  {
52
- "model": "sunbird-nllb-3.3b",
53
- "text": "Hello, how are you today?",
54
- "src_lang": "eng_Latn",
55
- "tgt_lang": "lug_Latn"
 
56
  }
57
  ```
58
 
59
  ---
60
 
61
- ## 🐳 Local Development (Docker)
62
 
63
- To build and test the container locally:
64
 
65
- ```bash
66
- # Build Docker image
67
- docker build -t translator-api .
 
68
 
69
- # Run Docker container mapping port 7860
70
- docker run -p 7860:7860 -v $(pwd)/data:/data translator-api
 
71
  ```
72
 
73
- ## πŸ“œ Citation & Credits
 
 
74
 
75
- This Space utilizes [AfriNLLB](https://huggingface.co/AfriNLP/AfriNLLB-12enc-12dec-full-ft-kd) developed by AfriNLP:
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
- address = "Rabat, Morocco",
85
- publisher = "Association for Computational Linguistics",
86
- url = "https://openreview.net/forum?id=hVJZNUZBur"
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
+ ```