File size: 863 Bytes
504d13c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build dependencies
FROM python:3.11-slim AS builder

WORKDIR /app
COPY requirements.txt .

RUN pip install --user --no-cache-dir -r requirements.txt

# Stage 2: Runtime
FROM python:3.11-slim AS runtime

WORKDIR /app

# Copy installed packages from builder
COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH

# Copy application code only (no tests, no eval)
COPY app/ ./app/

# HF Spaces runs as a non-root user (UID 1000)
# Create the user to match HF's runtime UID
RUN useradd -m -u 1000 user
USER user

# HF Spaces requires port 7860
EXPOSE 7860

# Single worker — HF free tier has ~16GB RAM but cold starts are common;
# single worker avoids OOM on smaller hardware tiers.
# Increase --workers to 2 only on upgraded hardware tiers.
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]