Sign inSign up

projecteaina/mt-api

Sponsored OSS

By Barcelona Supercomputing Center

Updated about 1 year ago

Machine translation API for serving machine translation models.

Image
API management
Machine learning & AI
0

7.3K

projecteaina/mt-api repository overview

Machine Translation API

Usage

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

How to Configure the Image

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 nameDescriptionDefault valuePossible values
MT_API_CONFIGConfiguration file path/app/config.jsonAny valid file path
MODELS_ROOTModels directory path/app/modelsAny valid directory path
MT_API_DEVICERuntime devicecpuCPU, GPU
MT_API_THREADSMaximum number of parallel translations16Any positive integer
NVIDIA_VISIBLE_DEVICESGPU visibility inside the containerallCheckout possible values at NVIDIA docs
NVIDIA_DRIVER_CAPABILITIESDriver libraries/binaries inside the containerempty or unsetCheckout possible values at NVIDIA docs

Rest API Endpoints

1. Translate text
MethodEndpointDescription
POST/api/v1/translateTranslate text.

Request Parameters:

ParameterTypeDescription
srcstringSource language code (e.g., "es")
tgtstringTarget language code (e.g., "ca")
textstringText to translate (e.g., "Hola cómo estás")
2. Translate batch of text
MethodEndpointDescription
POST/api/v1/translate/batchTranslate batch of texts.

Request Parameters:

ParameterTypeDescription
srcstringSource language code (e.g., "es")
tgtstringTarget language code (e.g., "ca")
textsstringList of texts (e.g., ["Hola", "Cómo estás"])
2. Chcek api health
MethodEndpointDescription
POST/healthCheck the api health, if the api is working correctly.

Example calls

Simple translation

Endpoint for translating a single phrase.

cURL
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."}'
Python
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'])
Batch translation

Endpoint for translating a list of sentences.

cURL
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."]}'
Python
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'])

Tag summary

Content type

Image

Digest

sha256:84d54ecd5

Size

3 GB

Last updated

about 1 year ago

docker pull projecteaina/mt-api

This week's pulls

Pulls:

33

Last week