-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.space
More file actions
54 lines (43 loc) · 2.31 KB
/
Copy pathDockerfile.space
File metadata and controls
54 lines (43 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# CineSemantics Hugging Face Space image — Streamlit demo of the champion stack
# (src/serving/space_app.py): e5-base-v2 + faiss HNSW + metadata rerank + ItemKNN,
# no Milvus. Built FROM THE SPACE REPO, which additionally carries the small
# artifacts that are gitignored on GitHub:
# models/cf_interactions.npz + cf_meta.json ItemKNN CF champion
# data/eval/cf_split.json CF split (self-heal fallback)
# The ~29 MB catalog-embedding cache is NOT shipped: it is regenerated during
# the image build (see the encode_catalog RUN below) with the exact same
# ChampionEmbedder code path, so the served vectors match the eval harness.
FROM python:3.11-slim
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
HOME=/app \
HF_HOME=/app/.hf \
STREAMLIT_BROWSER_GATHERUSAGESTATS=false
# libgomp1: faiss-cpu runtime; curl: healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 curl && rm -rf /var/lib/apt/lists/*
COPY requirements-space.txt .
RUN pip install --no-cache-dir -r requirements-space.txt
# Bake the query-encoder weights into the image so cold starts don't re-download.
RUN python -c "from sentence_transformers import SentenceTransformer; \
SentenceTransformer('intfloat/e5-base-v2')"
COPY src ./src
COPY data/9000plus.csv ./data/9000plus.csv
COPY data/eval/cf_split.json ./data/eval/cf_split.json
COPY models ./models
# Build the catalog-embedding cache at image-build time (~9,826 movies, one-off).
# encode_catalog writes results/emb_cache/intfloat__e5-base-v2.npy + .time.json,
# exactly the files the app's cache-first loader expects at startup.
RUN python -c "import pandas as pd; \
from src.retrieval.embedder import ChampionEmbedder; \
emb = ChampionEmbedder().encode_catalog(pd.read_csv('data/9000plus.csv').fillna('')); \
print('catalog embedded:', emb.shape)"
# HF Spaces may run the container as a non-root user: make HOME (=/app) writable
# so streamlit can create .streamlit/ and the HF cache stays usable.
RUN mkdir -p /app/.streamlit && chmod -R a+rwX /app
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 \
CMD curl -f http://localhost:7860/_stcore/health || exit 1
CMD ["streamlit", "run", "src/serving/space_app.py", \
"--server.port=7860", "--server.address=0.0.0.0", "--server.headless=true"]