File size: 1,036 Bytes
9dc3df4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use an official lightweight Python runtime
FROM python:3.10-slim

# Install light OS dependencies for matrix calculations or system libraries
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Create user matching the Hugging Face Space security identity policy (User 1000)
RUN useradd -m -u 1000 user
WORKDIR /app

# Switch cache directories to safe, user-writable root spaces
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONUNBUFFERED=1 \
    HF_HOME=/home/user/.cache/huggingface

# Copy instructions using accurate permission flags
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Bring code variables and model dependencies into build workspace
COPY --chown=user . .

# Adjust user context for active operations
USER user

# Hugging Face default external port mapping target
EXPOSE 7860

# Serve via asynchronous production uvicorn thread engine 
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]