FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ HF_HOME=/tmp/huggingface_cache \ PORT=7860 # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ ffmpeg \ libsndfile1 \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Copy requirements and install COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Create necessary folders and grant open permissions (required for Hugging Face non-root user 1000) RUN mkdir -p /app/data /app/data/users /app/data/qdrant /tmp/huggingface_cache && \ chmod -R 777 /app/data /tmp/huggingface_cache # Copy the rest of the application code COPY . . # Run a python script to pre-download the ML models to the cache folder during Docker build # This makes container startup immediate and avoids download timeouts. COPY scripts/preload_models.py /tmp/preload_models.py RUN python /tmp/preload_models.py # Set permissions for the app folder again RUN chmod -R 777 /app # Expose port 7860 for Hugging Face Spaces EXPOSE 7860 # Command to run uvicorn CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]