Skip to main content

A simple huggingface client for Python.

Project description

shiertier_huggingface

中文 | English

1. 简介

shiertier_huggingface 是一个用于与 Hugging Face 平台进行交互的 Python 工具库。它提供了下载模型和上传数据集的功能,简化了与 Hugging Face 平台的交互过程。

2. 安装

通过 pip 安装

pip install shiertier_huggingface

通过 git 安装(开发版)

pip install git+https://github.com/shiertier-utils/shiertier_huggingface.git

3. 环境变量设置

在使用 shiertier_huggingface 之前,您需要设置一些环境变量。 HUGGINGFACE_TOKEN 如果为 None,则仅可下载公开模型。 HF_HOME 如果为 None,则默认是 ~/.cache/huggingface。 以下是如何在不同环境中设置环境变量的示例。

Bash

export HUGGINGFACE_TOKEN="your_huggingface_token"
export HF_HOME="~/.cache/huggingface"

CMD

set HUGGINGFACE_TOKEN=your_huggingface_token
set HF_HOME=C:\Users\YourUsername\.cache\huggingface

PowerShell

$env:HUGGINGFACE_TOKEN = "your_huggingface_token"
$env:HF_HOME = "C:\Users\YourUsername\.cache\huggingface"

Python

import os
os.environ['HUGGINGFACE_TOKEN'] = "your_huggingface_token"
os.environ['HF_HOME'] = "~/.cache/huggingface"

4. 函数用法与示例

快速使用

from shiertier_huggingface import ez_hf
# 或者使用类
# from shiertier_huggingface import HuggingfaceUtil
# hf_util = HuggingfaceUtil(token="your_huggingface_token", hf_home="path/to/hf_home")

# 下载模型仓库
model_repo_dir = ez_hf.download_model("shiertier/model")
# 或者使用url
# model_repo_dir = ez_hf.download_model("https://huggingface.co/shiertier/model")

# 下载模型文件, 传递的必须为url
model_file_path = ez_hf.download_model("https://huggingface.co/shiertier/model/resolve/main/file")
# 如果需要下载到指定位置
# model_file_path = ez_hf.download_model("https://huggingface.co/shiertier/model/resolve/main/model.ckpt", local_dir="path/to/local/dir")
# print(model_file_path)
# -> "path/to/local/dir/model.ckpt"

# 上传数据集,需要为四位数字字符串的目录
# 需要导入shiertier_huggingface之前设置环境变量HUGGINFACE_TOKEN
ez_hf.upload_dataset("path/to/local/dir/0000", "shiertier/dataset")
# 或者直接传递token参数
ez_hf.upload_dataset("path/to/local/dir/0000", "shiertier/dataset", token="your_huggingface_token")

详细函数介绍

download_model(url_or_repo, local_dir=None, token=None)

  • url_or_repo: Hugging Face 模型 URL 或仓库名称。
  • local_dir: 本地目录,默认为 None,如果为 None,则使用 HF_HOME
  • token: Hugging Face 令牌,默认为 None,如果为 None,则使用环境变量 HUGGINGFACE_TOKEN

upload_dataset(local_dir, repo_name, commit_message=None, token=None)

  • local_dir: 要上传的本地目录,必须是四位数字。
  • repo_name: 上传到的仓库名称。
  • commit_message: 提交信息,默认为 None,如果为 None,则使用 'Upload {tar_name_without_ext}'
  • token: Hugging Face 令牌,默认为 None,如果为 None,则使用环境变量 HUGGINGFACE_TOKEN

帮助

您可以通过以下方式获取帮助信息:

from shiertier_huggingface import ez_hf

ez_hf.help()  # 获取英文帮助
ez_hf.help_zh()  # 获取中文帮助

5. 依赖

  • huggingface_hub
  • shiertier_tar
  • shiertier_logger

6. 许可证

本项目采用 MIT 许可证

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.3.tar.gz (6.3 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.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shiertier_huggingface-0.1.3.tar.gz
  • Upload date:
  • Size: 6.3 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.3.tar.gz
Algorithm Hash digest
SHA256 31b32d25dcdc8b25fc77335efdd4070eaf720f4522b3e2b5903228cc34bd7cce
MD5 36877cb2e0f6ef9eee662a72b0eb3ad4
BLAKE2b-256 843c5b9b5fc305ff360acd14dedb3776b5f81b8e38326a1f4cd07c7221f9c3b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shiertier_huggingface-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c3037fd36d20db66d0635c62dc38d23e5a5bafd2250c570ae39b06e942f28e2b
MD5 df51772a1c8c643a5677b87f6c6ba175
BLAKE2b-256 6c7e44b1552674d9dfd8db5185bd55034045462820fc25f871acec4ed093182a

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