# backend/requirements-cv.txt
# OPTIONAL face-restoration extra (gfpgan / realesrgan) for the shared backend venv.
#
# WHY THIS FILE EXISTS (P3-10b, edge-portability):
# These packages have thin or absent prebuilt wheels on aarch64 (Raspberry Pi)
# and frequently FAIL TO BUILD FROM SOURCE there. When they lived in the main
# requirements they aborted the ENTIRE `pip install` before chat/RAG was even
# usable, bricking a chat-only install on a Pi. They are NOT imported by any
# always-on path. The one consumer imports them lazily, inside a try/except:
#   - gfpgan / realesrgan / basicsr / facexlib -> backend/services/face_restoration_service.py
#       (guarded module-top try/except; only reached via offline_image_generator
#        and batch_image_generation_api, both lazy `from ... import` calls)
# When absent, that service sets `restoration_available=False` and degrades
# gracefully — no crash.
#
# INSTALL (on a box that wants face restoration):
#   pip install -r backend/requirements-cv.txt
# AFTER torch is installed by scripts/install_pytorch.sh (these build against torch),
# and under backend/constraints.txt (PIP_CONSTRAINT), which pins the opencv
# distributions and the numpy line the ML stack is built against.
#
# NOTE: basicsr 1.4.2 imports torchvision.transforms.functional_tensor, removed
# in torchvision 0.17+. face_restoration_service.py already aliases it back at
# import time, so this stays installable against current torch.

# --- Face Restoration & Enhancement ---
gfpgan==1.3.8          # Downgraded from 1.3.8 for torchvision compatibility
realesrgan==0.3.0
facexlib==0.3.0        # transitive (pulled by gfpgan); pinned for reproducibility
basicsr>=1.4.2         # Required by GFPGAN and RealESRGAN
lmdb>=1.0.0            # Required by GFPGAN/basicsr (no first-party import)
tb-nightly             # Required by GFPGAN (optional at runtime, recommended)

# --- Imaging backend (cv2) ---
# opencv-python is the ONE declared distribution for the shared venv: gfpgan,
# realesrgan, basicsr, facexlib and rapidocr all require it by that name, and
# pip does not accept opencv-python-headless as a substitute. The three opencv
# distributions unpack into the same cv2/ directory, so backend/constraints.txt
# locks all three names to one version; any -headless/-contrib a transitive dep
# brings in then matches these files instead of replacing them. cv2 is also
# used by the upscaling and vision_pipeline plugins, ComfyUI video nodes and
# rapidocr (docling), all in this venv.
opencv-python
