Skip to main content

A simple huggingface client for Python.

Project description

shiertier_huggingface

English | 中文

简介

shiertier_huggingface 是一个 Python 库,旨在简化与 Hugging Face Hub 的交互。它提供了一组实用函数,用于下载模型、上传数据集和管理 Hugging Face 仓库。该库特别适用于在 Hugging Face 平台上管理机器学习模型和数据集。

安装

您可以通过 pip 安装 shiertier_huggingface

pip install shiertier_huggingface

请注意,该项目仍在开发中。

环境变量和直接使用 easy_huggingface_client

环境变量

  • HUGGINGFACE_TOKEN: 用于与 Hugging Face Hub 进行身份验证的令牌。如果在初始化时未提供,客户端将尝试从该环境变量中检索。

直接使用 easy_huggingface_client

您可以直接使用 easy_huggingface_client 对象,而无需手动初始化 HuggingfaceClient。该对象会自动从环境变量中检索令牌。

from shiertier_huggingface import easy_huggingface_client

# 下载模型
easy_huggingface_client.download_model(url_or_repo='https://huggingface.co/bert-base-uncased', repo_type='repo', local_dir='./huggingface_models')

# 上传数据集
easy_huggingface_client.upload_dataset(local_dir='path/to/local_dataset', repo_name='my_dataset_repo', tmp_dir='/root/.tmp')

使用方法

初始化

要使用 HuggingfaceClient,您需要使用您的 Hugging Face 令牌进行初始化。如果在初始化时未提供令牌,它将尝试从 HUGGINGFACE_TOKEN 环境变量中检索。

from shiertier_huggingface import HuggingfaceClient

# 使用令牌初始化
client = HuggingfaceClient(token='your_huggingface_token')

下载模型

您可以使用 download_model 方法从 Hugging Face Hub 下载模型。该方法允许您指定 URL 或仓库名称、仓库类型和本地目录,模型将保存在该目录中。

# 下载模型
client.download_model(url_or_repo='https://huggingface.co/bert-base-uncased', repo_type='repo', local_dir='./huggingface_models')

上传数据集

您可以使用 upload_dataset 方法将数据集上传到 Hugging Face Hub。该方法允许您指定包含数据集的本地目录、仓库名称和可选的临时目录。

# 上传数据集
client.upload_dataset(local_dir='path/to/local_dataset', repo_name='my_dataset_repo', tmp_dir='/root/.tmp')

依赖

  • huggingface_hub
  • shiertier_i18n
  • shiertier_tar

许可证

本项目基于 MIT 许可证发布。有关详细信息,请参阅 LICENSE 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shiertier_huggingface-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shiertier_huggingface-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file shiertier_huggingface-0.1.1.tar.gz.

File metadata

  • Download URL: shiertier_huggingface-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for shiertier_huggingface-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1c98513ab8eaec398e31aff1f68f8a0d29f26690b8f635ff1e98c151e9105b50
MD5 e47f2bca54bbc122d7b94e0ad60feb68
BLAKE2b-256 4cd89290df67ef13f4d53e7d41cdfe9ab0b0a6c2f06c42b16177719fbb298522

See more details on using hashes here.

File details

Details for the file shiertier_huggingface-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for shiertier_huggingface-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10a07444f078214144a9b0dead0981984e56f93f35cda356d32ace0e452cd1df
MD5 549e2791cad2bb4ae58200f915477b9b
BLAKE2b-256 22be70123eacc14a2d699f8e202e45b27b314eec92dec1a67e151fe90836c347

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page