File size: 1,404 Bytes
817f25b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# FinChat API — headless FastAPI service for a Hugging Face Docker Space.
#
# IMPORTANT: build context is the repo ROOT, so the image can COPY the RAG code
# in src/ and the prebuilt vector index in vectorstore/ (shipped via git-lfs).
FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

# 1) Install Python deps as root -> system site-packages (readable by all users).
COPY api/requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r /tmp/requirements.txt

# 2) Non-root user (Hugging Face Spaces convention: uid 1000).
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    HF_HOME=/home/user/.cache/huggingface
WORKDIR /home/user/app

# 3) Pre-download the embedding model INTO the image (as the runtime user), so
#    the first request is fast and needs no network at runtime.
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('BAAI/bge-small-en-v1.5')"

# 4) App code + the prebuilt vector index.
COPY --chown=user src/ ./src/
COPY --chown=user vectorstore/ ./vectorstore/
COPY --chown=user api/ ./api/

# Point config at the committed, writable index (chromadb opens it read/write).
ENV FINCHAT_VECTORSTORE=/home/user/app/vectorstore

EXPOSE 7860
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]