FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 python3-pip git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# PyTorch CUDA-Wheels zuerst, damit diffusers nicht CPU-Torch zieht.
# Torch 2.5+ ist Pflicht: aktuelle transformers (4.50+, von diffusers
# transitiv reingezogen) registriert in integrations/moe.py einen
# custom_op mit String-Forward-References (`input: 'torch.Tensor'`).
# Erst torch 2.5's infer_schema kann die aufloesen — 2.4.1 crasht mit
# "Parameter input has unsupported type torch.Tensor" beim Import von
# diffusers.pipelines.flux.pipeline_flux.
# torchvision wird von den CLIP-/Siglip-ImageProcessors verlangt.
# cu121 bleibt — passt zum CUDA 12.2 Base-Image.
RUN pip3 install --no-cache-dir \
        torch==2.5.1 torchvision==0.20.1 \
    --index-url https://download.pytorch.org/whl/cu121

COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY bridge.py .

CMD ["python3", "bridge.py"]
