KohakuBlueleaf / a1111-sd-webui-lycoris

An extension for stable-diffusion-webui to load lycoris models.
Apache License 2.0
861 stars 116 forks source link

LyCORIS not show on extra network #64

Closed n714 closed 9 months ago

n714 commented 1 year ago

running SD 1.5.1 LyCORIS not show on extra network

i put all LyCORIS into lora folder, but it not list on web ui

makonli commented 1 year ago

in version 1.5, put it in a folder LORA

anonfaker commented 1 year ago

I moved my Lycoris files into my Lora folder but now when trying to generate images it uses <lora: and doesn't work, but when you change to <lyco: it does work correctly - what should we do

Nrgte commented 1 year ago

I'm missing the LyCORIS tab too. This is extremly frustrating.

Alverik commented 1 year ago

I got automatic1111 v1.60 and skipped installing the Lycoris extension, but even when I put my Lycoris files inside the webui/models/Lora folder (giving them their own folder "Z-Lycoris" so they always appear last), they never appear in the Lora tab...

I miss having a separate Lycoris tab too, haha... (I liked the differentiation since Lycoris are often higher quality than Lora, and I have a ton of Lora).

Nrgte commented 1 year ago

For those who want the LyCORIS tab back. Here's a workaround. Change the following files. It turns the extension into a UI placebo. The lyco apply will be made by the normal Lora extension, but you can load lycos in the UI like you've used to if you have them in the models/lycoris folder.

scripts/lycoris_script.py

import gradio as gr

import lycoris
import extra_networks_lyco
import ui_extra_networks_lyco
from modules import script_callbacks, ui_extra_networks, extra_networks, shared

def before_ui():
    ui_extra_networks.register_page(ui_extra_networks_lyco.ExtraNetworksPageLyCORIS())
    extra_networks.register_extra_network(extra_networks_lyco.ExtraNetworkLyCORIS())

script_callbacks.on_model_loaded(lycoris.assign_lyco_names_to_compvis_modules)
script_callbacks.on_before_ui(before_ui)

shared.options_templates.update(shared.options_section(('extra_networks', "Extra Networks"), {
    "sd_lyco": shared.OptionInfo("None", "Add LyCORIS to prompt", gr.Dropdown, lambda: {"choices": ["None"] + [x for x in lycoris.available_lycos]}, refresh=lycoris.list_available_lycos),
}))

extra_networks_lyco.py

from modules import extra_networks, shared
import lycoris
from lyco_logger import logger

default_args = [
    ('te', 1.0, float),
    ('unet', None, float),
    ('dyn', None, int)
]

def parse_args(params:list):
    arg_list = []
    kwarg_list = {}

    for i in params:
        if '=' in str(i):
            k, v = i.split('=', 1)
            kwarg_list[k] = v
        else:
            arg_list.append(i)

    args = []
    for name, default, type in default_args:
        if name in kwarg_list:
            x = kwarg_list[name]
        elif arg_list:
            x = arg_list.pop(0)
        else:
            x = default

        if x == 'default':
            x = default
        elif x is not None:
            x = type(x)

        args.append(x)

    return args

class ExtraNetworkLyCORIS(extra_networks.ExtraNetwork):
    def __init__(self, base_name = 'lycoris'):
        super().__init__(base_name)
        self.base_name = base_name
        self.cache = ()

    def activate(self, p, params_list):
        if self.base_name == 'lora':
            additional = shared.opts.sd_lora
        elif self.base_name == 'lycoris':
            additional = shared.opts.sd_lyco

        if additional != "" and additional in lycoris.available_lycos and len([x for x in params_list if x.items[0] == additional]) == 0:
            p.all_prompts = [
                x + 
                f"<{self.base_name}:{additional}:{shared.opts.extra_networks_default_multiplier}>" 
                for x in p.all_prompts
            ]
            params_list.append(
                extra_networks.ExtraNetworkParams(
                    items=[additional, shared.opts.extra_networks_default_multiplier])
                )

        names = []
        te_multipliers = []
        unet_multipliers = []
        dyn_dims = []
        for params in params_list:
            assert len(params.items) > 0

            names.append(params.items[0])
            te, unet, dyn_dim = parse_args(params.items[1:])
            if unet is None:
                unet = te
            te_multipliers.append(te)
            unet_multipliers.append(unet)
            dyn_dims.append(dyn_dim)

        all_lycos = tuple(
            (name, te, unet, dyn)
            for name, te, unet, dyn in zip(names, te_multipliers, unet_multipliers, dyn_dims)
        )

        if all_lycos != self.cache:
            for name, te, unet, dyn in all_lycos:
                logger.debug(f"\nApply LyCORIS model: {name}: te={te}, unet={unet}, dyn={dyn}")
            self.cache = all_lycos
        lycoris.load_lycos(names, te_multipliers, unet_multipliers, dyn_dims)

    def deactivate(self, p):
        pass
KINGLIFER commented 1 year ago

I was wracking my brain why I could not see it. Why did they remove it? Thanks.

WBV-CWB commented 1 year ago

I don't understand why they did that?! Now I don't know what LORA OR LYCO is and when I add the LORA set it puts it makes things much worse, it's disorganized =/

KohakuBlueleaf commented 1 year ago

I don't understand why they did that?! Now I don't know what LORA OR LYCO is and when I add the LORA set it puts it makes things much worse, it's disorganized =/

LoRA is a subset of LyCORIS So merge them is way better then split them