diff --git a/Dockerfile b/Dockerfile index 9b6bbef..dfaf8f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,18 @@ FROM python:3.8.14-slim-buster RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* - + WORKDIR /app -RUN pip3 install --upgrade pip - COPY ./requirements.txt ./requirements.txt +COPY . /app # Install package from source code -RUN pip3 install -r ./requirements.txt +RUN pip install --upgrade pip && \ + pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html && \ + pip install -r requirements.txt + +EXPOSE 6060 -EXPOSE 5001 +# Command to start the server +CMD ["python", "-m", "nllb_serve"] \ No newline at end of file diff --git a/README.md b/README.md index bfa2d9f..d4f4025 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ nllb-serve -h python -m nllb_serve -h ``` +## Docker + + docker build -t nllb-serve-cpu . + docker run -p 6060:6060 --name nllb-cpu-trad nllb-serve-cpu + ## Start server ```bash @@ -131,6 +136,9 @@ options: Batch size; number of sentences (default: 10) ``` +## Additional +If you want to use this server to translate web pages with the Firefox/Chrome browser, you can use the extension [linguist-NLLB-translator](https://github.com/MoonDragon-MD/linguist-NLLB-translator) + ## License The code and model weights carry different licenses. diff --git a/nllb_serve/app.py b/nllb_serve/app.py index 60b26f9..6e236d3 100644 --- a/nllb_serve/app.py +++ b/nllb_serve/app.py @@ -18,8 +18,8 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer from . import log, DEF_MODEL_ID - -device = torch.device(torch.cuda.is_available() and 'cuda' or 'cpu') +os.environ['CUDA_VISIBLE_DEVICES'] = '' +device = torch.device('cpu') log.info(f'torch device={device}') #DEF_MODEL_ID = "facebook/nllb-200-distilled-600M" diff --git a/requirements.txt b/requirements.txt index edaf7a5..eb5fb00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ -transformers>=4.21 +torch==1.13.1+cpu +transformers==4.37.0 Flask==3.0.2 Werkzeug>=3.0.0 -torch>=1.12 -gunicorn +gunicorn==20.1.0 gevent sentence-splitter +sentencepiece==0.1.99