Spaces:
Sleeping
Sleeping
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)
- Dockerfile +21 -17
- README.md +1 -1
- requirements_hf.txt +8 -5
Dockerfile
CHANGED
|
@@ -1,36 +1,40 @@
|
|
| 1 |
-
# ββ Hugging Face Spaces
|
| 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
|
| 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 |
-
#
|
| 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
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# Copy
|
| 23 |
-
COPY . .
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
RUN python -c "from transformers import T5Tokenizer, T5ForConditionalGeneration; \
|
| 28 |
-
T5Tokenizer.from_pretrained('t5-small'); \
|
| 29 |
-
T5ForConditionalGeneration.from_pretrained('t5-small')" || true
|
| 30 |
|
| 31 |
-
#
|
| 32 |
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
|
| 33 |
ENV HF_HOME=/app/.cache/huggingface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
# Run on port 7860
|
| 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
|
| 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 β
|
| 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 (
|
| 26 |
deep-translator==1.11.4
|
| 27 |
|
| 28 |
-
# Document parsing
|
| 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
|