File size: 1,413 Bytes
8d1d8b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
# Use a slim Python base image
FROM python:3.10-slim

# Create a non-root user 'user' with UID 1000
# This is required by Hugging Face Spaces
RUN useradd -m -u 1000 user

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV HOME=/home/user
ENV PATH=$HOME/.local/bin:$PATH

# Install system dependencies required for OpenCV, audio processing, etc.
RUN apt-get update && apt-get install -y \
    libgl1 \
    libglib2.0-0 \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR $HOME/app

# Change ownership of the app directory to the 'user'
RUN chown -R user:user $HOME/app

# Switch to the non-root user
USER user

# Copy requirements and install them
COPY --chown=user:user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the download script and execute it to cache models
# This bakes the downloaded models directly into the Docker image layers
COPY --chown=user:user download_models.py .
ARG HUGGING_FACE_TOKEN
ENV HUGGING_FACE_TOKEN=$HUGGING_FACE_TOKEN
RUN python download_models.py

# Copy the rest of the application code
COPY --chown=user:user app ./app
COPY --chown=user:user frontend ./frontend


# Expose port (HF Spaces routes traffic to 7860 by default)
EXPOSE 7860

# Command to run the application (assuming FastAPI via Uvicorn)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]