HuggingFaceApi
Documentation for HuggingFaceApi.
HuggingFaceApi.HuggingFaceURLHuggingFaceApi.cached_downloadHuggingFaceApi.dataset_infoHuggingFaceApi.delete_tokenHuggingFaceApi.get_file_metadataHuggingFaceApi.get_tokenHuggingFaceApi.get_token_pathHuggingFaceApi.hf_homeHuggingFaceApi.hf_hub_cacheHuggingFaceApi.hf_hub_downloadHuggingFaceApi.huggingface_emojiHuggingFaceApi.list_cacheHuggingFaceApi.list_dataset_filesHuggingFaceApi.list_datasetsHuggingFaceApi.list_metricsHuggingFaceApi.list_model_filesHuggingFaceApi.list_modelsHuggingFaceApi.list_space_filesHuggingFaceApi.list_spacesHuggingFaceApi.loginHuggingFaceApi.logoutHuggingFaceApi.model_infoHuggingFaceApi.remove_cacheHuggingFaceApi.remove_cacheHuggingFaceApi.save_tokenHuggingFaceApi.space_infoHuggingFaceApi.try_to_load_from_cache
HuggingFaceApi.HuggingFaceURL — Type
HuggingFaceURL(repo_id, [subfolder], filename;
repo_type = nothing,
revision = "main")Construct the real url with the inputs. repo_type is nothing (model), "dataset", or "space".
HuggingFaceApi.cached_download — Method
cached_download(
hgfurl :: HuggingFaceURL;
local_files_only :: Bool = HuggingFaceApi.offline_mode(),
auth_token :: Union{AbstractString, Nothing} = get_token(),
cache_dir = HuggingFaceApi.hf_hub_cache(),
)Find the local cache of given url or do downloading. If local_files_only is set (the default when the HF_HUB_OFFLINE environment variable is set), it will try to find the file from cache, and error out when not found. For downloading from private repo, auth_token need to be set, or do HuggingFaceApi.login() beforehand.
The cache uses the same layout as the Python huggingface_hub library, so files are shared between the two.
See also: HuggingFaceURL, login, hf_hub_cache
HuggingFaceApi.dataset_info — Function
dataset_info(repo_id; revision = nothing, token = get_token())Get information for a specific dataset repo repo_id.
HuggingFaceApi.delete_token — Method
delete_token()Remove token from the disk.
HuggingFaceApi.get_file_metadata — Method
get_file_metadata(url; timeout = 10, headers = [])Fetch the commit hash, ETag, download location and size of a file on the Hub without downloading it.
HuggingFaceApi.get_token — Method
get_token()Get the user access token, from the HF_TOKEN environment variable or the file saved by login (see get_token_path). Returns nothing if no token is found.
HuggingFaceApi.get_token_path — Method
get_token_path()File where login saves the token: $HF_TOKEN_PATH, or $(hf_home())/token.
HuggingFaceApi.hf_home — Method
hf_home()Root directory of the Hugging Face files shared with the Python huggingface_hub library: $HF_HOME, or $XDG_CACHE_HOME/huggingface, or ~/.cache/huggingface.
HuggingFaceApi.hf_hub_cache — Method
hf_hub_cache()Directory of the download cache: $HF_HUB_CACHE, or $(hf_home())/hub.
HuggingFaceApi.hf_hub_download — Method
hf_hub_download(
repo_id :: AbstractString,
filename :: AbstractString;
repo_type = nothing,
revision = "main",
auth_token :: Union{AbstractString, Nothing} = get_token(),
local_files_only :: Bool = HuggingFaceApi.offline_mode(),
cache :: Bool = true,
)Construct HuggingFaceURL and do cached_download. If cache is false, download file to the temp dir with name generated by tempname(). If local_files_only is set, cache must set.
HuggingFaceApi.huggingface_emoji — Method
add 🤗 autocomplete in REPL
HuggingFaceApi.list_cache — Method
list_cache(; cache_dir = HuggingFaceApi.hf_hub_cache())Get the list of all the cache, as repo type => repo id => revision => files. A revision is a reference (like "main") when one points to the snapshot, otherwise a commit hash.
HuggingFaceApi.list_dataset_files — Function
list_dataset_files(repo_id; revision = nothing, token = get_token())List all files in the specific dataset repo repo_id.
HuggingFaceApi.list_datasets — Function
list_datasets(token = get_token();
search = nothing, author = nothing, filter = nothing,
sort = nothing, direction = nothing, limit = nothing,
full::Bool = false, cardData::Bool = false)Get information from all datasets in the Hub. You can specify additional parameters to have more specific results.
search: Filter based on substrings for repos and their usernames, such as pets or microsoftauthor: Filter datasets by an other or organization, such as huggingface or microsoftfilter: Filter based on tags, such as task_categories:text-classification or language:en.sort: Property to use when sorting, such asdownloads,likes,lastModified,createdAtortrendingScore.direction: Direction in which to sort. Results are sorted in descending order; the Hub only accepts ascending order (1) forcreatedAt.limit: Limit the number of datasets fetched. Results come in pages of at most 1000; withoutlimit, only the first page is returned.full: Whether to fetch most dataset data, such as all tags, the files, etc.cardData: Whether to grab the metadata for the dataset as well. Can contain useful information such as the PapersWithCode ID.
HuggingFaceApi.list_metrics — Method
list_metrics()Get information from all metrics in the Hub.
HuggingFaceApi.list_model_files — Function
list_model_files(repo_id; revision = nothing, token = get_token())List all files in the specific model repo repo_id.
HuggingFaceApi.list_models — Function
list_models(token = get_token();
search = nothing, author = nothing, filter = nothing,
sort = nothing, direction = nothing, limit = nothing,
full::Bool = !isnothing(filter), cardData::Bool = false)Get information from all models in the Hub. You can specify additional parameters to have more specific results.
search: Filter based on substrings for repos and their usernames, such as resnet or microsoftauthor: Filter models by an author or organization, such as huggingface or microsoftfilter: Filter based on tags, such as text-classification or spacy.sort: Property to use when sorting, such asdownloads,likes,lastModified,createdAtortrendingScore.direction: Direction in which to sort. Results are sorted in descending order; the Hub only accepts ascending order (1) forcreatedAt.limit: Limit the number of models fetched. Results come in pages of at most 1000; withoutlimit, only the first page is returned.full: Whether to fetch most model data, such as all tags, the files, etc.cardData: Whether to grab the metadata for the model as well, such as carbon emissions, metrics, and datasets trained on.
HuggingFaceApi.list_space_files — Function
list_space_files(repo_id; revision = nothing, token = get_token())List all files in the specific space repo repo_id.
HuggingFaceApi.list_spaces — Function
list_spaces(token = get_token();
search = nothing, author = nothing, filter = nothing,
datasets = nothing, models = nothing, linked::Bool = false,
sort = nothing, direction = nothing, limit = nothing,
full::Bool = false)Get information from all Spaces in the Hub. You can specify additional parameters to have more specific results.
search: Filter based on substrings for repos and their usernames, such as resnet or microsoftauthor: Filter models by an author or organization, such as huggingface or microsoftfilter: Filter based on tags, such as text-classification or spacy.sort: Property to use when sorting, such asdownloads,likes,lastModified,createdAtortrendingScore.direction: Direction in which to sort. Results are sorted in descending order; the Hub only accepts ascending order (1) forcreatedAt.limit: Limit the number of Spaces fetched. Results come in pages of at most 1000; withoutlimit, only the first page is returned.full: Whether to fetch most Space data, such as all tags, the files, etc.datasets: Whether to return Spaces that make use of a dataset. The name of a specific dataset can be passed as a string.models: Whether to return Spaces that make use of a model. The name of a specific model can be passed as a string.linked: Whether to return Spaces that make use of either a model or a dataset.
HuggingFaceApi.login — Method
login(token = <prompt>)Validate a user access token and save it to get_token_path() for operations that need authentication. The file is shared with the Python huggingface_hub library, so hf auth login works too.
HuggingFaceApi.logout — Method
logout()Remove the token saved by login.
HuggingFaceApi.model_info — Function
model_info(repo_id; revision = nothing, token = get_token())Get information for a specific model repo repo_id.
HuggingFaceApi.remove_cache — Method
remove_cache(repo_id::AbstractString; repo_type = nothing, revision = nothing, cache_dir = HuggingFaceApi.hf_hub_cache())Remove all cached files of a given repo, or only those of revision if it is set.
HuggingFaceApi.remove_cache — Method
remove_cache(hgfurl::HuggingFaceURL; cache_dir = HuggingFaceApi.hf_hub_cache())Remove the cached file of the given url, and its blob if no other revision uses it.
HuggingFaceApi.save_token — Method
save_token(token)Write token to the disk for future use.
HuggingFaceApi.space_info — Function
space_info(repo_id; revision = nothing, token = get_token())Get information for a specific space repo repo_id.
HuggingFaceApi.try_to_load_from_cache — Method
try_to_load_from_cache(hgfurl::HuggingFaceURL; cache_dir = hf_hub_cache())Return the path of the cached file for hgfurl, or nothing if it is not in the cache. No request is made.