Spaces:
Sleeping
Sleeping
File size: 1,175 Bytes
9d962cb |
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 |
# Use an official Python 3.11 slim image as a parent image
FROM python:3.11-slim
# --- Stage 1: Install system dependencies as root ---
# We need ffmpeg for pydub/torchaudio and git/git-lfs to download large models
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
git \
git-lfs \
&& rm -rf /var/lib/apt/lists/*
# --- Stage 2: Set up a non-root user for better security ---
# This is a best practice from the Hugging Face team
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /home/user/app
# --- Stage 3: Install Python dependencies as the non-root user ---
# Copy requirements first to leverage Docker layer caching
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# --- Stage 4: Copy the rest of the application code ---
# This includes your app.py, models/ folder, and static/ folder
COPY --chown=user . .
# --- Stage 5: Run the application ---
# Expose the port the app runs on
EXPOSE 7860
# Command to run the application using uvicorn
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |