Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +25 -45
Dockerfile
CHANGED
|
@@ -1,62 +1,42 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
# Déps système minimales
|
| 4 |
-
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
WORKDIR /app
|
| 12 |
-
COPY requirements.txt ./requirements.txt
|
| 13 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
-
|
| 15 |
-
# (Optionnel mais conseillé) pré-télécharger les modèles pour éviter un cold start trop long
|
| 16 |
-
RUN python - <<'PY'\n\
|
| 17 |
-
from transformers import pipeline\n\
|
| 18 |
-
print('Downloading XLM-R sentiment...')\n\
|
| 19 |
-
pipeline('sentiment-analysis', model='cardiffnlp/twitter-xlm-roberta-base-sentiment')\n\
|
| 20 |
-
print('Done.')\n\
|
| 21 |
-
PY
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
# IMPORTANT : utiliser le port fourni par HF Spaces
|
| 27 |
-
ENV PORT=7860
|
| 28 |
-
EXPOSE 7860
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
# Déps système minimales
|
| 35 |
-
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
WORKDIR /app
|
| 43 |
-
COPY requirements.txt ./requirements.txt
|
| 44 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
PY
|
| 53 |
|
| 54 |
-
# Copie de l’app
|
| 55 |
-
COPY app.py ./app.py
|
| 56 |
|
| 57 |
-
|
| 58 |
ENV PORT=7860
|
| 59 |
EXPOSE 7860
|
| 60 |
|
| 61 |
-
|
| 62 |
-
CMD [ "sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT}" ]
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Dépendances système minimales
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
+
git \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 11 |
+
PYTHONUNBUFFERED=1 \
|
| 12 |
+
TRANSFORMERS_CACHE=/models \
|
| 13 |
+
HF_HOME=/models
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
WORKDIR /app
|
| 17 |
+
COPY requirements.txt ./
|
| 18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Pré-téléchargement des modèles pour éviter le cold start
|
| 22 |
+
RUN python - <<'PY'
|
| 23 |
+
from transformers import pipeline
|
| 24 |
+
from transformers import MarianMTModel, MarianTokenizer
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
print('Downloading XLM-R sentiment...')
|
| 28 |
+
pipeline('sentiment-analysis', model='cardiffnlp/twitter-xlm-roberta-base-sentiment')
|
| 29 |
+
print('Downloading FinBERT...')
|
| 30 |
+
pipeline('sentiment-analysis', model='yiyanghkust/finbert-tone')
|
| 31 |
+
print('Downloading Marian FR-EN...')
|
| 32 |
+
MarianTokenizer.from_pretrained('Helsinki-NLP/opus-mt-fr-en')
|
| 33 |
+
MarianMTModel.from_pretrained('Helsinki-NLP/opus-mt-fr-en')
|
| 34 |
+
print('All models cached.')
|
| 35 |
PY
|
| 36 |
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
COPY app ./app
|
| 39 |
ENV PORT=7860
|
| 40 |
EXPOSE 7860
|
| 41 |
|
| 42 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|
|
|