File size: 2,173 Bytes
8d29e78 8ae78b0 8e16dd4 8ae78b0 8d29e78 8ae78b0 8d29e78 8e16dd4 8ae78b0 8e16dd4 8ae78b0 8e16dd4 8ae78b0 8e16dd4 8ae78b0 8e16dd4 8d29e78 8ae78b0 8e16dd4 6d2ceb6 8ae78b0 8e16dd4 8d29e78 8e16dd4 8d29e78 8e16dd4 8ae78b0 8d29e78 8e16dd4 8ae78b0 8e16dd4 8ae78b0 8e16dd4 8ae78b0 8e16dd4 8ae78b0 | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
# Set non-interactive frontend for debconf
ARG DEBIAN_FRONTEND=noninteractive
# Install Python and system dependencies
RUN apt-get update && apt-get install -y \
python3.11 \
python3.11-venv \
python3-pip \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
ffmpeg \
tzdata \
postgresql-client \
libpq-dev \
git \
curl \
&& ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user with UID 1000 (required for Hugging Face Spaces)
RUN useradd -m -u 1000 user
# Set up the user environment
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONPATH=/home/user/.local/lib/python3.11/site-packages \
CUDA_HOME=/usr/local/cuda \
CUDA_PATH=/usr/local/cuda \
LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
# Create and set up working directory
WORKDIR $HOME/app
# Install Python virtual environment
RUN python3.11 -m venv $HOME/venv
ENV PATH="$HOME/venv/bin:$PATH"
# Copy requirements first (for better caching)
COPY --chown=user:user behavior_backend/requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
pip install --no-cache-dir -r requirements.txt
# Create required directories with proper ownership
RUN mkdir -p $HOME/app/static/uploads $HOME/app/static/results && \
chown -R user:user $HOME/app
# Create data directory for persistence (if needed)
RUN mkdir -p /data && chown -R user:user /data
# Copy application code with proper ownership
COPY --chown=user:user behavior_backend/app/ ./app/
COPY --chown=user:user behavior_backend/main.py .
COPY --chown=user:user behavior_backend/.env .
# Switch to non-root user
USER user
# Expose the port that Hugging Face Spaces expects
EXPOSE 7860
# Command to run the application on the port Hugging Face expects
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |