File size: 3,278 Bytes
54c3f8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ──────────────────────────────────────────────────────────────────────────────
# Dockerfile β€” Flash Flood Risk API
#
# Targets Hugging Face Spaces (Docker SDK, port 7860).
# Uses CPU-only PyTorch to keep the image small (~1 GB vs ~5 GB for CUDA).
#
# Build & run locally:
#   docker build -t flood-api .
#   docker run -p 7860:7860 flood-api
#
# Then open: http://localhost:7860/docs
# ──────────────────────────────────────────────────────────────────────────────

FROM python:3.11-slim

# ── System metadata ────────────────────────────────────────────────────────────
LABEL maintainer="NMIMS Hack Team"
LABEL description="Flash Flood Risk Inference API β€” FastAPI + LSTM"

WORKDIR /app

# ── Install CPU-only PyTorch FIRST ─────────────────────────────────────────────
# The default PyPI torch wheel bundles CUDA (~2.5 GB).
# The official CPU wheel from pytorch.org is ~220 MB.
RUN pip install --no-cache-dir \

    "torch==2.6.0" \
    --index-url https://download.pytorch.org/whl/cpu

# ── Install remaining serving dependencies ─────────────────────────────────────
# Copy only the slim requirements file (not the full training requirements.txt)
COPY requirements-serve.txt .
RUN pip install --no-cache-dir -r requirements-serve.txt

# ── Copy application source ─────────────────────────────────────────────────────
COPY src/ src/
COPY configs/ configs/

# ── Copy model artifacts ────────────────────────────────────────────────────────
# scaler.joblib  β€” StandardScaler fitted on training data
COPY artifacts/scaler.joblib artifacts/scaler.joblib

# best.pt        β€” nowcast model  (used by /predict)
# forecast_24h.pt β€” 24h forecast model (used by /forecast)
COPY models/best.pt models/best.pt
COPY models/forecast_24h.pt models/forecast_24h.pt

# ── Hugging Face Spaces expects port 7860 ──────────────────────────────────────
EXPOSE 7860

# ── Run ────────────────────────────────────────────────────────────────────────
# --host 0.0.0.0  β€” accept connections from outside the container
# --port 7860     β€” HF Spaces default; override with -e PORT=xxxx if needed
CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "7860"]