# Use a lightweight Python base FROM python:3.10-slim # Prevent interactive prompts & speed up Python ENV DEBIAN_FRONTEND=noninteractive \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ TOKENIZERS_PARALLELISM=false # Set work directory WORKDIR /code # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ curl \ libopenblas-dev \ libomp-dev \ && rm -rf /var/lib/apt/lists/* # Copy requirements first (for Docker caching) COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Hugging Face tools RUN pip install --no-cache-dir huggingface-hub accelerate # Set Hugging Face cache inside container (persistent, not /tmp) ENV HF_HOME=/models/huggingface ENV TRANSFORMERS_CACHE=/models/huggingface ENV HUGGINGFACE_HUB_CACHE=/models/huggingface ENV HF_HUB_CACHE=/models/huggingface # Create cache dir RUN mkdir -p /models/huggingface # Pre-download model at build time (BLIP captioning model) RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='Salesforce/blip-image-captioning-large')" # Copy project files COPY . . # Expose FastAPI port (Hugging Face Spaces uses 7860) EXPOSE 7860 # Run FastAPI app with uvicorn (single worker) CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]