File size: 1,112 Bytes
ba7290b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
FROM python:3.13-slim

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

RUN useradd -m -u 1000 user
RUN mkdir -p /model && chown user:user /model
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

# Enable bytecode compilation for faster startup
ENV UV_COMPILE_BYTECODE=1
# Use hard links for cached packages to save space
ENV UV_LINK_MODE=copy

# Copy dependency files first (for layer caching)
COPY --chown=user pyproject.toml uv.lock ./

# Install dependencies 
RUN uv sync --frozen --no-install-project --no-dev

# Model download (to a path that won't be overwritten by COPY . /app)
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
    uv run hf download \
    --token=$(cat /run/secrets/HF_TOKEN) \
    --local-dir=/model/ \
    --repo-type=model ObinnaOkpolu/dala-afri-mbart50-ct2-int8

# Layer: app code 
COPY --chown=user . /app
RUN uv sync --frozen --no-dev

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