|
|
|
|
|
FROM python:3.10-slim
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PORT=7860 \
|
|
HF_HOME=/app/.cache/huggingface \
|
|
NLTK_DATA=/app/nltk_data \
|
|
MPLCONFIGDIR=/app/.config/matplotlib
|
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
gcc \
|
|
g++ \
|
|
libjpeg-dev \
|
|
zlib1g-dev \
|
|
libpng-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
COPY requirements.txt ./
|
|
RUN pip install --upgrade pip && \
|
|
pip install -r requirements.txt
|
|
|
|
|
|
RUN mkdir -p ${HF_HOME} ${NLTK_DATA} ${MPLCONFIGDIR}
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
RUN chmod -R 777 /app
|
|
|
|
|
|
RUN if [ -f postbuild ]; then sh postbuild; else python -m spacy download en_core_web_md; fi
|
|
|
|
|
|
RUN python - <<'PY'
|
|
import nltk, os
|
|
os.makedirs(os.environ.get('NLTK_DATA','/app/nltk_data'), exist_ok=True)
|
|
for pkg in ['punkt','punkt_tab','wordnet','averaged_perceptron_tagger']:
|
|
try:
|
|
nltk.download(pkg, download_dir=os.environ['NLTK_DATA'])
|
|
except Exception as e:
|
|
print('NLTK download failed for', pkg, e)
|
|
PY
|
|
|
|
|
|
RUN python - <<'PY'
|
|
from transformers import pipeline
|
|
|
|
pipeline('sentiment-analysis', model='distilbert-base-uncased-finetuned-sst-2-english')
|
|
|
|
pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
|
|
|
|
pipeline('sentiment-analysis', model='j-hartmann/emotion-english-distilroberta-base')
|
|
PY
|
|
|
|
|
|
EXPOSE 7860
|
|
|
|
|
|
CMD ["sh", "-c", "gunicorn -b 0.0.0.0:${PORT:-7860} app:app"]
|
|
|