Spaces:
Sleeping
Sleeping
File size: 1,427 Bytes
e4a2631 |
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 |
# 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"]
|