File size: 1,513 Bytes
df0da91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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"]