FROM python:3.10-slim # Install system dependencies (only curl is needed for health checks) RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ && rm -rf /var/lib/apt/lists/* # Create a user with UID 1000 RUN useradd -m -u 1000 user # Set environment variables ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Create app directory and set ownership WORKDIR /app RUN chown user:user /app # Switch to the non-root user USER user # Copy requirements and install dependencies COPY --chown=user requirements.txt . RUN pip install --default-timeout=1000 --no-cache-dir --upgrade --user -r requirements.txt # Pre-download and cache the Alibaba-NLP/gte-multilingual-base model # This makes Space container startup instant RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('Alibaba-NLP/gte-multilingual-base', trust_remote_code=True)" # Copy the rest of the application files COPY --chown=user . . # Expose default HF Spaces port EXPOSE 7860 # Run the FastAPI application using Uvicorn CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]