Spaces:
Running
Running
Dev-ks04 commited on
Commit Β·
c9b24fa
1
Parent(s): 36720a3
fix: pin numpy<2.0 to resolve faiss-cpu ImportError
Browse filesfaiss-cpu 1.8.0 uses numpy.core.multiarray which was removed in NumPy 2.0.
Fix: install numpy>=1.24,<2.0 explicitly BEFORE torch and faiss in Dockerfile.
- Dockerfile +16 -13
- requirements_hf.txt +7 -7
Dockerfile
CHANGED
|
@@ -1,40 +1,43 @@
|
|
| 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:
|
| 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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
COPY requirements_hf.txt ./requirements_hf.txt
|
| 22 |
RUN pip install --no-cache-dir -r requirements_hf.txt
|
| 23 |
|
| 24 |
-
# ββ Step
|
| 25 |
COPY . .
|
| 26 |
|
| 27 |
-
# ββ Step
|
| 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
|
| 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
|
| 38 |
|
| 39 |
-
# ββ
|
| 40 |
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 |
EXPOSE 7860
|
| 5 |
|
|
|
|
| 6 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
gcc g++ git curl \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
WORKDIR /app
|
| 11 |
|
| 12 |
+
# ββ Step 1: Upgrade pip ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade pip
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# ββ Step 2: Pin NumPy <2.0 FIRST (faiss-cpu needs numpy.core, removed in 2.0) β
|
| 16 |
+
RUN pip install --no-cache-dir "numpy>=1.24.0,<2.0.0"
|
| 17 |
+
|
| 18 |
+
# ββ Step 3: Install PyTorch CPU-only ββββββββββββββββββββββββββββββββββββββββββ
|
| 19 |
+
RUN pip install --no-cache-dir \
|
| 20 |
+
torch==2.2.2 \
|
| 21 |
+
--index-url https://download.pytorch.org/whl/cpu
|
| 22 |
+
|
| 23 |
+
# ββ Step 4: Install remaining dependencies ββββββββββββββββββββββββββββββββββββ
|
| 24 |
COPY requirements_hf.txt ./requirements_hf.txt
|
| 25 |
RUN pip install --no-cache-dir -r requirements_hf.txt
|
| 26 |
|
| 27 |
+
# ββ Step 5: Copy source βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
COPY . .
|
| 29 |
|
| 30 |
+
# ββ Step 6: HuggingFace cache config βββββββββββββββββββββββββββββββββββββββββ
|
| 31 |
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
|
| 32 |
ENV HF_HOME=/app/.cache/huggingface
|
| 33 |
ENV TOKENIZERS_PARALLELISM=false
|
| 34 |
|
| 35 |
+
# Pre-download T5-small to bake into image
|
| 36 |
RUN python -c "\
|
| 37 |
from transformers import T5Tokenizer, T5ForConditionalGeneration; \
|
| 38 |
T5Tokenizer.from_pretrained('t5-small'); \
|
| 39 |
T5ForConditionalGeneration.from_pretrained('t5-small'); \
|
| 40 |
+
print('T5-small cached.')" || echo "Model will download at runtime"
|
| 41 |
|
| 42 |
+
# ββ Step 7: Run on port 7860 ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 43 |
CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|
requirements_hf.txt
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
-
# ββ Contexto Backend β HF Spaces requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# NLP core
|
| 4 |
transformers==4.40.1
|
|
@@ -6,6 +11,7 @@ sentencepiece
|
|
| 6 |
nltk
|
| 7 |
|
| 8 |
# Embedding + vector search (RAG)
|
|
|
|
| 9 |
sentence-transformers==2.7.0
|
| 10 |
faiss-cpu==1.8.0
|
| 11 |
|
|
@@ -16,7 +22,6 @@ pydantic==2.7.1
|
|
| 16 |
python-multipart
|
| 17 |
|
| 18 |
# Text processing
|
| 19 |
-
numpy
|
| 20 |
scikit-learn
|
| 21 |
rouge-score
|
| 22 |
|
|
@@ -25,8 +30,3 @@ deep-translator==1.11.4
|
|
| 25 |
|
| 26 |
# Document parsing helpers
|
| 27 |
requests
|
| 28 |
-
|
| 29 |
-
# Document reading
|
| 30 |
-
python-docx
|
| 31 |
-
PyMuPDF
|
| 32 |
-
mammoth
|
|
|
|
| 1 |
+
# ββ Contexto Backend β HF Spaces requirements βββββββββββββββββββββββββββββββββ
|
| 2 |
+
# NOTE: torch is installed separately in the Dockerfile via --index-url
|
| 3 |
+
|
| 4 |
+
# NumPy MUST be <2.0 β faiss-cpu and sentence-transformers use numpy.core
|
| 5 |
+
# which was removed in NumPy 2.0
|
| 6 |
+
numpy>=1.24.0,<2.0.0
|
| 7 |
|
| 8 |
# NLP core
|
| 9 |
transformers==4.40.1
|
|
|
|
| 11 |
nltk
|
| 12 |
|
| 13 |
# Embedding + vector search (RAG)
|
| 14 |
+
# faiss-cpu 1.8.0 requires numpy<2.0 (pinned above)
|
| 15 |
sentence-transformers==2.7.0
|
| 16 |
faiss-cpu==1.8.0
|
| 17 |
|
|
|
|
| 22 |
python-multipart
|
| 23 |
|
| 24 |
# Text processing
|
|
|
|
| 25 |
scikit-learn
|
| 26 |
rouge-score
|
| 27 |
|
|
|
|
| 30 |
|
| 31 |
# Document parsing helpers
|
| 32 |
requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|