Reads the files of a model repository on the Hugging Face Hub or in a local directory.
A source is {:hf, repo} or the path of a local directory. Hub files download into the cache directory and come from there later. When the metadata of the repository gives a new ETag for a file, the file downloads again. Each download must match its ETag. The cache directory is ~/.cache/transmuter, or the :cache_dir option. An error status of the Hub, such as 401 for a gated repository without a token, raises Transmuter.HubError.
Environment
This module reads these environment variables, as Python huggingface_hub does:
HF_TOKEN(or the olderHUGGING_FACE_HUB_TOKEN) - the token for private and gated repositories. Without it, the token comes from the file thathf auth loginwrites:HF_TOKEN_PATH, elsetokeninHF_HOME, elsehuggingface/tokeninXDG_CACHE_HOME, else~/.cache/huggingface/token. A token from the browser login ofhf auth loginexpires. Pythonhuggingface_hubrefreshes it in the token file when less than one day remains, on each command that reads the token, such ashf auth whoami. Transmuter only reads the file, so when the Hub gives status 401 for such a token, runhf auth whoami.HTTPS_PROXY(andHTTP_PROXYfor anhttpURL), elseALL_PROXY- the HTTP or HTTPS proxy, such ashttp://user:password@proxy:3128. A lowercase name wins over the uppercase name.NO_PROXY- hosts that connect without the proxy, separated by commas. A host that ends with an entry connects directly, and*matches all hosts. The Hub redirects downloads to other hosts, such ascas-bridge.xethub.hf.co, and each host gets its own rule.HF_HUB_OFFLINEandTRANSFORMERS_OFFLINE- see the:offlineoption.
Options
:cache_dir- the directory for Hub downloads. The default is~/.cache/transmuter.:revision- a branch, a tag or a commit hash of the repository. The default is"main". The files of another revision go in a directory of their own in the cache,<repo>@<revision>. The files of a commit hash do not change, so its metadata comes from the Hub only once.:offline- whentrue, no request goes to the Hub. Files and metadata come only from the cache, and a file that is not in the cache raises. A file in the cache is used also when its ETag differs from the saved metadata. The default istruewhen theHF_HUB_OFFLINEorTRANSFORMERS_OFFLINEenvironment variable is1,ON,YESorTRUE, as in Python, andfalseotherwise.
The tasks of Transmuter.Text, Transmuter.Vision and Transmuter.Audio, Transmuter.Repo.load!/2 and Transmuter.load!/2 take these options too.
A large download shows a progress bar on the standard output. To disable it, set config :transmuter, progress_bar_enabled: false.
Summary
Functions
Returns {:ok, path} for file in source, or :error when the repository does not have the file.
Returns the local path of file in source. Raises if the repository does not have the file.
Returns the names of all files in source, with paths relative to the repository root.
Returns the metadata of a Hub repository from the Hub API, such as "sha" (the commit), "siblings" (the files with their ETags), "pipeline_tag" and "cardData", or nil for a local directory.
Reads and decodes the JSON file in source, or returns nil when the repository does not have the file.
Returns the names of the options of this module, which the tasks take and give to it.
Functions
Returns {:ok, path} for file in source, or :error when the repository does not have the file.
Returns the local path of file in source. Raises if the repository does not have the file.
A Hub file downloads when it is not in the cache or when its ETag in the metadata (see info/2) changed. An ONNX file also gets its external data files.
Returns the names of all files in source, with paths relative to the repository root.
Returns the metadata of a Hub repository from the Hub API, such as "sha" (the commit), "siblings" (the files with their ETags), "pipeline_tag" and "cardData", or nil for a local directory.
The metadata is saved in the cache directory and comes from there later. The refresh: true option reads it from the Hub again, and uses the saved metadata when the Hub cannot be reached, so a repository that was downloaded once also works without a network. With offline: true, the metadata comes only from the cache.
Reads and decodes the JSON file in source, or returns nil when the repository does not have the file.
Returns the names of the options of this module, which the tasks take and give to it.