# Use NVIDIA CUDA base image for GPU support FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ DEBIAN_FRONTEND=noninteractive # Install system dependencies RUN apt-get update && apt-get install -y \ python3-pip \ python3-dev \ git \ wget \ ffmpeg \ libsm6 \ libxext6 \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Upgrade pip RUN pip3 install --no-cache-dir --upgrade pip # Install Python dependencies # We install torch first to ensure correct CUDA version RUN pip3 install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # Copy requirements and install COPY requirements.txt . RUN pip3 install --no-cache-dir -r requirements.txt # Create a user to run the application (Hugging Face Spaces requirement for security) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set working directory for the user WORKDIR $HOME/app # Copy the rest of the application code COPY --chown=user . $HOME/app # Expose the port (Hugging Face Spaces maps port 7860 by default) EXPOSE 7860 # Command to run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]