Pagination (200/page), batched+checkpointed ingest (batch_size, resume-safe), quality max_files slicing, upload page; Caddy routes for prefect/photo-filter

This commit is contained in:
2026-08-08 13:36:00 +10:00
parent 1814b5c5c4
commit 0d20c29f35
7 changed files with 309 additions and 74 deletions

View File

@@ -86,9 +86,37 @@ def _move(p: Path, dest_root: Path, src_root: Path):
shutil.move(str(p), str(dest))
def _slice_dir(base_dir: str, max_files: int) -> str:
"""Copy first N images into a temp dir for CleanVision to audit."""
import shutil
import tempfile
from pathlib import Path
src = Path(base_dir)
tmp = Path(tempfile.mkdtemp(prefix="cvslice_"))
exts = {".jpg", ".jpeg", ".png", ".webp", ".gif", ".heic", ".tif", ".bmp"}
n = 0
for p in src.rglob("*"):
if p.is_file() and p.suffix.lower() in exts:
shutil.copy2(p, tmp / p.name)
n += 1
if n >= max_files:
break
print(f"_slice_dir: copied {n} files to {tmp}")
return str(tmp)
@flow(name="photo-quality-scan")
def quality_scan(base_dir: str, move: bool = False, notify: bool = True):
"""Audit image quality with CleanVision; classify into keep/review/delete."""
def quality_scan(base_dir: str, move: bool = False, notify: bool = True, max_files: int = None):
"""Audit image quality with CleanVision; classify into keep/review/delete.
max_files: if set, only audit the first N image files (slices huge folders
into reviewable chunks — prevents OOM on 50K-file trees).
"""
if max_files: # 0/None = unlimited
base_dir = _slice_dir(base_dir, max_files)
audit = audit_folder(base_dir)
print(f"Issue summary: {audit['summary']}")
result = classify_and_sort(base_dir, audit["per_image"], move=move)