Commit 70a01cd4 authored by AUTOMATIC1111's avatar AUTOMATIC1111
Browse files

Merge branch 'dev' into refiner

parents 1aefb502 070b034c
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -195,6 +195,15 @@ def load_network(name, network_on_disk):
    return net


def purge_networks_from_memory():
    while len(networks_in_memory) > shared.opts.lora_in_memory_limit and len(networks_in_memory) > 0:
        name = next(iter(networks_in_memory))
        networks_in_memory.pop(name, None)

    devices.torch_gc()



def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=None):
    already_loaded = {}

@@ -212,15 +221,19 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No

    failed_to_load_networks = []

    for i, name in enumerate(names):
    for i, (network_on_disk, name) in enumerate(zip(networks_on_disk, names)):
        net = already_loaded.get(name, None)

        network_on_disk = networks_on_disk[i]

        if network_on_disk is not None:
            if net is None:
                net = networks_in_memory.get(name)

            if net is None or os.path.getmtime(network_on_disk.filename) > net.mtime:
                try:
                    net = load_network(name, network_on_disk)

                    networks_in_memory.pop(name, None)
                    networks_in_memory[name] = net
                except Exception as e:
                    errors.display(e, f"loading network {network_on_disk.filename}")
                    continue
@@ -242,6 +255,8 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No
    if failed_to_load_networks:
        sd_hijack.model_hijack.comments.append("Failed to find networks: " + ", ".join(failed_to_load_networks))

    purge_networks_from_memory()


def network_restore_weights_from_backup(self: Union[torch.nn.Conv2d, torch.nn.Linear, torch.nn.MultiheadAttention]):
    weights_backup = getattr(self, "network_weights_backup", None)
@@ -462,6 +477,7 @@ def infotext_pasted(infotext, params):
available_networks = {}
available_network_aliases = {}
loaded_networks = []
networks_in_memory = {}
available_network_hash_lookup = {}
forbidden_network_aliases = {}

+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ shared.options_templates.update(shared.options_section(('extra_networks', "Extra
    "lora_add_hashes_to_infotext": shared.OptionInfo(True, "Add Lora hashes to infotext"),
    "lora_show_all": shared.OptionInfo(False, "Always show all networks on the Lora page").info("otherwise, those detected as for incompatible version of Stable Diffusion will be hidden"),
    "lora_hide_unknown_for_versions": shared.OptionInfo([], "Hide networks of unknown versions for model versions", gr.CheckboxGroup, {"choices": ["SD1", "SD2", "SDXL"]}),
    "lora_in_memory_limit": shared.OptionInfo(0, "Number of Lora networks to keep cached in memory", gr.Number, {"precision": 0}),
}))


@@ -121,3 +122,5 @@ def infotext_pasted(infotext, d):


script_callbacks.on_infotext_pasted(infotext_pasted)

shared.opts.onchange("lora_in_memory_limit", networks.purge_networks_from_memory)
+31 −1
Original line number Diff line number Diff line
@@ -42,6 +42,11 @@ onUiLoaded(async() => {
        }
    }

    // Detect whether the element has a horizontal scroll bar
    function hasHorizontalScrollbar(element) {
        return element.scrollWidth > element.clientWidth;
    }

    // Function for defining the "Ctrl", "Shift" and "Alt" keys
    function isModifierKey(event, key) {
        switch (key) {
@@ -201,7 +206,8 @@ onUiLoaded(async() => {
        canvas_hotkey_overlap: "KeyO",
        canvas_disabled_functions: [],
        canvas_show_tooltip: true,
        canvas_blur_prompt: false
        canvas_auto_expand: true,
        canvas_blur_prompt: false,
    };

    const functionMap = {
@@ -648,8 +654,32 @@ onUiLoaded(async() => {
            mouseY = e.offsetY;
        }

        // Simulation of the function to put a long image into the screen.
        // We detect if an image has a scroll bar or not, make a fullscreen to reveal the image, then reduce it to fit into the element.
        // We hide the image and show it to the user when it is ready.
        function autoExpand(e) {
            const canvas = document.querySelector(`${elemId} canvas[key="interface"]`);
            const isMainTab = activeElement === elementIDs.inpaint || activeElement === elementIDs.inpaintSketch || activeElement === elementIDs.sketch;

            if (canvas && isMainTab) {
                if (hasHorizontalScrollbar(targetElement)) {
                    targetElement.style.visibility = "hidden";
                    setTimeout(() => {
                        fitToScreen();
                        resetZoom();
                        targetElement.style.visibility = "visible";
                    }, 10);
                }
            }
        }

        targetElement.addEventListener("mousemove", getMousePosition);

        // Apply auto expand if enabled
        if (hotkeysConfig.canvas_auto_expand) {
            targetElement.addEventListener("mousemove", autoExpand);
        }

        // Handle events only inside the targetElement
        let isKeyDownHandlerAttached = false;

+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ shared.options_templates.update(shared.options_section(('canvas_hotkey', "Canvas
    "canvas_hotkey_reset": shared.OptionInfo("R", "Reset zoom and canvas positon"),
    "canvas_hotkey_overlap": shared.OptionInfo("O", "Toggle overlap").info("Technical button, neededs for testing"),
    "canvas_show_tooltip": shared.OptionInfo(True, "Enable tooltip on the canvas"),
    "canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"),
    "canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"),
    "canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom","Adjust brush size", "Moving canvas","Fullscreen","Reset Zoom","Overlap"]}),
}))
+37 −0
Original line number Diff line number Diff line
var observerAccordionOpen = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutationRecord) {
        var elem = mutationRecord.target;
        var open = elem.classList.contains('open');

        var accordion = elem.parentNode;
        accordion.classList.toggle('input-accordion-open', open);

        var checkbox = gradioApp().querySelector('#' + accordion.id + "-checkbox input");
        checkbox.checked = open;
        updateInput(checkbox);

        var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
        if (extra) {
            extra.style.display = open ? "" : "none";
        }
    });
});

function inputAccordionChecked(id, checked) {
    var label = gradioApp().querySelector('#' + id + " .label-wrap");
    if (label.classList.contains('open') != checked) {
        label.click();
    }
}

onUiLoaded(function() {
    for (var accordion of gradioApp().querySelectorAll('.input-accordion')) {
        var labelWrap = accordion.querySelector('.label-wrap');
        observerAccordionOpen.observe(labelWrap, {attributes: true, attributeFilter: ['class']});

        var extra = gradioApp().querySelector('#' + accordion.id + "-extra");
        if (extra) {
            labelWrap.insertBefore(extra, labelWrap.lastElementChild);
        }
    }
});
Loading