Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with custom tag lists #1539

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions ai_diffusion/ui/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,21 @@ def _reload_tag_model(self):

with tag_path.open("r", encoding="utf-8") as f:
csv_reader = csv.reader(f)
# skip header line
next(csv_reader)
for tag, type_str, count, _aliases in csv_reader:
tag = tag.replace("_", " ")
tag_type = TagType(int(type_str))
count = int(count)
count_str = str(count)
if count > 1_000_000:
count_str = f"{count/1_000_000:.0f}m"
elif count > 1_000:
count_str = f"{count/1_000:.0f}k"
meta = f"{tag_name} {count_str}"
all_tags.append(TagItem(tag, tag_type, count, meta))
if type_str.isdigit(): # skip header rows if they exist
tag = tag.replace("_", " ")
try:
tag_type = TagType(int(type_str))
except: # default to general category if category is not recognised
tag_type = TagType(0)
count = int(count)
count_str = str(count)
if count > 1_000_000:
count_str = f"{count/1_000_000:.0f}m"
elif count > 1_000:
count_str = f"{count/1_000:.0f}k"
meta = f"{tag_name} {count_str}"
all_tags.append(TagItem(tag, tag_type, count, meta))

sorted_tags = sorted(all_tags, key=lambda x: x.count, reverse=True)
seen = set()
Expand Down