File size: 955 Bytes
2d93e30
4040150
 
2d93e30
deb9e1f
 
 
 
4040150
2d93e30
deb9e1f
4040150
 
 
 
2d93e30
4040150
bfce2a9
 
2d93e30
bfce2a9
 
 
4040150
49d1e1b
4040150
 
 
 
2d93e30
4040150
 
2d93e30
4040150
 
bfce2a9
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
# Use 3.11 to maintain compatibility with Torch 2.3.0
FROM python:3.11-slim

# 1. Install system dependencies for C++ builds (needed for sentencepiece)
USER root
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# 2. Setup non-root user for Hugging Face
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HF_HOME=/home/user/.cache/huggingface

WORKDIR $HOME/app

# 3. Initialize cache directories
RUN mkdir -p $HF_HOME && chown -R user:user $HOME

USER user

# 4. Install Python requirements
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# 5. Copy application code
COPY --chown=user . .

# 6. Expose port 7860 for Hugging Face Spaces
EXPOSE 7860

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