File size: 1,285 Bytes
0468ff5 9156292 0468ff5 9156292 0468ff5 9156292 0468ff5 cd94836 39932bb 0468ff5 | 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 43 44 | FROM python:3.12-slim
WORKDIR /app
# Install system dependencies required for audio processing (libsndfile)
RUN apt-get update && apt-get install -y \
libsndfile1 \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user (recommended for security and HF Spaces)
RUN useradd -m -u 1000 user
# Switch to user to install python dependencies?
# Usually better to install as root to system or as user to user --user
# For simplicity and standard HF spaces, we can keep install as root but ensure perms are right.
# Actually, standard pattern often is:
# 1. User setup
# 2. Env setup
# 3. Copy chown
# Copy requirements first to leverage Docker cache
COPY --chown=user requirements.txt .
# Install python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application with correct ownership
COPY --chown=user . .
# Create directories that are not copied but required
# and ensure the entire app directory is owned by user
RUN mkdir -p data temp logs && chown -R user:user /app
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Expose the port used by Hugging Face Spaces (7860)
EXPOSE 7860
# Start the application on port 7860
CMD ["python", "main.py", "serve", "--host", "0.0.0.0", "--port", "7860"]
|