NIKKI77 commited on
Commit
d6a554f
·
1 Parent(s): 7c679a2

Non-root + writable caches, NLTK punkt_tab, cached models, timeout=300

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -17
Dockerfile CHANGED
@@ -1,17 +1,20 @@
1
  FROM python:3.12-slim
2
 
3
- ENV DEBIAN_FRONTEND=noninteractive PIP_NO_CACHE_DIR=1
 
 
4
 
5
- # Create non-root user
6
  RUN useradd -m -u 1000 appuser
7
  ENV PATH="/home/appuser/.local/bin:$PATH"
8
 
9
  WORKDIR /app
10
 
11
- # Minimal OS deps
12
- RUN apt-get update && apt-get install -y --no-install-recommends libgomp1 && rm -rf /var/lib/apt/lists/*
 
13
 
14
- # Put ALL caches in the user's home; also set Python path
15
  ENV HF_HOME=/home/appuser/.cache \
16
  TRANSFORMERS_CACHE=/home/appuser/.cache/transformers \
17
  HUGGINGFACE_HUB_CACHE=/home/appuser/.cache/huggingface \
@@ -21,18 +24,19 @@ ENV HF_HOME=/home/appuser/.cache \
21
  OMP_NUM_THREADS=1 \
22
  OPENBLAS_NUM_THREADS=1 \
23
  MKL_NUM_THREADS=1 \
 
24
  PYTHONPATH=/app/backend:$PYTHONPATH
25
 
26
  # Copy code with correct ownership
27
  COPY --chown=appuser:appuser . .
28
 
29
- # Switch to non-root BEFORE installs so any caches/dirs are writable
30
  USER appuser
31
 
32
- # Python deps (install to user site)
33
  RUN pip install --no-cache-dir --user -r requirements.txt
34
 
35
- # Preload models/data so first boot doesn’t timeout
36
  RUN python -m spacy download en_core_web_sm
37
  RUN python - <<'PY'
38
  import nltk
@@ -41,15 +45,19 @@ for pkg in ["punkt","punkt_tab","wordnet","omw-1.4"]:
41
  print("NLTK OK")
42
  PY
43
 
44
- # (Optional) prefetch light-weight bits; safe to skip
45
- # RUN python - <<'PY'
46
- # from sentence_transformers import SentenceTransformer
47
- # SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
48
- # from transformers import AutoTokenizer
49
- # AutoTokenizer.from_pretrained("oliverguhr/fullstop-punctuation-multilang-large")
50
- # PY
 
 
 
 
51
 
52
  EXPOSE 7860
53
 
54
- # Extra time for cold-start model downloads
55
- CMD ["gunicorn","-w","1","-k","gthread","--threads","4","--timeout","180","-b","0.0.0.0:7860","backend.app:app"]
 
1
  FROM python:3.12-slim
2
 
3
+ ENV DEBIAN_FRONTEND=noninteractive \
4
+ PIP_NO_CACHE_DIR=1 \
5
+ PYTHONUNBUFFERED=1
6
 
7
+ # Non-root user so caches are writable at runtime
8
  RUN useradd -m -u 1000 appuser
9
  ENV PATH="/home/appuser/.local/bin:$PATH"
10
 
11
  WORKDIR /app
12
 
13
+ # Minimal OS deps (OpenMP runtime)
14
+ RUN apt-get update && apt-get install -y --no-install-recommends libgomp1 \
15
+ && rm -rf /var/lib/apt/lists/*
16
 
17
+ # Put ALL caches in the user's home; plus perf/env knobs
18
  ENV HF_HOME=/home/appuser/.cache \
19
  TRANSFORMERS_CACHE=/home/appuser/.cache/transformers \
20
  HUGGINGFACE_HUB_CACHE=/home/appuser/.cache/huggingface \
 
24
  OMP_NUM_THREADS=1 \
25
  OPENBLAS_NUM_THREADS=1 \
26
  MKL_NUM_THREADS=1 \
27
+ HF_HUB_ENABLE_HF_TRANSFER=1 \
28
  PYTHONPATH=/app/backend:$PYTHONPATH
29
 
30
  # Copy code with correct ownership
31
  COPY --chown=appuser:appuser . .
32
 
33
+ # Switch to non-root BEFORE installs so caches land in /home/appuser
34
  USER appuser
35
 
36
+ # Python deps
37
  RUN pip install --no-cache-dir --user -r requirements.txt
38
 
39
+ # Preload NLP data
40
  RUN python -m spacy download en_core_web_sm
41
  RUN python - <<'PY'
42
  import nltk
 
45
  print("NLTK OK")
46
  PY
47
 
48
+ # Pre-fetch models to avoid cold-start timeouts
49
+ RUN python - <<'PY'
50
+ from sentence_transformers import SentenceTransformer
51
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
52
+ # semantic encoder
53
+ SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
54
+ # punctuation model
55
+ AutoTokenizer.from_pretrained("oliverguhr/fullstop-punctuation-multilang-large")
56
+ AutoModelForTokenClassification.from_pretrained("oliverguhr/fullstop-punctuation-multilang-large")
57
+ print("HF models cached")
58
+ PY
59
 
60
  EXPOSE 7860
61
 
62
+ # Give the worker time for initial GPU warmup
63
+ CMD ["gunicorn","-w","1","-k","gthread","--threads","4","--timeout","300","-b","0.0.0.0:7860","backend.app:app"]