picobyte / stable-diffusion-webui-wd14-tagger

Labeling extension for Automatic1111's Web UI
580 stars 70 forks source link

fix: variable access issues #24

Closed guansss closed 1 year ago

guansss commented 1 year ago

This fixes two errors:

  1. UnboundLocalError: local variable 'data' referenced before assignment when model.json is missing (after a fresh install).

  2. TypeError: expected str, bytes or os.PathLike object, not NoneType when setting input directory in the UI. Reproduction steps:

    1. After SD startup, go to the Tagger tab
    2. Fill in `Output directory`
    3. Check `Unload model after running` (maybe other operations also have the same effect, but I didn't test it)
    4. Fill in `Input directory` and click somewhere else
picobyte commented 1 year ago

good catch, the second part may change I am also debugging there

picobyte commented 1 year ago

Actually, looking more closely and at this file,

json_pp < models/interrogators/model.json

it looks like, if already existing that this json file just keeps appending the same entries.

so I think better would be

        data = [download_model]

        if not os.path.exists(mdir):
            os.mkdir(mdir)

        elif os.path.exists(mpath):
            with io.open(file=mpath, mode='r', encoding='utf-8') as filename:
                try:
                    data = json.load(filename)
                    # No need to append if it's already contained
                    if download_model not in data:
                        data.append(download_model)
                except ...

right?

guansss commented 1 year ago

Ah, yeah, would be good to avoid duplicates!

picobyte commented 1 year ago

I've already fixed it, also going over your second change. I was having some issues there as well:

batch interrogate dir with images
batch interrogate dir without
=> path / output does not change

(actually in my feature branch) thanks!