# syntax=docker/dockerfile:1 FROM python:3.10-slim ARG TORCH_VARIANT=cpu ARG TORCH_INDEX=https://download.pytorch.org/whl/${TORCH_VARIANT} WORKDIR /app RUN apt-get update && apt-get install -y --no-install-recommends libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir "typing-extensions==4.12.2" "numpy==2.2.6" RUN pip install --no-cache-dir torch torchvision --index-url ${TORCH_INDEX} RUN pip install --no-cache-dir --no-deps basicsr==1.4.2 realesrgan==0.3.0 gfpgan==1.3.8 facexlib==0.3.0 && \ pip install --no-cache-dir "numpy==2.2.6" "opencv-python-headless==5.0.0.93" addict future lmdb Pillow pyyaml \ requests scikit-image scipy tqdm filterpy numba fastapi "uvicorn[standard]" python-multipart RUN BASICSR_DEG=$(python -c "import basicsr; import os; print(os.path.join(os.path.dirname(basicsr.__file__), 'data', 'degradations.py'))" 2>/dev/null) || \ BASICSR_DEG=$(find /usr/local/lib/python3.10 -path "*/basicsr/data/degradations.py" 2>/dev/null | head -1) && \ if [ -n "$BASICSR_DEG" ]; then \ sed -i 's/from torchvision.transforms.functional_tensor/from torchvision.transforms.functional/g' "$BASICSR_DEG" && \ echo "basicsr patch applied to $BASICSR_DEG"; \ else \ echo "basicsr degradations.py not found, skipping patch"; \ fi COPY app.py ./ COPY fetch-weights.py ./ COPY vendor/ ./vendor/ ENV PHOTO_AI_MODELS_DIR=/models ENV MODEL_PATH=/models/RealESRGAN_x2plus.pth ENV PHOTO_AI_SEED_DIR=/opt/photo-ai-seed ARG PHOTO_AI_PREFETCH=codeformer RUN --mount=type=cache,target=/var/cache/photo-ai-weights,sharing=locked \ mkdir -p "$PHOTO_AI_SEED_DIR" && \ if [ -n "$PHOTO_AI_PREFETCH" ] && [ "$PHOTO_AI_PREFETCH" != "none" ]; then \ python fetch-weights.py "$PHOTO_AI_SEED_DIR" /var/cache/photo-ai-weights || echo "предзагрузка весов не удалась, сервис скачает их при первом запросе"; \ else \ echo "предзагрузка весов отключена (PHOTO_AI_PREFETCH=$PHOTO_AI_PREFETCH)"; \ fi VOLUME /models CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"]