File size: 1,154 Bytes
1fee1c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Hugging Face Spaces requires port 7860 and uid 1000
FROM python:3.11-slim

# System dependencies for chromadb, lxml, sentence-transformers, unstructured
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libxml2-dev \
    libxslt-dev \
    libsqlite3-dev \
    libffi-dev \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Install uv for fast dependency resolution
RUN pip install --no-cache-dir uv

# HF Spaces requires non-root user with uid 1000
RUN useradd -m -u 1000 -s /bin/bash appuser

WORKDIR /app

# Install deps before copying source (better layer caching)
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev

# Copy source code
COPY --chown=appuser:appuser . .

# Create writable runtime directories
RUN mkdir -p vector_store cache documents \
    && chown -R appuser:appuser /app

USER appuser

# Pre-download the sentence transformer model so first request is fast
RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"

EXPOSE 7860

CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]