Interact with Hugging Face Hub — browse models/datasets/spaces, download files, upload artifacts, and more.
Install the library:
bash
pip install huggingface_hub
Save your HF token to Settings > Advanced as HF_TOKEN (get one at https://huggingface.co/settings/tokens).
bash
python3 /home/workspace/Skills/huggingface-hub/scripts/hf_hub.py <command> [options]
CommandDescriptionlist-modelsList models. Options: --search, --sort, --direction, --limit``list-datasetsList datasets. Options: --search, --sort, --direction, --limit``list-spacesList spaces. Options: --search, --sort, --direction, --limit``model-infoGet model info. Options: --model``dataset-infoGet dataset info. Options: --dataset``download-fileDownload a file from a repo. Options: --repo-id, --filename, --revision``upload-fileUpload a file. Options: --local-path, --repo-id, --repo-type, --path-in-repo``whoamiShow authenticated user info
bash
# Search for text-to-image models
python3 .../hf_hub.py list-models --search "text-to-image" --limit 10
# Download a model file
python3 .../hf_hub.py download-file --repo-id "stabilityai/stable-diffusion-xl-base-1.0" --filename "pytorch_model.bin"
# Upload a file
python3 .../hf_hub.py upload-file --local-path ./model.pt --repo-id "your-username/my-model" --repo-type "model"
# List top-rated datasets
python3 .../hf_hub.py list-datasets --sort "likes" --direction desc --limit 5
This skill wraps huggingface_hub. Key functions:
list_models, list_datasets, list_spaces — browse hubhuggingface_hub — authentication and file opsInferenceClient — run inference on hosted models/spaces~/.cache/huggingface/repo-type values: model, dataset, spacemain