Dev-ks04 commited on
Commit
36720a3
Β·
1 Parent(s): e4a4ef5

fix: Docker build - install torch CPU via --index-url, not requirements file

Browse files

- Dockerfile now installs torch==2.2.2 separately with --index-url (correct way)
- requirements_hf.txt no longer contains torch (avoids pip conflict)
- Model pre-download step has graceful fallback echo on failure
- README.md: fixed colorTo orange->yellow (HF validation)

Files changed (3) hide show
  1. Dockerfile +21 -17
  2. README.md +1 -1
  3. requirements_hf.txt +8 -5
Dockerfile CHANGED
@@ -1,36 +1,40 @@
1
- # ── Hugging Face Spaces – Contexto FastAPI Backend ──────────────────────────
2
- # Base image: slim Python (HF Spaces runs on CPU by default)
3
  FROM python:3.10-slim
4
 
5
  # HF Spaces requires port 7860
6
  EXPOSE 7860
7
 
8
- # System deps for faiss-cpu, lxml, etc.
9
  RUN apt-get update && apt-get install -y --no-install-recommends \
10
  gcc g++ git curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
  WORKDIR /app
14
 
15
- # Copy requirements first for Docker layer caching
16
- COPY requirements_hf.txt ./requirements.txt
17
-
18
- # Install Python deps (no CUDA β†’ CPU-only torch, much smaller)
19
  RUN pip install --no-cache-dir --upgrade pip && \
20
- pip install --no-cache-dir -r requirements.txt
 
 
21
 
22
- # Copy backend source
23
- COPY . .
 
24
 
25
- # Pre-download the T5 model so it is cached in the image
26
- # (avoids cold-start download on first request)
27
- RUN python -c "from transformers import T5Tokenizer, T5ForConditionalGeneration; \
28
- T5Tokenizer.from_pretrained('t5-small'); \
29
- T5ForConditionalGeneration.from_pretrained('t5-small')" || true
30
 
31
- # Set env so transformers uses /app/.cache (writable in HF Spaces)
32
  ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
33
  ENV HF_HOME=/app/.cache/huggingface
 
 
 
 
 
 
 
 
34
 
35
- # Run on port 7860 (HF Spaces requirement)
36
  CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
1
+ # ── Contexto Backend – Hugging Face Spaces (CPU) ──────────────────────────────
 
2
  FROM python:3.10-slim
3
 
4
  # HF Spaces requires port 7860
5
  EXPOSE 7860
6
 
7
+ # System deps
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
  gcc g++ git curl \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  WORKDIR /app
13
 
14
+ # ── Step 1: Install PyTorch CPU-only FIRST (separate layer for caching) ────────
 
 
 
15
  RUN pip install --no-cache-dir --upgrade pip && \
16
+ pip install --no-cache-dir \
17
+ torch==2.2.2 \
18
+ --index-url https://download.pytorch.org/whl/cpu
19
 
20
+ # ── Step 2: Copy requirements and install remaining deps ───────────────────────
21
+ COPY requirements_hf.txt ./requirements_hf.txt
22
+ RUN pip install --no-cache-dir -r requirements_hf.txt
23
 
24
+ # ── Step 3: Copy all source files ─────────────────────────────────────────────
25
+ COPY . .
 
 
 
26
 
27
+ # ── Step 4: Set HuggingFace cache to writable path ────────────────────────────
28
  ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
29
  ENV HF_HOME=/app/.cache/huggingface
30
+ ENV TOKENIZERS_PARALLELISM=false
31
+
32
+ # Pre-download T5-small to bake into image (avoids cold-start delay)
33
+ RUN python -c "\
34
+ from transformers import T5Tokenizer, T5ForConditionalGeneration; \
35
+ T5Tokenizer.from_pretrained('t5-small'); \
36
+ T5ForConditionalGeneration.from_pretrained('t5-small'); \
37
+ print('T5-small cached.')" || echo "Model pre-download skipped (will download at runtime)"
38
 
39
+ # ── Run FastAPI on port 7860 ───────────────────────────────────────────────────
40
  CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
README.md CHANGED
@@ -11,7 +11,7 @@ app_port: 7860
11
 
12
  # Contexto β€” Intent-Aware Summarization API
13
 
14
- FastAPI backend for [Contexto](https://github.com/Dks-040204/intent-aware-context-preserving-summarization-gen-ai-rag).
15
 
16
  ## Endpoints
17
  - `GET /health` β€” health check
 
11
 
12
  # Contexto β€” Intent-Aware Summarization API
13
 
14
+ FastAPI backend for Contexto.
15
 
16
  ## Endpoints
17
  - `GET /health` β€” health check
requirements_hf.txt CHANGED
@@ -1,6 +1,4 @@
1
- # ── Contexto Backend – Hugging Face Spaces requirements ──────────────────────
2
- # CPU-only torch (much smaller than the full CUDA build)
3
- torch==2.2.2+cpu --extra-index-url https://download.pytorch.org/whl/cpu
4
 
5
  # NLP core
6
  transformers==4.40.1
@@ -22,8 +20,13 @@ numpy
22
  scikit-learn
23
  rouge-score
24
 
25
- # Translation (for multilingual output)
26
  deep-translator==1.11.4
27
 
28
- # Document parsing (used by evaluation helpers)
29
  requests
 
 
 
 
 
 
1
+ # ── Contexto Backend – HF Spaces requirements (torch installed separately in Dockerfile) ──
 
 
2
 
3
  # NLP core
4
  transformers==4.40.1
 
20
  scikit-learn
21
  rouge-score
22
 
23
+ # Translation (multilingual output)
24
  deep-translator==1.11.4
25
 
26
+ # Document parsing helpers
27
  requests
28
+
29
+ # Document reading
30
+ python-docx
31
+ PyMuPDF
32
+ mammoth