Machine translation API for serving machine translation models.
7.3K
To start up projecteaina/mt-api.
docker run -p 8000:8000 -v ./models:/app/models projecteaina/mt-api:latest
NOTE: --load argument is used to prevent downloading all the models, by default it will load only ca-es es-ca. If you need to load all the models you can use --load all
To start up projecteaina/mt-api without internet connectivity (load models from local)
docker run -p 8000:8000 -e HF_HUB_OFFLINE=True -v ./models:/app/models projecteaina/mt-api:latest
NOTE: How to download models documentation is available on Github
Some configuration options are important when starting up this component. The following is a list of environment variables that you can set (e.g. when starting the docker image):
| Variable name | Description | Default value | Possible values |
|---|---|---|---|
| MT_API_CONFIG | Configuration file path | /app/config.json | Any valid file path |
| MODELS_ROOT | Models directory path | /app/models | Any valid directory path |
| MT_API_DEVICE | Runtime device | cpu | CPU, GPU |
| MT_API_THREADS | Maximum number of parallel translations | 16 | Any positive integer |
| NVIDIA_VISIBLE_DEVICES | GPU visibility inside the container | all | Checkout possible values at NVIDIA docs |
| NVIDIA_DRIVER_CAPABILITIES | Driver libraries/binaries inside the container | empty or unset | Checkout possible values at NVIDIA docs |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/translate | Translate text. |
Request Parameters:
| Parameter | Type | Description |
|---|---|---|
| src | string | Source language code (e.g., "es") |
| tgt | string | Target language code (e.g., "ca") |
| text | string | Text to translate (e.g., "Hola cómo estás") |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/translate/batch | Translate batch of texts. |
Request Parameters:
| Parameter | Type | Description |
|---|---|---|
| src | string | Source language code (e.g., "es") |
| tgt | string | Target language code (e.g., "ca") |
| texts | string | List of texts (e.g., ["Hola", "Cómo estás"]) |
| Method | Endpoint | Description |
|---|---|---|
| POST | /health | Check the api health, if the api is working correctly. |
Endpoint for translating a single phrase.
curl --location --request POST 'http://127.0.0.1:8000/api/v1/translate' \
--header 'Content-Type: application/json' \
--data-raw '{"src":"ca", "tgt":"es", "text":"c'\''Això es una prova."}'
import httpx
translate_service_url = "http://127.0.0.1:8000/api/v1/translate"
json_data ={"src":"ca", "tgt":"es", "text":''Això es una prova."}
r = httpx.post(translate_service_url, json=json_data)
response = r.json()
print("Translation:", response['translation'])
Endpoint for translating a list of sentences.
curl --location --request POST 'http://127.0.0.1:8000/api/v1/translate/batch' \
--header 'Content-Type: application/json' \
--data-raw '{"src":"ca", "tgt":"es", "texts":["Bon dia", "això es una prova."]}'
import httpx
translate_service_url = "http://127.0.0.1:8001/api/v1/translate/batch"
json_data = {'src':'ca', 'tgt':'es', 'texts':["Bon dia", "això es una prova."]}
r = httpx.post(translate_service_url, json=json_data)
response = r.json()
print("Translation:", response['translation'])
Content type
Image
Digest
sha256:84d54ecd5…
Size
3 GB
Last updated
about 1 year ago
docker pull projecteaina/mt-apiPulls:
33
Last week