News:

Please request registration email again and then check your "Spam" folder

Former www.henthighschool.com

BK Autotagger

Started by Ch12, Feb 23, 2025, 05:37 PM

Previous topic - Next topic

Bloonut34

#15
I've run into an interesting issue. I can get the autotagger to work (accuracy notwithstanding) on individual folders just fine, but it has an issue with subdirectories. I can get the webUI to tag multiple folders at once using "\**", but running bk-autotagger.bat gives me an error: FileNotFoundError: [Errno 2] No such file or directory: 'imagepacks/[folder]/db.json'

(And it leaves txt files even when "Save to tags files" isn't checked. The autotagging issue happens whether or not I've deleted these txt files before running the autotagger.)

But I can run the tagger on each individual folder, leaving a db file in each one, and then I can run bk-autotagger.bat once and it leaves an autotagged folder in each subdirectory then. Is the ability to work thru each sub-folder from one db file something that could be available in the future?
Here's a link to my girlpacks.

InfiniteTomorrow

#16
Ok either i missed smthn but this ok...

WebUI >> gets u general tags
This thing BK Autotagger 1.0. converts those tags into usable tags.

so download BK Autotagger 1.0, put ur untagged stuff in the imagepacks dir (make a folder so imagepacks\'mysuperduperpack')
- run the bk-autotagger_initialInstall.bat now so it installs dependecies -

Go to webUI and set the input dir to imagepacks\'mysuperduperpack' from earlier. then run webUI (ull haffa figure out how to set that up did it ages ago and forgot) and itll tag <uncgeck 'save to tags files' so u get the json and not a nunch of txt>
a db.json will appear in the pack

Now run the _run.bat or the main.py or bk-autotagger.bat
when its done a new file called autotagged will show up

Now in BK-Autotagger-1.0\bk-autotagger make a new text file and name it to 'rename.txt'

paste this:

import os
import pandas as pd

# === CONFIG ===
base = r"D:\Games\b\BK-Autotagger-1.0\bk-autotagger\imagepacks\t"
csv_path = os.path.join(base, "autotagged", "_predictions.csv")
src_dir = base
rename_dir = os.path.join(base, "renamed")

os.makedirs(rename_dir, exist_ok=True)
print("Reading CSV:", csv_path)

# Read the CSV
df = pd.read_csv(csv_path, header=0, names=["raw"], encoding="utf-8")

renamed_count = 0
missing_count = 0

for _, row in df.iterrows():
    raw = str(row["raw"]).strip()
    if not raw or "." not in raw:
        continue

    parts = raw.split()
    filename = parts[0].replace("t\\", "").replace("t/", "")
    tags = parts[1:]
    if not tags:
        tags = ["untagged"]

    # Join tags with spaces, but replace illegal chars with safe ones
    joined_tags = " ".join(tags)
    safe_tags = joined_tags.replace("/", "-").replace("\\", "-").replace(":", "-").replace("*", "-").replace("?", "-").replace("\"", "").replace("<", "").replace(">", "").replace("|", "")

    # Limit to 100 characters for Windows safety
    safe_tags = safe_tags[:100].rstrip()

    old_path = os.path.join(src_dir, filename)
    if not os.path.exists(old_path):
        print(f"⚠ Missing file: {filename}")
        missing_count += 1
        continue

    # Keep only the file extension
    _, ext = os.path.splitext(filename)
    new_name = f"{safe_tags}{ext}".strip()
    new_path = os.path.join(rename_dir, new_name)

    # Prevent overwriting if same name appears twice
    counter = 1
    while os.path.exists(new_path):
        new_name = f"{safe_tags} ({counter}){ext}"
        new_path = os.path.join(rename_dir, new_name)
        counter += 1

    os.rename(old_path, new_path)
    renamed_count += 1
    print(f"✔ Renamed: {filename} → {new_name}")

# === SUMMARY ===
print("\n====== DONE ======")
print(f"✅ Renamed: {renamed_count}")
print(f"❌ Missing: {missing_count}")
print(f"📁 Output folder: {rename_dir}")


Save the file and rename it 'rename.py'

Then click on it to run the new rename.py

The tagged files will be in \bk-autotagger\imagepacks\'mysuperduperpack'\renamed


So far the tagging is p bad lol. Gonna mess around with webUI and improve it if I can but at least this part is automated....mb if it already existed

Edit1:
Switched the preset to settings_bk.json. dunno where i got it or when but that definetly helped lol


These are my notes but they can be yours too!

Jman

#17
When I last tried it, 'autotagged' was already a directory with the renamed files and none of this vibe-coded renaming stuff was necessary.

Has something changed?

At least Sill got tagged passably well, so I do wonder what kind of examples you have where the tagging is 'p bad lol'?
And with strange aeons even death may die...

InfiniteTomorrow

i be fixing problems that dont exist. whatever i did its working now....