feat(suggestions): auto-accept threshold + retroactive blocklist sweep
Two capabilities that work together to turn the suggestion system from
a 'review every noisy chip' UX into a 'curated tags only, configurable
auto-apply' UX for a solo-user library.
Auto-accept threshold
Service (tag_suggestions.py):
- New default auto_accept_general_threshold = 0.95 in _DEFAULTS
- get_suggestions splits general-category hits at/above the threshold
into a separate auto_accept_candidates list; the core 'character'/
'copyright'/'general' keys stay the same shape for existing callers
- get_bulk_suggestions ignores the new key (no side effects in bulk)
Route (main.py GET /image/<id>/suggestions):
- For each candidate: find-or-create Tag(kind='user', name=name), attach
to image, log SuggestionFeedback(source='wd14'|etc, decision='accepted')
- Response adds 'auto_accepted: [{id, name, display_name, kind,
confidence, source}, ...]' so the modal can review + undo
Config endpoints (main.py):
GET /api/suggestions/config/auto-accept-threshold
POST /api/suggestions/config/auto-accept-threshold {threshold}
Values > 1.0 effectively disable the feature
UI (view-modal.js):
- New renderAutoAccepted block at top of suggestions section with
green-tinted chips carrying ✕ (undo for this image, logs rejection)
and ⊘ (blocklist + remove from all images)
- loadSuggestions refreshes the tag pill list when auto_accepted has
items so the user sees them in the Tags section too
Settings:
- Maintenance tab gains a number input + save button backed by
/api/suggestions/config/auto-accept-threshold
Retroactive blocklist sweep
New Celery task app.tasks.maintenance.sweep_blocklisted_tag_from_images
on the maintenance queue. Enqueued automatically when a name is added
via POST /api/suggestions/blocklist or appears new in the bulk replace.
Task body: finds kind='user' Tag matching the name, deletes its
image_tags rows, deletes the Tag itself. Scope limited to kind='user'
so deliberate character/fandom/artist tags sharing a blocklisted name
aren't silently destroyed.
Verification (local dev):
- Threshold GET/POST round-trip correct (default 0.95, persisted in
tag_suggestion_config)
- Image 633 at threshold=0.9: 4 general tags auto-applied, each with
a SuggestionFeedback row, returned in auto_accepted
- Blocklist add of 'sweeptestonly' with an attached test tag: Redis
maintenance queue depth = 1, task body removes 1 image_tags row +
the Tag row
- get_bulk_suggestions still works (auto_accept_candidates key skipped)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,10 @@ _DEFAULTS = {
|
||||
'threshold_meta': 0.5,
|
||||
'threshold_embedding': 0.85,
|
||||
'min_reference_images': 5.0,
|
||||
# Above this confidence, general-category suggestions are auto-applied
|
||||
# to the image by the route layer (see app.main.get_image_suggestions).
|
||||
# Use 1.1 or greater to effectively disable. Default is conservative.
|
||||
'auto_accept_general_threshold': 0.95,
|
||||
'wd14_model_version': 'wd-eva02-large-tagger-v3',
|
||||
'siglip_model_version': 'siglip-so400m-patch14-384',
|
||||
}
|
||||
@@ -246,17 +250,34 @@ def get_suggestions(
|
||||
if existing_all is None:
|
||||
existing_all = _existing_tag_names()
|
||||
|
||||
# Separate out general-category suggestions above the auto-accept
|
||||
# threshold. The route layer applies these to the image directly;
|
||||
# we just identify them here so the service remains side-effect-free.
|
||||
try:
|
||||
auto_accept_threshold = float(cfg.get('auto_accept_general_threshold',
|
||||
_DEFAULTS['auto_accept_general_threshold']))
|
||||
except (TypeError, ValueError):
|
||||
auto_accept_threshold = _DEFAULTS['auto_accept_general_threshold']
|
||||
auto_accept_candidates: list[dict] = []
|
||||
|
||||
grouped: dict[str, list[dict]] = {'character': [], 'copyright': [], 'general': []}
|
||||
for s in merged:
|
||||
if s['category'] not in grouped:
|
||||
continue # meta / rating / artist / unknown are dropped
|
||||
s['exists_in_db'] = s['name'] in existing_all
|
||||
if s['category'] == 'general' and s['confidence'] >= auto_accept_threshold:
|
||||
auto_accept_candidates.append(s)
|
||||
continue
|
||||
grouped[s['category']].append(s)
|
||||
|
||||
for cat in grouped:
|
||||
grouped[cat].sort(key=lambda x: x['confidence'], reverse=True)
|
||||
grouped[cat] = grouped[cat][:top_k_per_category]
|
||||
|
||||
# Stash candidates in a way the shape documents but legacy callers can
|
||||
# ignore. We keep the three core keys at the top level for backwards
|
||||
# compat and add a 4th list.
|
||||
grouped['auto_accept_candidates'] = auto_accept_candidates
|
||||
return grouped
|
||||
|
||||
|
||||
@@ -308,6 +329,11 @@ def get_bulk_suggestions(
|
||||
existing_all=existing_all,
|
||||
)
|
||||
for category, items in grouped.items():
|
||||
# `auto_accept_candidates` is returned by get_suggestions for the
|
||||
# single-image route to apply; skip in bulk (bulk has no single
|
||||
# image to attach to).
|
||||
if category == 'auto_accept_candidates':
|
||||
continue
|
||||
for item in items:
|
||||
name = item['name']
|
||||
stat = tag_stats.get(name)
|
||||
|
||||
Reference in New Issue
Block a user