Spaces:
Running
Running
BramVanroy
commited on
Update Dockerfile
Browse files- Dockerfile +52 -24
Dockerfile
CHANGED
@@ -1,37 +1,65 @@
|
|
1 |
-
FROM
|
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
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
&& rm -rf /var/lib/apt/lists/*
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
ENV
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
WORKDIR $HOME
|
|
|
|
|
21 |
RUN git clone https://github.com/BramVanroy/mateo-demo.git
|
22 |
-
WORKDIR
|
23 |
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
# Pre-download default models
|
27 |
-
RUN
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
HEALTHCHECK CMD curl --fail http
|
34 |
|
35 |
-
|
|
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|