MANOJSEQ commited on
Commit
ab6969d
Β·
verified Β·
1 Parent(s): d62f608

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -19
Dockerfile CHANGED
@@ -5,12 +5,13 @@ ENV PYTHONUNBUFFERED=1 \
5
  PIP_NO_CACHE_DIR=1 \
6
  HF_HUB_DISABLE_TELEMETRY=1 \
7
  PORT=7860 \
8
- NLTK_DATA=/app/nltk_data \
9
- HF_HOME=/app/hf_cache \
10
- TRANSFORMERS_CACHE=/app/hf_cache \
11
- SENTENCE_TRANSFORMERS_HOME=/app/hf_cache
 
12
 
13
- # (optional) handy tools for healthchecks & logs
14
  RUN apt-get update && apt-get install -y --no-install-recommends curl git && \
15
  rm -rf /var/lib/apt/lists/*
16
 
@@ -26,30 +27,27 @@ RUN python -m pip install --upgrade pip && \
26
  # ---- App code ----
27
  COPY . .
28
 
29
- # ---- Warm caches into the image layer ----
30
- # 1) Cache sentence-transformers model (SBERT)
 
 
31
  RUN python - <<'PY'
32
  from sentence_transformers import SentenceTransformer
33
  SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
34
- print("βœ… SBERT model cached")
35
  PY
36
 
37
- # 2) Cache NLTK VADER lexicon into /app/nltk_data
38
  RUN python - <<'PY'
39
  import os, nltk
40
- os.makedirs("/app/nltk_data", exist_ok=True)
41
- nltk.download("vader_lexicon", download_dir="/app/nltk_data")
42
- print("βœ… NLTK VADER cached")
43
  PY
44
 
45
- # 3) (Optional) Cache tldextract's PSL so first run is snappy
46
- RUN python - <<'PY'
47
- import tldextract
48
- tldextract.extract("example.com")
49
- print("βœ… tldextract PSL cached")
50
- PY
51
 
52
  EXPOSE 7860
53
 
54
  # ---- Run ----
55
- CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]
 
5
  PIP_NO_CACHE_DIR=1 \
6
  HF_HUB_DISABLE_TELEMETRY=1 \
7
  PORT=7860 \
8
+ # βœ… Writable + persistent on HF Spaces:
9
+ HF_HOME=/data/hf_cache \
10
+ TRANSFORMERS_CACHE=/data/hf_cache \
11
+ SENTENCE_TRANSFORMERS_HOME=/data/hf_cache \
12
+ NLTK_DATA=/data/nltk_data
13
 
14
+ # small tools
15
  RUN apt-get update && apt-get install -y --no-install-recommends curl git && \
16
  rm -rf /var/lib/apt/lists/*
17
 
 
27
  # ---- App code ----
28
  COPY . .
29
 
30
+ # βœ… Make caches writable for the runtime user
31
+ RUN mkdir -p /data/hf_cache /data/nltk_data && chmod -R 777 /data
32
+
33
+ # (optional) pre-warm models into /data caches to speed first run
34
  RUN python - <<'PY'
35
  from sentence_transformers import SentenceTransformer
36
  SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
37
+ print("βœ… SBERT cached")
38
  PY
39
 
 
40
  RUN python - <<'PY'
41
  import os, nltk
42
+ os.makedirs(os.getenv("NLTK_DATA","/data/nltk_data"), exist_ok=True)
43
+ nltk.download("vader_lexicon")
44
+ print("βœ… VADER cached")
45
  PY
46
 
47
+ # ensure everything under /data is writable after warm
48
+ RUN chmod -R 777 /data
 
 
 
 
49
 
50
  EXPOSE 7860
51
 
52
  # ---- Run ----
53
+ CMD ["sh","-c","uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]