Commit 083dc3c7 authored by AUTOMATIC's avatar AUTOMATIC
Browse files

directory hiding for extra networks: dirs starting with . will hide their...

directory hiding for extra networks: dirs starting with . will hide their cards on extra network tabs unless specifically searched for
create HTML for extra network pages only on demand
allow directories starting with . to still list their models for lora, checkpoints, etc
keep "search" filter for extra networks when user refreshes the page
parent 855f83f9
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -352,11 +352,7 @@ def list_available_loras():

    os.makedirs(shared.cmd_opts.lora_dir, exist_ok=True)

    candidates = \
        glob.glob(os.path.join(shared.cmd_opts.lora_dir, '**/*.pt'), recursive=True) + \
        glob.glob(os.path.join(shared.cmd_opts.lora_dir, '**/*.safetensors'), recursive=True) + \
        glob.glob(os.path.join(shared.cmd_opts.lora_dir, '**/*.ckpt'), recursive=True)

    candidates = list(shared.walk_files(shared.cmd_opts.lora_dir, allowed_extensions=[".pt", ".ckpt", ".safetensors"]))
    for filename in sorted(candidates, key=str.lower):
        if os.path.isdir(filename):
            continue
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
			<ul>
				<a href="#" title="replace preview image with currently selected in gallery" onclick={save_card_preview}>replace preview</a>
			</ul>
			<span style="display:none" class='search_term'>{search_term}</span>
			<span style="display:none" class='search_term{serach_only}'>{search_term}</span>
		</div>
		<span class='name'>{name}</span>
		<span class='description'>{description}</span>
+21 −4
Original line number Diff line number Diff line

function setupExtraNetworksForTab(tabname){
    gradioApp().querySelector('#'+tabname+'_extra_tabs').classList.add('extra-networks')

@@ -10,16 +9,34 @@ function setupExtraNetworksForTab(tabname){
    tabs.appendChild(search)
    tabs.appendChild(refresh)

    search.addEventListener("input", function(){
    var applyFilter = function(){
        var searchTerm = search.value.toLowerCase()

        gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){
            var searchOnly = elem.querySelector('.search_only')
            var text = elem.querySelector('.name').textContent.toLowerCase() + " " + elem.querySelector('.search_term').textContent.toLowerCase()
            elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : ""

            var visible = text.indexOf(searchTerm) != -1

            if(searchOnly && searchTerm.length < 4){
                visible = false
            }

            elem.style.display = visible ? "" : "none"
        })
    });
    }

    search.addEventListener("input", applyFilter);
    applyFilter();

    extraNetworksApplyFilter[tabname] = applyFilter;
}

function applyExtraNetworkFilter(tabname){
    setTimeout(extraNetworksApplyFilter[tabname], 1);
}

var extraNetworksApplyFilter = {}
var activePromptTextarea = {};

function setupExtraNetworks(){
+8 −19
Original line number Diff line number Diff line
@@ -22,9 +22,6 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None
    """
    output = []

    if ext_filter is None:
        ext_filter = []

    try:
        places = []

@@ -39,21 +36,13 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None
        places.append(model_path)

        for place in places:
            if os.path.exists(place):
                for file in glob.iglob(place + '**/**', recursive=True):
                    full_path = file
                    if os.path.isdir(full_path):
                        continue
            for full_path in shared.walk_files(place, allowed_extensions=ext_filter):
                if os.path.islink(full_path) and not os.path.exists(full_path):
                    print(f"Skipping broken symlink: {full_path}")
                    continue
                if ext_blacklist is not None and any([full_path.endswith(x) for x in ext_blacklist]):
                    continue
                    if len(ext_filter) != 0:
                        model_name, extension = os.path.splitext(file)
                        if extension not in ext_filter:
                            continue
                    if file not in output:
                if full_path not in output:
                    output.append(full_path)

        if model_url is not None and len(output) == 0:
+17 −0
Original line number Diff line number Diff line
@@ -726,3 +726,20 @@ def html(filename):
            return file.read()

    return ""


def walk_files(path, allowed_extensions=None):
    if not os.path.exists(path):
        return

    if allowed_extensions is not None:
        allowed_extensions = set(allowed_extensions)

    for root, dirs, files in os.walk(path):
        for filename in files:
            if allowed_extensions is not None:
                _, ext = os.path.splitext(filename)
                if ext not in allowed_extensions:
                    continue

            yield os.path.join(root, filename)
Loading