How to Deploy Hugging Face Models in a Docker Container

This is the repository for the tutorial on how to deploy Hugging Face models in a Docker container and to expose it as a web service endpoint using Flask. The tutorial is available on this blog post.


To use the translation service, you need to have Docker installed. The best way to install it is by installing Docker Desktop of your local computer.

The next step is to clone this repository:

git clone

Finally, you only have to run this Make command to build the Docker image:

make build

That will create the Docker image from which you will be able to create a container using Docker Decktop.

Refer to this blog post for detailed information about how it works.

How to use

Web Service Endpoints

Once you have the container running, you can use the web service endpoints to translate text from English to French and vice-versa. The two endpoints are:

  • /translate/en/fr
  • /translate/fr/en

Then you can test the web service endpoints using curl:

curl http://localhost:6000/translate/en/fr/ POST -H "Content-Type: application/json" -d '{"en_text":"Hello World!"}'

The output should be:

  "fr_text": "Bonjour le monde!"
curl http://localhost:6000/translate/fr/en/ POST -H "Content-Type: application/json" -d '{"fr_text":"Bonjour le monde!"}'

The output should be:

  "en_text": "Hello world!"