Skip to content

Commit c133b85

Browse files
authored
Merge pull request #4152 from Artheriax/base-model-filtering
Filter on base model in networks tab
2 parents 6ac9d31 + f22ebdb commit c133b85

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

javascript/extraNetworks.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,28 @@ function extraNetworksSearchButton(event) {
290290
}
291291
}
292292

293+
function extraNetworksFilterVersion(event) {
294+
// log('extraNetworksFilterVersion', event);
295+
const version = event.target.textContent.trim();
296+
const activeTab = gradioApp().querySelector('.extra-networks-tab:not([style*="display: none"])');
297+
if (!activeTab) return;
298+
const cardContainer = activeTab.querySelector('.extra-network-cards');
299+
if (!cardContainer) return;
300+
if (cardContainer.dataset.activeVersion === version) {
301+
cardContainer.dataset.activeVersion = '';
302+
cardContainer.querySelectorAll('.card').forEach(card => card.style.display = '');
303+
} else {
304+
cardContainer.dataset.activeVersion = version;
305+
cardContainer.querySelectorAll('.card').forEach(card => {
306+
if (card.dataset.version === version) {
307+
card.style.display = '';
308+
} else {
309+
card.style.display = 'none';
310+
}
311+
});
312+
}
313+
}
314+
293315
let desiredStyle = '';
294316
function selectStyle(name) {
295317
desiredStyle = name;

modules/ui_extra_networks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
debug = shared.log.trace if os.environ.get('SD_EN_DEBUG', None) is not None else lambda *args, **kwargs: None
2525
debug('Trace: EN')
2626
card_full = '''
27-
<div class='card' onclick={card_click} title='{name}' data-page='{page}' data-name='{name}' data-filename='{filename}' data-short='{short}' data-tags='{tags}' data-mtime='{mtime}' data-size='{size}' data-search='{search}' style='--data-color: {color}'>
27+
<div class='card' onclick={card_click} title='{name}' data-page='{page}' data-name='{name}' data-filename='{filename}' data-short='{short}' data-tags='{tags}' data-mtime='{mtime}' data-size='{size}' data-search='{search}' data-version='{version}' style='--data-color: {color}'>
2828
<div class='overlay'>
2929
<div class='name {reference}'>{title}</div>
3030
</div>
@@ -291,6 +291,10 @@ def create_page(self, tabname, skip = False):
291291
subdirs_html += f'<button class="lg secondary gradio-button custom-button {style}" onclick="extraNetworksSearchButton(event)">{html.escape(subdir)}</button><br>'
292292
self.html = ''
293293
self.create_items(tabname)
294+
versions = sorted({item.get("version", "") for item in self.items if item.get("version")})
295+
versions_html = ''
296+
for ver in versions:
297+
versions_html += f'<button class="lg secondary gradio-button custom-button" onclick="extraNetworksFilterVersion(event)" style="margin-left:4px">{html.escape(ver)}</button><br>'
294298
self.create_xyz_grid()
295299
htmls = []
296300

@@ -314,7 +318,7 @@ def create_page(self, tabname, skip = False):
314318
htmls.append(self.create_html(item, tabname))
315319
self.html += ''.join(htmls)
316320
self.page_time = time.time()
317-
self.html = f"<div id='{tabname}_{self_name_id}_subdirs' class='extra-network-subdirs'>{subdirs_html}</div><div id='~tabname_{self_name_id}_cards' class='extra-network-cards'>{self.html}</div>"
321+
self.html = f"""<div id='{tabname}_{self_name_id}_subdirs' class='extra-network-subdirs'>{subdirs_html}{versions_html}</div><div id='~tabname_{self_name_id}_cards' class='extra-network-cards'>{self.html}</div>"""
318322
shared.log.debug(f'Networks: type="{self.name}" items={len(self.items)} subfolders={len(subdirs)} tab={tabname} folders={self.allowed_directories_for_previews()} list={self.list_time:.2f} thumb={self.preview_time:.2f} desc={self.desc_time:.2f} info={self.info_time:.2f} workers={shared.max_workers}')
319323
if len(self.missing_thumbs) > 0:
320324
threading.Thread(target=self.create_thumb).start()

0 commit comments

Comments
 (0)