FROM python:3.10-slim-bookworm

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    git wget curl ffmpeg build-essential libgl1 libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

RUN python -m pip install \
    pip==24.0 setuptools==69.5.1 wheel==0.43.0

RUN python -m pip install \
    torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 \
    --index-url https://download.pytorch.org/whl/cu118

COPY requirements.txt /app/requirements.txt

RUN printf '%s\n' \
    'torch==2.0.1' \
    'torchvision==0.15.2' \
    'torchaudio==2.0.2' \
    'numpy==1.23.4' \
    'numba==0.57.1' \
    'gradio==3.41.2' \
    'gradio-client==0.5.0' \
    'huggingface-hub==0.25.2' \
    'opencv-python==4.8.1.78' \
    'opencv-python-headless==4.8.1.78' \
    'gfpgan==1.3.8' \
    'av==12.3.0' \
    > /app/constraints.txt

RUN python -m pip install --no-build-isolation \
    -r /app/requirements.txt -c /app/constraints.txt

COPY . /app

RUN mkdir -p checkpoints gfpgan/weights results inputs \
    && python -m pip check \
    && python inference.py --help

CMD ["python", "inference.py", "--help"]
