Inzaniak / sd-webui-ranbooru

71 stars 7 forks source link

[Feature Request] WD14 Tagger/Deepdanbooru on image before generating #24

Open trihardseven opened 9 months ago

trihardseven commented 9 months ago

I find that a lot of the images in the boorus lack the proper tagging, and while using the tags directly can yield good results sometimes, I get way better results when I run the image through the Tagger extension with a model like WD14 SwinV2 and add to the booru tags.

Would it be possible to have an option to run a tagging program like that before generating? Thank you for your time, just found this extension and looks really fun to use.

Inzaniak commented 9 months ago

Hey! You can do this using the img2img tab and setting it like this: image This uses the same model which is utilized by Automatic1111.

trihardseven commented 9 months ago

Thanks! It works way better now. Is there a way to run the WD14 models instead of Deepbooru?

trihardseven commented 9 months ago

Oh, I just realized its taking the images and running them in img2img instead of t2i. Unfortunately using this method it seems stuck in 512-768x and no high res fix

Inzaniak commented 9 months ago

I've updated the code (https://github.com/Inzaniak/sd-webui-ranbooru/commit/75d5e76756a814eb671d785cfcd17e6bfcc3d870), this should give you the ability to run Deepbooru without enabling the img2img flag. I am not sure if WD14 can be implemented, because right now I'm just using the standard implementation available in Automatic1111, while implementing WD14 will need to run it from another extension which requires more work to implement.

trihardseven commented 9 months ago

Thanks a lot, just tried it and it works great! Very fun to leave it on generate forever and come back later to see what it made. I did notice it doesn't add the scanned tags to the danbooru tags, it replaces them all instead. I think it would be better if it only replaced duplicates, not sure if it's possible.

Inzaniak commented 9 months ago

I've added a new button in the img2img panel which changes the way tags are added when using deepbooru.

trihardseven commented 9 months ago

Awesome! I just tried it and I'm getting the following error though:

*** Error running before_process: N:\AI\Forge\stable-diffusion-webui-forge\extensions\sd-webui-ranbooru\scripts\ranbooru.py
    Traceback (most recent call last):
      File "N:\AI\Forge\stable-diffusion-webui-forge\modules\scripts.py", line 795, in before_process
        script.before_process(p, *script_args)
      File "N:\AI\Forge\stable-diffusion-webui-forge\extensions\sd-webui-ranbooru\scripts\ranbooru.py", line 782, in before_process
        p.prompt = modify_prompt(p.prompt, tagged_prompts, type_deepbooru)
      File "N:\AI\Forge\stable-diffusion-webui-forge\extensions\sd-webui-ranbooru\scripts\ranbooru.py", line 370, in modify_prompt
        return tagged_prompt + ',' + prompt
    TypeError: can only concatenate list (not "str") to list

Any idea what it could be? I tried reinstalling the extension but it didn't help

trihardseven commented 9 months ago

Editing this part of the code seems to have fixed it:

def modify_prompt(prompt, tagged_prompt, type_deepbooru):
    """Modifies the prompt based on the type_deepbooru selected

    Args:
        prompt (str): the prompt
        tagged_prompt (str): the prompt tagged by deepbooru
        type_deepbooru (str): the type of modification

    Returns:
        str: the modified prompt
    """
    if isinstance(tagged_prompt, list):
        tagged_prompt = ','.join(tagged_prompt)
    if isinstance(prompt, list):
        prompt = ','.join(prompt)

    if type_deepbooru == 'Add Before':
        modified_prompt = tagged_prompt + ',' + prompt
    elif type_deepbooru == 'Add After':
        modified_prompt = prompt + ',' + tagged_prompt
    elif type_deepbooru == 'Replace':
        modified_prompt = tagged_prompt
    else:
        modified_prompt = prompt

    return remove_repeated_tags(modified_prompt)