diff --git a/backend/app/api/tags.py b/backend/app/api/tags.py index 31aee4e..0556ed9 100644 --- a/backend/app/api/tags.py +++ b/backend/app/api/tags.py @@ -320,27 +320,6 @@ async def common_tags(): return jsonify({"tags": tags}) -@tags_bp.route("/images/cluster/tag-gaps", methods=["POST"]) -async def cluster_tag_gaps(): - """Cluster-consensus tag gaps for a visual neighbour set (#94 Explore): - tags on >= threshold of the images but not all. Each gap carries the - laggard image ids (minus rejections) for apply-to-cluster.""" - body = await request.get_json() - ids, err = _parse_bulk_ids(body) - if err: - return err - try: - threshold = float(body.get("threshold", 0.6)) - except (TypeError, ValueError): - threshold = 0.6 - threshold = min(1.0, max(0.0, threshold)) - async with get_session() as session: - gaps = await BulkTagService(session).tag_gaps(ids, threshold) - return jsonify( - {"gaps": gaps, "total": len(set(ids)), "threshold": threshold} - ) - - @tags_bp.route("/images/bulk/tags", methods=["POST"]) async def bulk_add_tag(): body = await request.get_json() diff --git a/backend/app/services/bulk_tag_service.py b/backend/app/services/bulk_tag_service.py index 57d673c..b573ef9 100644 --- a/backend/app/services/bulk_tag_service.py +++ b/backend/app/services/bulk_tag_service.py @@ -1,7 +1,5 @@ """Bulk tag operations over a set of images (Core, set-based, atomic).""" -import math - from sqlalchemy import and_, func, select from sqlalchemy.dialects.postgresql import insert as pg_insert from sqlalchemy.ext.asyncio import AsyncSession @@ -15,85 +13,6 @@ class BulkTagService: def __init__(self, session: AsyncSession): self.session = session - async def tag_gaps( - self, image_ids: list[int], threshold: float - ) -> list[dict]: - """Cluster-consensus tag gaps (#94 Explore): tags applied to at least - `threshold` fraction of the image set but NOT all of it — the - "7 of these 10 share Hatsune Miku; these 3 don't" signal. - - For each gap, `missing_image_ids` are the set members that LACK the tag - and have NOT rejected it (TagSuggestionRejection) — so apply-to-cluster - never re-proposes a tag a neighbor explicitly dismissed. A tag on every - image is "common", not a gap; a tag on fewer than 2 isn't consensus. - """ - ids = list({int(i) for i in image_ids}) - if len(ids) < 2: - return [] - n = len(ids) - min_present = max(2, math.ceil(threshold * n)) - if min_present >= n: - return [] # threshold so high only a 100%-common tag could qualify - - cnt = func.count(func.distinct(image_tag.c.image_record_id)) - gap_rows = ( - await self.session.execute( - select(Tag.id, Tag.name, Tag.kind) - .join(image_tag, image_tag.c.tag_id == Tag.id) - .where(image_tag.c.image_record_id.in_(ids)) - .group_by(Tag.id, Tag.name, Tag.kind) - .having(and_(cnt >= min_present, cnt < n)) - .order_by(cnt.desc(), Tag.name.asc()) - ) - ).all() - if not gap_rows: - return [] - gap_ids = [r.id for r in gap_rows] - - present: dict[int, set[int]] = {} - for tid, iid in ( - await self.session.execute( - select(image_tag.c.tag_id, image_tag.c.image_record_id).where( - image_tag.c.tag_id.in_(gap_ids), - image_tag.c.image_record_id.in_(ids), - ) - ) - ).all(): - present.setdefault(tid, set()).add(iid) - - rejected: dict[int, set[int]] = {} - for tid, iid in ( - await self.session.execute( - select( - TagSuggestionRejection.tag_id, - TagSuggestionRejection.image_record_id, - ).where( - TagSuggestionRejection.tag_id.in_(gap_ids), - TagSuggestionRejection.image_record_id.in_(ids), - ) - ) - ).all(): - rejected.setdefault(tid, set()).add(iid) - - id_set = set(ids) - gaps = [] - for r in gap_rows: - have = present.get(r.id, set()) - missing = id_set - have - rejected.get(r.id, set()) - if not missing: - continue # every laggard rejected it — nothing to apply - gaps.append( - { - "tag_id": r.id, - "name": r.name, - "kind": r.kind.value if hasattr(r.kind, "value") else str(r.kind), - "present_count": len(have), - "total": n, - "missing_image_ids": sorted(missing), - } - ) - return gaps - async def common_tags(self, image_ids: list[int]) -> list[dict]: """Tags present on EVERY image in image_ids.""" if not image_ids: diff --git a/frontend/src/components/modal/ProvenancePanel.vue b/frontend/src/components/modal/ProvenancePanel.vue index 95d0630..2bd8309 100644 --- a/frontend/src/components/modal/ProvenancePanel.vue +++ b/frontend/src/components/modal/ProvenancePanel.vue @@ -97,9 +97,19 @@ import { useProvenanceStore } from '../../stores/provenance.js' import { formatPostDate } from '../../utils/date.js' import { toPlainText } from '../../utils/htmlSanitize.js' +// `imageId`/`image` let a non-modal surface (the Explore workspace) render +// provenance for its anchor. Default to the modal store's current image so the +// image modal is unchanged. Provenance is its own system (loaded by id via the +// provenance store), so it only needs the right id + the artist fallback. +const props = defineProps({ + imageId: { type: Number, default: null }, + image: { type: Object, default: null }, +}) const modal = useModalStore() const prov = useProvenanceStore() const router = useRouter() +const effectiveId = computed(() => props.imageId ?? modal.currentImageId) +const effectiveImage = computed(() => props.image ?? modal.current) // Per-post description collapse state (keyed by provenance_id). Default // collapsed so multiple posts don't each eat ~180px of the panel — the @@ -107,21 +117,21 @@ const router = useRouter() // 2026-05-28. Reset when the viewed image changes. const expanded = reactive({}) function toggleDesc(id) { expanded[id] = !expanded[id] } -watch(() => modal.currentImageId, () => { +watch(() => effectiveId.value, () => { for (const k of Object.keys(expanded)) delete expanded[k] }) watch( - () => modal.currentImageId, + () => effectiveId.value, (id) => { if (id != null) prov.loadForImage(id) }, { immediate: true } ) const state = computed(() => - modal.currentImageId == null ? null : prov.imageProv(modal.currentImageId) + effectiveId.value == null ? null : prov.imageProv(effectiveId.value) ) -const fallbackArtist = computed(() => modal.current?.artist || null) +const fallbackArtist = computed(() => effectiveImage.value?.artist || null) const showArtistFallback = computed(() => { const st = state.value diff --git a/frontend/src/components/modal/TagPanel.vue b/frontend/src/components/modal/TagPanel.vue index 4f0d335..0e76142 100644 --- a/frontend/src/components/modal/TagPanel.vue +++ b/frontend/src/components/modal/TagPanel.vue @@ -30,7 +30,15 @@ @accepted="focusTagInput" /> - + + - -