ts-anomaly-api / Dockerfile
stevenmcdermott's picture
Upload Dockerfile
df0da91 verified
# Dockerfile β€” Hugging Face Spaces backend
# Builds the FastAPI benchmark API, exposed on port 7860.
#
# Deploy steps:
# 1. Create a new HF Space (Docker SDK) at huggingface.co/spaces
# 2. Push this repo (or mirror it) to that Space's git remote
# 3. HF will build and serve the image automatically
FROM python:3.11-slim
WORKDIR /app
# System deps: git (for HF model downloads), build tools for numpy/scipy
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# ── Install API dependencies first (better Docker layer caching) ──
COPY api/requirements.txt /tmp/api-requirements.txt
RUN pip install --no-cache-dir -r /tmp/api-requirements.txt
# ── Install PyTorch CPU build (smaller than CUDA, sufficient for MOMENT) ──
RUN pip install --no-cache-dir \
torch==2.1.0+cpu \
torchvision==0.16.0+cpu \
--index-url https://download.pytorch.org/whl/cpu
# ── Install benchmark dependencies (torch already satisfied above) ──
COPY ts-anomaly-benchmark/requirements.txt /tmp/benchmark-requirements.txt
RUN pip install --no-cache-dir -r /tmp/benchmark-requirements.txt
# ── Copy source code ──
COPY ts-anomaly-benchmark/ /app/ts-anomaly-benchmark/
COPY api/ /app/api/
# Make benchmark modules importable as top-level packages
ENV PYTHONPATH="/app/ts-anomaly-benchmark"
# HF Spaces requires port 7860
EXPOSE 7860
CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "7860"]