Classify library components consistently and hide standalone profile action

This commit is contained in:
Mikei386
2026-09-28 17:41:06 +02:00
parent 057b9df644
commit 413906f619
6 changed files with 37 additions and 4 deletions
+16 -1
View File
@@ -36,6 +36,21 @@ def repo_id(value):
if not isinstance(value,str) or not re.fullmatch(r'[A-Za-z0-9_-][A-Za-z0-9_.-]{0,95}/[A-Za-z0-9_-][A-Za-z0-9_.-]{0,95}',value):raise ValueError('Ungültige Repository-ID.')
return value
def file_role(filename):
"""One classification shared by library UI and profile validation."""
name=filename.lower();parts=PurePosixPath(name).parts
if any(p in ('text_encoder','text_encoders') for p in parts) or re.search(r'(?:^|[/_-])(?:text.encoder|qwen3vl|t5xxl|clip_l|clip_g)(?:[/_.-]|$)',name):
role,label='text_encoder','Textencoder'
elif 'vae' in parts or re.search(r'(?:^|[/_-])vae(?:[/_.-]|$)',name):
role,label='vae','VAE'
elif re.search(r'(?:^|[/_-])(?:mmproj|lora|adapter)(?:[/_.-]|$)',name):
role,label='auxiliary','Zusatzkomponente'
elif name.endswith(('.gguf','.safetensors')):
role,label='model','Modelldatei'
else:
role,label='configuration','Konfiguration'
return dict(role=role,role_label=label,profile_eligible=role=='model')
class Catalog:
def __init__(self,root):
self.root=Path(root);self.lock=threading.RLock();self.job=None;self.cancel=threading.Event()
@@ -101,7 +116,7 @@ class Catalog:
if self.root.exists():
for p in self.root.glob('*/entry.json'):
try:
item=json.loads(p.read_text());item['id']=p.parent.name;entries.append(item)
item=json.loads(p.read_text());item['id']=p.parent.name;item.update(file_role(item['file']));entries.append(item)
except (OSError,ValueError):pass
return dict(entries=entries,downloads=[dict(x) for x in reversed(self.history) if not x.get("dismissed")],job=dict(self.job) if self.job else None,free_bytes=shutil.disk_usage(self.root if self.root.exists() else self.root.parent).free)
def start(self,repo,filename,revision,kind):