1
0
mirror of https://github.com/vladmandic/sdnext.git synced 2026-01-27 15:02:48 +03:00
Files
sdnext/cli/hf-search.py
vladmandic 0d90d95bf6 lint and safeguard glm
Signed-off-by: vladmandic <mandic00@live.com>
2026-01-16 09:40:48 +01:00

28 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
import sys
import huggingface_hub as hf
from rich import print # pylint: disable=redefined-builtin
if __name__ == "__main__":
sys.argv.pop(0)
keyword = sys.argv[0] if len(sys.argv) > 0 else ''
hf.logging.set_verbosity_info()
hf_api = hf.HfApi()
res = hf_api.list_models(
model_name=keyword,
full=True,
limit=100,
sort="downloads",
direction=-1,
)
res = sorted(res, key=lambda x: x.id)
exact = [m for m in res if keyword.lower() in m.id.lower()]
if len(exact) > 0:
res = exact
for m in res:
meta = hf_api.model_info(m.id, files_metadata=True)
m.files = [f.rfilename for f in meta.siblings if f.rfilename.endswith('.bin') or f.rfilename.endswith('.safetensors')]
m.size = round(sum([f.size for f in meta.siblings]) / 1024 / 1024 / 1024, 2)
print({ 'name': m.id, 'files': len(m.files), 'size': m.size, 'downloads': m.downloads, 'ctime': m.created_at.isoformat(), 'url': f'https://huggingface.co/{m.id}', 'pipeline': m.pipeline_tag })