Spaces:
Running
Running
File size: 3,307 Bytes
79b0bef | 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 68 69 70 71 72 73 | # ββ Builder stage βββββββββββββββββββββββββββββββββββββββββββββββββ
# Installs all dependencies including heavy ML packages.
# Kept separate so the final image is smaller.
FROM python:3.10-slim AS builder
WORKDIR /app
# System deps needed by some Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
# --extra-index-url pulls the CPU-only torch build (matches the local
# dev env: torch==2.12.0+cpu). Without it, pip resolves requirements.txt's
# plain "torch>=2.1.0" against default PyPI and pulls the CUDA build β
# adding ~2GB of unused NVIDIA libraries (cudnn, cusparselt, etc.) that
# this project never needs (it runs CPU-only everywhere, see classifier.py).
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt \
--extra-index-url https://download.pytorch.org/whl/cpu
# scispaCy + its own deps (conllu/pysbd/nmslib-metabrainz).
# --no-deps avoids scispaCy's spacy<3.8.0 pin clobbering the
# spacy>=3.7.0,<3.8.0 already installed via requirements.txt.
RUN pip install --no-cache-dir --no-deps scispacy==0.5.5 && \
pip install --no-cache-dir conllu pysbd "nmslib-metabrainz==2.1.3"
# en_core_sci_lg (~531 MB) β broad entity coverage.
# Separate layer so a network drop only retries this download,
# not the whole scispaCy install above.
# --timeout 300: S3 can stall on large files; 15s default is too short.
RUN pip install --no-cache-dir --no-deps --timeout 300 \
https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.4/en_core_sci_lg-0.5.4.tar.gz
# en_ner_bc5cdr_md (~100 MB) β DISEASE/CHEMICAL NER.
RUN pip install --no-cache-dir --no-deps --timeout 300 \
https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.4/en_ner_bc5cdr_md-0.5.4.tar.gz
# ββ Runtime stage βββββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:3.10-slim AS runtime
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Application code and the small public ICD-10 reference CSV.
# NOT copied: data/processed/ (cached embeddings) or data/models/
# (fine-tuned classifier) β both too large to ship in the image.
# ClinicalClassifier.load() and ICD10Mapper download them from
# HuggingFace Hub on first use instead (see ModelConfig fallback
# settings in src/utils/config.py).
COPY src/ ./src/
COPY dashboard/ ./dashboard/
COPY data/raw/ ./data/raw/
# Create writable dirs and non-root user before switching
RUN useradd --create-home appuser && \
mkdir -p /app/data/processed /app/data/models && \
chown -R appuser:appuser /app/data
USER appuser
# The API port β Railway/Render assign this via $PORT at runtime
EXPOSE 8000
# Shell form so $PORT is actually expanded; falls back to 8000 for
# local `docker run` testing where $PORT isn't set.
CMD ["sh", "-c", "exec uvicorn src.api.main:app --host 0.0.0.0 --port ${PORT:-8000}"]
|