BramVanroy commited on
Commit
4f1e963
β€’
1 Parent(s): 55eb099

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +52 -24
Dockerfile CHANGED
@@ -1,37 +1,65 @@
1
- FROM ubuntu:latest
2
- LABEL authors="Bram Vanroy"
3
 
 
 
 
 
 
4
  ENV DEBIAN_FRONTEND=noninteractive
5
- RUN apt-get -y update \
6
- && apt-get -y install build-essential curl git software-properties-common
7
 
8
- RUN add-apt-repository ppa:deadsnakes/ppa \
9
- && apt-get -y update \
10
- && apt-get -y install python3.10 python3.10-dev python3-pip python3.10-distutils \
11
- && ln -s /usr/bin/python3.10 /usr/bin/python \
 
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- RUN useradd -m -u 1000 user
15
- USER user
16
- ENV HOME /home/user
17
- ENV PATH $HOME/.local/bin:$PATH
18
- ENV HF_HUB_ENABLE_HF_TRANSFER=1
 
 
 
 
 
 
 
 
19
 
20
- WORKDIR $HOME
 
 
21
  RUN git clone https://github.com/BramVanroy/mateo-demo.git
22
- WORKDIR $HOME/mateo-demo
23
 
24
- RUN python -m pip install --no-cache-dir --upgrade pip && python -m pip install --no-cache-dir --upgrade .
 
 
 
25
 
26
  # Pre-download default models
27
- RUN python -c "import comet; from comet import download_model; download_model('Unbabel/wmt22-comet-da')"
28
- RUN python -c "import evaluate; evaluate.load('bleurt', 'BLEURT-20')"
29
- RUN huggingface-cli download bert-base-multilingual-cased model.safetensors tokenizer.json vocab.txt
30
- RUN huggingface-cli download facebook/nllb-200-distilled-600M pytorch_model.bin sentencepiece.bpe.model tokenizer.json
 
 
 
31
 
32
- EXPOSE 7860
33
- HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
34
 
35
- WORKDIR $HOME/mateo-demo/src/mateo_st
 
36
 
37
- CMD ["streamlit", "run", "01_🎈_MATEO.py", "--server.port", "7860", "--server.enableXsrfProtection", "false", "--", "--no_cuda"]
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim-bookworm
 
2
 
3
+ # Metadata as per https://github.com/opencontainers/image-spec/blob/master/annotations.md
4
+ LABEL org.opencontainers.image.authors="Bram Vanroy"
5
+ LABEL org.opencontainers.image.title="MAchine Translation Evaluation Online - Demo"
6
+
7
+ # Avoid prompts from apt
8
  ENV DEBIAN_FRONTEND=noninteractive
 
 
9
 
10
+ # Install dependencies in a single RUN command to reduce image layers
11
+ RUN apt-get update && apt-get install -y --no-install-recommends \
12
+ build-essential \
13
+ curl \
14
+ git \
15
+ && apt-get clean \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # Create a non-root user
19
+ RUN useradd -m -u 1000 mateo_user
20
+ USER mateo_user
21
+ ENV HOME="/home/mateo_user"
22
+
23
+ # Environment variables
24
+ ENV PORT=7860 \
25
+ SERVER="localhost" \
26
+ BASE="" \
27
+ DEMO_MODE="" \
28
+ HF_HUB_ENABLE_HF_TRANSFER=1 \
29
+ PATH="${HOME}/.local/bin:${PATH}" \
30
+ USE_CUDA=false
31
 
32
+ WORKDIR ${HOME}/mateo
33
+
34
+ # Clone the repository
35
  RUN git clone https://github.com/BramVanroy/mateo-demo.git
36
+ WORKDIR mateo-demo
37
 
38
+ # Install Python dependencies with conditional torch installation
39
+ RUN python -m pip install --no-cache-dir --upgrade pip wheel setuptools \
40
+ && python -m pip install --no-cache-dir torch==2.2.1+cpu -f https://download.pytorch.org/whl/torch \
41
+ && python -m pip install --no-cache-dir --upgrade .
42
 
43
  # Pre-download default models
44
+ RUN huggingface-cli download bert-base-multilingual-cased model.safetensors tokenizer.json vocab.txt; \
45
+ huggingface-cli download facebook/nllb-200-distilled-600M pytorch_model.bin sentencepiece.bpe.model tokenizer.json; \
46
+ python -c "import comet; from comet import download_model; download_model('Unbabel/wmt22-comet-da')"; \
47
+ python -c "import evaluate; evaluate.load('bleurt', 'BLEURT-20')"
48
+
49
+ # Expose the port the app runs on
50
+ EXPOSE $PORT
51
 
52
+ # Healthcheck to ensure the service is running
53
+ HEALTHCHECK CMD curl --fail http://$SERVER:$PORT$BASE/_stcore/health || exit 1
54
 
55
+ # Set the working directory to the Streamlit app
56
+ WORKDIR src/mateo_st
57
 
58
+ # Simplify the CMD script with conditional --use_cuda flag
59
+ CMD streamlit run 01_🎈_MATEO.py \
60
+ --server.port $PORT \
61
+ --server.address $SERVER \
62
+ $(if [ -n "$BASE" ]; then echo "--server.baseUrlPath $BASE"; fi) \
63
+ $(if [ "$DEMO_MODE" = "true" ]; then echo "--server.maxUploadSize 1"; fi) \
64
+ -- \
65
+ $(if [ "$DEMO_MODE" = "true" ]; then echo "--demo_mode"; fi)