Unverified Commit 63a2f8d8 authored by Karun's avatar Karun Committed by GitHub
Browse files

Merge branch 'master' into master

parents ca2b8faa 70615448
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -157,5 +157,6 @@ Licenses for borrowed code can be found in `Settings -> Licenses` screen, and al
- Sampling in float32 precision from a float16 UNet - marunine for the idea, Birch-san for the example Diffusers implementation (https://github.com/Birch-san/diffusers-play/tree/92feee6)
- Sampling in float32 precision from a float16 UNet - marunine for the idea, Birch-san for the example Diffusers implementation (https://github.com/Birch-san/diffusers-play/tree/92feee6)
- Instruct pix2pix - Tim Brooks (star), Aleksander Holynski (star), Alexei A. Efros (no star) - https://github.com/timothybrooks/instruct-pix2pix
- Instruct pix2pix - Tim Brooks (star), Aleksander Holynski (star), Alexei A. Efros (no star) - https://github.com/timothybrooks/instruct-pix2pix
- Security advice - RyotaK
- Security advice - RyotaK
- UniPC sampler - Wenliang Zhao - https://github.com/wl-zhao/UniPC
- Initial Gradio script - posted on 4chan by an Anonymous user. Thank you Anonymous user.
- Initial Gradio script - posted on 4chan by an Anonymous user. Thank you Anonymous user.
- (You)
- (You)
+21 −1
Original line number Original line Diff line number Diff line
@@ -3,7 +3,9 @@ import os
import re
import re
import torch
import torch


from modules import shared, devices, sd_models
from modules import shared, devices, sd_models, errors

metadata_tags_order = {"ss_sd_model_name": 1, "ss_resolution": 2, "ss_clip_skip": 3, "ss_num_train_images": 10, "ss_tag_frequency": 20}


re_digits = re.compile(r"\d+")
re_digits = re.compile(r"\d+")
re_unet_down_blocks = re.compile(r"lora_unet_down_blocks_(\d+)_attentions_(\d+)_(.+)")
re_unet_down_blocks = re.compile(r"lora_unet_down_blocks_(\d+)_attentions_(\d+)_(.+)")
@@ -43,6 +45,23 @@ class LoraOnDisk:
    def __init__(self, name, filename):
    def __init__(self, name, filename):
        self.name = name
        self.name = name
        self.filename = filename
        self.filename = filename
        self.metadata = {}

        _, ext = os.path.splitext(filename)
        if ext.lower() == ".safetensors":
            try:
                self.metadata = sd_models.read_metadata_from_safetensors(filename)
            except Exception as e:
                errors.display(e, f"reading lora {filename}")

        if self.metadata:
            m = {}
            for k, v in sorted(self.metadata.items(), key=lambda x: metadata_tags_order.get(x[0], 999)):
                m[k] = v

            self.metadata = m

        self.ssmd_cover_images = self.metadata.pop('ssmd_cover_images', None)  # those are cover images and they are too big to display in UI as text




class LoraModule:
class LoraModule:
@@ -159,6 +178,7 @@ def load_loras(names, multipliers=None):




def lora_forward(module, input, res):
def lora_forward(module, input, res):
    input = devices.cond_cast_unet(input)
    if len(loaded_loras) == 0:
    if len(loaded_loras) == 0:
        return res
        return res


+4 −10
Original line number Original line Diff line number Diff line
@@ -15,21 +15,15 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage):
    def list_items(self):
    def list_items(self):
        for name, lora_on_disk in lora.available_loras.items():
        for name, lora_on_disk in lora.available_loras.items():
            path, ext = os.path.splitext(lora_on_disk.filename)
            path, ext = os.path.splitext(lora_on_disk.filename)
            previews = [path + ".png", path + ".preview.png"]

            preview = None
            for file in previews:
                if os.path.isfile(file):
                    preview = self.link_preview(file)
                    break

            yield {
            yield {
                "name": name,
                "name": name,
                "filename": path,
                "filename": path,
                "preview": preview,
                "preview": self.find_preview(path),
                "description": self.find_description(path),
                "search_term": self.search_terms_from_path(lora_on_disk.filename),
                "search_term": self.search_terms_from_path(lora_on_disk.filename),
                "prompt": json.dumps(f"<lora:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
                "prompt": json.dumps(f"<lora:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
                "local_preview": path + ".png",
                "local_preview": f"{path}.{shared.opts.samples_format}",
                "metadata": json.dumps(lora_on_disk.metadata, indent=4) if lora_on_disk.metadata else None,
            }
            }


    def allowed_directories_for_previews(self):
    def allowed_directories_for_previews(self):
+4 −11
Original line number Original line Diff line number Diff line
@@ -89,22 +89,15 @@ function checkBrackets(evt, textArea, counterElt) {
function setupBracketChecking(id_prompt, id_counter){
function setupBracketChecking(id_prompt, id_counter){
    var textarea = gradioApp().querySelector("#" + id_prompt + " > label > textarea");
    var textarea = gradioApp().querySelector("#" + id_prompt + " > label > textarea");
    var counter = gradioApp().getElementById(id_counter)
    var counter = gradioApp().getElementById(id_counter)

    textarea.addEventListener("input", function(evt){
    textarea.addEventListener("input", function(evt){
        checkBrackets(evt, textarea, counter)
        checkBrackets(evt, textarea, counter)
    });
    });
}
}


var shadowRootLoaded = setInterval(function() {
onUiLoaded(function(){
    var shadowRoot = document.querySelector('gradio-app').shadowRoot;
    if(! shadowRoot)  return false;

    var shadowTextArea = shadowRoot.querySelectorAll('#txt2img_prompt > label > textarea');
    if(shadowTextArea.length < 1)  return false;

    clearInterval(shadowRootLoaded);

    setupBracketChecking('txt2img_prompt', 'txt2img_token_counter')
    setupBracketChecking('txt2img_prompt', 'txt2img_token_counter')
    setupBracketChecking('txt2img_neg_prompt', 'txt2img_negative_token_counter')
    setupBracketChecking('txt2img_neg_prompt', 'txt2img_negative_token_counter')
    setupBracketChecking('img2img_prompt', 'imgimg_token_counter')
    setupBracketChecking('img2img_prompt', 'img2img_token_counter')
    setupBracketChecking('img2img_neg_prompt', 'img2img_negative_token_counter')
    setupBracketChecking('img2img_neg_prompt', 'img2img_negative_token_counter')
}, 1000);
})
 No newline at end of file
+1 −0
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@
			<span style="display:none" class='search_term'>{search_term}</span>
			<span style="display:none" class='search_term'>{search_term}</span>
		</div>
		</div>
		<span class='name'>{name}</span>
		<span class='name'>{name}</span>
		<span class='description'>{description}</span>
	</div>
	</div>
</div>
</div>
Loading