Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nllb-serve-slim #26

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions nllb_serve/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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