zea.tools.hf

Huggingface hub (hf) tooling.

Functions

load_model_from_hf(repo_id[, revision, verbose])

Load the model from a given repo_id using the Hugging Face library.

upload_folder_to_hf(local_dir, repo_id[, ...])

Upload a local directory to Hugging Face Hub.

Classes

HFPath(*args)

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.

is_dir()[source]

Return True if this HFPath points to a directory in the repo.

is_file()[source]

Return True if this HFPath points to a file in the repo.

joinpath(*args)[source]

Join paths like Path.joinpath but preserve the hf:// scheme.

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