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

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

Open
trihardseven opened this issue Feb 6, 2024 · 8 comments

Comments

@trihardseven
Copy link

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
Copy link
Owner

Inzaniak commented Feb 6, 2024

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
Copy link
Author

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

@trihardseven
Copy link
Author

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
Copy link
Owner

Inzaniak commented Feb 6, 2024

I've updated the code (75d5e76), 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
Copy link
Author

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
Copy link
Owner

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

@trihardseven
Copy link
Author

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
Copy link
Author

trihardseven commented Feb 19, 2024

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)                
   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants