Spaces:
Running
Running
File size: 2,447 Bytes
3484ae4 0853b44 83d3b05 0853b44 83d3b05 3484ae4 3d9ad4a 0853b44 83d3b05 0853b44 640ad48 83d3b05 0853b44 83d3b05 0853b44 83d3b05 0853b44 59dd371 83d3b05 0853b44 83d3b05 3484ae4 0853b44 83d3b05 0853b44 83d3b05 | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 | # Base image with Python 3.10 (Explicitly using Bookworm to avoid unstable Trixie repos)
FROM python:3.10-slim-bookworm
# Keeps Python from buffering stdout/stderr (important for HF Spaces logs)
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Tell HuggingFace where to cache downloaded models (ViT, BERT)
ENV HF_HOME=/app/.cache/huggingface
# Set working directory
WORKDIR /app
# ββ System dependencies βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Pinning to stable repos and adding --fix-missing for robustness
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
libgl1 \
libglib2.0-0 \
libgomp1 \
libcairo2-dev \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libgdk-pixbuf2.0-0 \
libffi-dev \
shared-mime-info \
fonts-liberation \
fonts-dejavu-core \
build-essential \
pkg-config \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
# ββ Python dependencies βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
COPY requirements.txt .
# Install PyTorch CPU-only FIRST (avoids pulling the massive CUDA build)
RUN pip install --no-cache-dir \
torch==2.4.1 \
torchvision==0.19.1 \
--index-url https://download.pytorch.org/whl/cpu
# Install everything else
RUN pip install --no-cache-dir -r requirements.txt
# Download spaCy English model
RUN python -m spacy download en_core_web_sm
# ββ App code ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
COPY . .
# Create runtime directories
RUN mkdir -p /app/temp_uploads /app/.cache/huggingface
# ββ Security: run as non-root (HF Spaces best practice) ββββββββββββββββββββββ
# Handle case where UID 1000 already exists (common in some base images)
RUN if ! id -u 1000 >/dev/null 2>&1; then \
useradd -m -u 1000 appuser; \
else \
useradd -m appuser || true; \
fi && \
chown -R 1000:1000 /app
USER 1000
# HF Spaces requires port 7860
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] |