2023-01-28 17:18:47 +03:00
|
|
|
from modules import extra_networks, shared
|
2023-01-21 16:15:53 +03:00
|
|
|
import lora
|
|
|
|
|
2023-05-07 08:25:34 +03:00
|
|
|
|
2023-01-21 16:15:53 +03:00
|
|
|
class ExtraNetworkLora(extra_networks.ExtraNetwork):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__('lora')
|
|
|
|
|
|
|
|
def activate(self, p, params_list):
|
2023-01-28 17:18:47 +03:00
|
|
|
additional = shared.opts.sd_lora
|
|
|
|
|
2023-06-02 14:58:10 +03:00
|
|
|
if additional != "None" and additional in lora.available_loras and not any(x for x in params_list if x.items[0] == additional):
|
2023-01-28 17:18:47 +03:00
|
|
|
p.all_prompts = [x + f"<lora:{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]))
|
|
|
|
|
2023-01-21 16:15:53 +03:00
|
|
|
names = []
|
|
|
|
multipliers = []
|
|
|
|
for params in params_list:
|
2023-06-02 14:58:10 +03:00
|
|
|
assert params.items
|
2023-01-21 16:15:53 +03:00
|
|
|
|
|
|
|
names.append(params.items[0])
|
|
|
|
multipliers.append(float(params.items[1]) if len(params.items) > 1 else 1.0)
|
|
|
|
|
|
|
|
lora.load_loras(names, multipliers)
|
|
|
|
|
2023-05-19 22:59:29 +03:00
|
|
|
if shared.opts.lora_add_hashes_to_infotext:
|
|
|
|
lora_hashes = []
|
|
|
|
for item in lora.loaded_loras:
|
|
|
|
shorthash = item.lora_on_disk.shorthash
|
|
|
|
if not shorthash:
|
|
|
|
continue
|
|
|
|
|
|
|
|
alias = item.mentioned_name
|
|
|
|
if not alias:
|
|
|
|
continue
|
|
|
|
|
|
|
|
alias = alias.replace(":", "").replace(",", "")
|
|
|
|
|
|
|
|
lora_hashes.append(f"{alias}: {shorthash}")
|
|
|
|
|
|
|
|
if lora_hashes:
|
|
|
|
p.extra_generation_params["Lora hashes"] = ", ".join(lora_hashes)
|
|
|
|
|
2023-01-21 16:15:53 +03:00
|
|
|
def deactivate(self, p):
|
|
|
|
pass
|