📦 Huggingface Hub
v1.0.0通过 huggingface_hub Python 库访问 Hugging Face Hub 的模型、数据集和 Spaces。在需要列出、搜索、下载或上传 HF 资源时使用。
运行时依赖
安装命令
点击复制技能文档
Hugging Face Hub 技能 与 Hugging Face Hub 交互——浏览模型/数据集/spaces、下载文件、上传制品等。
前置条件 安装库:pip install huggingface_hub 将 HF token 保存到 Settings > Advanced 的 HF_TOKEN(在 https://huggingface.co/settings/tokens 获取)。
用法 python3 /home/workspace/Skills/huggingface-hub/scripts/hf_hub.py [options]
命令 命令 描述 list-models 列出模型。选项:--search, --sort, --direction, --limit list-datasets 列出数据集。选项:--search, --sort, --direction, --limit list-spaces 列出 spaces。选项:--search, --sort, --direction, --limit model-info 获取模型信息。选项:--model dataset-info 获取数据集信息。选项:--dataset download-file 从仓库下载文件。选项:--repo-id, --filename, --revision upload-file 上传文件。选项:--local-path, --repo-id, --repo-type, --path-in-repo whoami 显示已认证用户信息
示例 # 搜索文生图模型 python3 .../hf_hub.py list-models --search "text-to-image" --limit 10
# 下载模型文件 python3 .../hf_hub.py download-file --repo-id "stabilityai/stable-diffusion-xl-base-1.0" --filename "pytorch_model.bin"
# 上传文件 python3 .../hf_hub.py upload-file --local-path ./model.pt --repo-id "your-username/my-model" --repo-type "model"
# 列出点赞最多的数据集 python3 .../hf_hub.py list-datasets --sort "likes" --direction desc --limit 5
API 参考 本技能封装 huggingface_hub。关键函数: list_models, list_datasets, list_spaces —— 浏览 hub huggingface_hub —— 认证与文件操作 InferenceClient —— 在托管模型/spaces 上运行推理
备注 下载缓存至 ~/.cache/huggingface/ repo-type 取值:model, dataset, space 默认 revision 为 main