fix(suggestions): resolve bare WD14 character names to existing "(Fandom)" tags
WD14 emits bare names (e.g. "Ruby Rose") while curated character/fandom
tags carry a fandom suffix ("Ruby Rose (RWBY)"). Two gaps caused a
duplicate, fandom-less tag to be created when users accepted a WD14
suggestion for an image that already had the curated version:
- Suggestion compute: bare character/copyright suggestions are now
suppressed when the image already carries a `Name (Fandom)` variant,
so the duplicate chip no longer surfaces.
- Accept endpoint: if the exact-name lookup misses for character/fandom
kinds, we try a `Name (%)`-scoped lookup and attach the existing tag
only when exactly one candidate matches. Zero or multiple matches
fall through to prior behavior to avoid silently guessing across
ambiguous fandoms.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+21
-3
@@ -767,9 +767,27 @@ def accept_image_suggestion(image_id):
|
||||
tag = Tag.query.filter_by(name=tag_name).first()
|
||||
if tag is None:
|
||||
kind = _WD14_CATEGORY_TO_KIND.get(category) # None for 'general'
|
||||
tag = Tag(name=tag_name, kind=kind)
|
||||
db.session.add(tag)
|
||||
db.session.flush()
|
||||
# WD14 emits bare names ("Ruby Rose") while curated character/fandom tags
|
||||
# carry a fandom suffix ("Ruby Rose (RWBY)"). Try to auto-resolve a bare
|
||||
# suggestion to an existing fandom-scoped tag — but only when exactly one
|
||||
# candidate exists; zero/multiple falls through to creating a new tag so
|
||||
# we don't silently guess across ambiguous matches (e.g. same name in
|
||||
# multiple fandoms).
|
||||
if kind in ('character', 'fandom'):
|
||||
candidates = (
|
||||
Tag.query
|
||||
.filter(Tag.kind == kind)
|
||||
.filter(Tag.name.ilike(f'{tag_name} (%)'))
|
||||
.limit(2)
|
||||
.all()
|
||||
)
|
||||
if len(candidates) == 1:
|
||||
tag = candidates[0]
|
||||
tag_name = tag.name # feedback row logs the resolved name
|
||||
if tag is None:
|
||||
tag = Tag(name=tag_name, kind=kind)
|
||||
db.session.add(tag)
|
||||
db.session.flush()
|
||||
|
||||
if tag not in image.tags:
|
||||
image.tags.append(tag)
|
||||
|
||||
Reference in New Issue
Block a user