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/model.ckpt")
# 如果需要下载到指定位置
# 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, hf_home=None)
local_dir: 要上传的本地目录,必须是四位数字。repo_name: 上传到的仓库名称。commit_message: 提交信息,默认为None,如果为None,则使用'Upload {tar_name_without_ext}'。token: Hugging Face 令牌,默认为None,如果为None,则使用环境变量HUGGINGFACE_TOKEN。hf_home: Hugging Face 临时目录,默认为None,如果为None,则使用环境变量HF_HOME。
帮助
您可以通过以下方式获取帮助信息:
from shiertier_huggingface import ez_hf
ez_hf.help # 获取英文帮助
ez_hf.help_zh # 获取中文帮助
5. 依赖
huggingface_hubshiertier_tarshiertier_logger
6. 许可证
本项目采用 MIT 许可证。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shiertier_huggingface-0.1.7.tar.gz.
File metadata
- Download URL: shiertier_huggingface-0.1.7.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80769473f75b8907946fdb795b3c188b673a6b00d00845742bcb6e7251756196
|
|
| MD5 |
91daaa2212be69d6180721b1b5e546b1
|
|
| BLAKE2b-256 |
db28ac77eb1bbf24d68553417cbd35b5f80e1ad34aa3990baea4661193b41f5a
|
File details
Details for the file shiertier_huggingface-0.1.7-py3-none-any.whl.
File metadata
- Download URL: shiertier_huggingface-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f1596519a5a7ea26ddfdb03a2456664bd3b2a15ddb3a1e2bb81ea9ab9cc8ad9
|
|
| MD5 |
6e435d520b2a6f2255da557690f9b549
|
|
| BLAKE2b-256 |
435cfdc126c8be8ae21ffababfa27ca6e481dcecc0a0257f5cb75b32f2af8e9d
|