File size: 1,880 Bytes
b59fc2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c4590b
 
 
 
66c6f17
8c4590b
 
b59fc2c
 
 
 
8c4590b
b59fc2c
 
66c6f17
 
 
 
 
 
 
b59fc2c
 
 
8c4590b
b59fc2c
 
 
 
 
 
 
 
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
55
56
57
# ── HuggingFace Spaces compatible Dockerfile ──────────────────────────────
# Port MUST be 7860 for HF Spaces.
# Runs as user 1000 (HF requirement).

FROM python:3.10-slim

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential curl git \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user (required by HF Spaces)
RUN useradd -m -u 1000 appuser

WORKDIR /app

# Install Python deps first (better layer caching)
COPY requirements_api.txt .
RUN pip install --no-cache-dir -r requirements_api.txt

# Copy application files
COPY . .

# Pin HuggingFace cache inside /app so the sentence-transformer model is
# downloaded once during `docker build` and baked into the image layer.
ENV HF_HOME=/app/.hf_cache
ENV TRANSFORMERS_CACHE=/app/.hf_cache/transformers
ENV SENTENCE_TRANSFORMERS_HOME=/app/.hf_cache/sentence_transformers

# Set ownership (includes .hf_cache written by the build step below)
RUN chown -R appuser:appuser /app

USER appuser

# Pre-build FAISS index + download the embedding model into /app/.hf_cache
RUN python src/build_faiss.py

# ── Offline mode ────────────────────────────────────────────────────────────
# Model is now cached in the image. Tell all HF libraries to NEVER call the
# network at runtime β€” prevents "Could not resolve host: huggingface.co" errors.
ENV TRANSFORMERS_OFFLINE=1
ENV HF_DATASETS_OFFLINE=1
ENV HF_HUB_OFFLINE=1

# Environment defaults (override via HF Space secrets)
ENV GROQ_API_KEY_1=""
ENV GROQ_API_KEY_2=""
ENV GROQ_API_KEY_3=""
ENV GROQ_MODEL="llama-3.3-70b-versatile"
ENV ALLOWED_ORIGINS="*"
ENV PORT=7860

# Expose HF Spaces port
EXPOSE 7860

CMD ["python", "api_server_fastapi.py"]