zea.tools.hf¶
Huggingface hub (hf) tooling.
Functions
|
Load the model from a given repo_id using the Hugging Face library. |
|
Upload a local directory to Hugging Face Hub. |
Classes
|
A path-like object that preserves the hf:// scheme and mimics Path API. |
- class zea.tools.hf.HFPath(*args)[source]¶
Bases:
PurePosixPath
A path-like object that preserves the hf:// scheme and mimics Path API.
- property repo_id¶
Extract the repo ID (e.g., zeahub/camus-sample).
- property subpath¶
Get path inside the repo.
- zea.tools.hf.load_model_from_hf(repo_id, revision='main', verbose=True)[source]¶
Load the model from a given repo_id using the Hugging Face library.
Will download to a model_dir directory and return the path to it. Need your own load model logic to load the model from the model_dir.
- Parameters:
repo_id (str) – The ID of the repository.
revision (str) – The revision to download. Can be a branch, tag, or commit hash.
verbose (bool) – Whether to print the download message. Default is True.
- Returns:
The path to the downloaded model directory.
- Return type:
model_dir (Path)
- zea.tools.hf.upload_folder_to_hf(local_dir, repo_id, commit_message=None, revision='main', tag=None, verbose=True)[source]¶
Upload a local directory to Hugging Face Hub.
- Parameters:
local_dir (str or Path) – Path to the local directory to upload.
repo_id (str) – The ID of the repository to upload to.
commit_message (str, optional) – Commit message. Defaults to “Upload files”.
revision (str) – The revision to upload to. Defaults to “main”.
tag (str, optional) – Tag to create. Defaults to None.
verbose (bool) – Whether to print the upload message. Default is True.
- Returns:
URL of the uploaded repository.
- Return type:
str