Module: DurableHuggingfaceHub

Defined in:
lib/huggingface_hub.rb,
lib/durable_huggingface_hub/cli.rb,
lib/durable_huggingface_hub/cache.rb,
lib/durable_huggingface_hub/types.rb,
lib/durable_huggingface_hub/errors.rb,
lib/durable_huggingface_hub/hf_api.rb,
lib/durable_huggingface_hub/version.rb,
lib/durable_huggingface_hub/constants.rb,
lib/durable_huggingface_hub/repo_card.rb,
lib/durable_huggingface_hub/types/user.rb,
lib/durable_huggingface_hub/utils/auth.rb,
lib/durable_huggingface_hub/utils/http.rb,
lib/durable_huggingface_hub/utils/paths.rb,
lib/durable_huggingface_hub/utils/retry.rb,
lib/durable_huggingface_hub/configuration.rb,
lib/durable_huggingface_hub/file_download.rb,
lib/durable_huggingface_hub/utils/headers.rb,
lib/durable_huggingface_hub/authentication.rb,
lib/durable_huggingface_hub/utils/progress.rb,
lib/durable_huggingface_hub/types/cache_info.rb,
lib/durable_huggingface_hub/types/model_info.rb,
lib/durable_huggingface_hub/types/space_info.rb,
lib/durable_huggingface_hub/utils/validators.rb,
lib/durable_huggingface_hub/types/commit_info.rb,
lib/durable_huggingface_hub/types/dataset_info.rb

Overview

DurableHuggingfaceHub is a Ruby client library for the HuggingFace Hub.

This library provides a pure Ruby implementation of the HuggingFace Hub client, enabling users to download models, datasets, and other files from the HuggingFace Hub, manage repositories, and interact with HuggingFace’s inference APIs.

Examples:

Basic usage

require "huggingface_hub"

# Configure the library
DurableHuggingfaceHub.configure do |config|
  config.token = "hf_your_token_here"
end

# Use the library features
# (Additional features will be added in subsequent phases)

See Also:

Defined Under Namespace

Modules: Authentication, Cache, Constants, FileDownload, Types, Utils Classes: BadRequestError, CLI, CacheNotFoundError, Configuration, CorruptedCacheError, DatasetCard, DisabledRepoError, DurableHuggingfaceHubError, EntryNotFoundError, FileMetadataError, GatedRepoError, HfApi, HfHubHTTPError, InferenceEndpointError, InferenceTimeoutError, LFSError, LocalEntryNotFoundError, LocalTokenNotFoundError, ModelCard, RepoCard, RepositoryNotFoundError, RevisionNotFoundError, SpaceCard, Struct, ValidationError

Constant Summary collapse

VERSION =

Current version of the HuggingFace Hub Ruby client library

"0.2.1"

Class Method Summary collapse

Class Method Details

.cached_assets_path(**kwargs) ⇒ Object

Delegates to Cache.cached_assets_path



123
124
125
# File 'lib/huggingface_hub.rb', line 123

def cached_assets_path(**kwargs)
  Cache.cached_assets_path(**kwargs)
end

.configConfiguration

Returns the current configuration.

Returns:



188
189
190
# File 'lib/durable_huggingface_hub/configuration.rb', line 188

def self.config
  Configuration.instance
end

.configurationConfiguration

Returns the global configuration instance.

Returns:



64
65
66
# File 'lib/huggingface_hub.rb', line 64

def configuration
  Configuration.instance
end

.configure {|config| ... } ⇒ Configuration

Provides a convenient way to configure the library.

Examples:

DurableHuggingfaceHub.configure do |config|
  config.token = "hf_your_token"
  config.cache_dir = "/tmp/hf_cache"
end

Yields:

  • (config)

    Yields the configuration object for modification

Yield Parameters:

Returns:



75
76
77
# File 'lib/huggingface_hub.rb', line 75

def configure
  yield configuration if block_given?
end

.dataset_info(repo_id, revision: nil, timeout: nil) ⇒ Object

Delegates to HfApi.dataset_info



141
142
143
# File 'lib/huggingface_hub.rb', line 141

def dataset_info(repo_id, revision: nil, timeout: nil)
  HfApi.new.dataset_info(repo_id, revision: revision, timeout: timeout)
end

.hf_hub_download(**kwargs) ⇒ Object

Delegates to FileDownload.hf_hub_download



105
106
107
# File 'lib/huggingface_hub.rb', line 105

def hf_hub_download(**kwargs)
  FileDownload.hf_hub_download(**kwargs)
end

.hf_hub_url(**kwargs) ⇒ Object

Delegates to FileDownload.hf_hub_url



198
199
200
# File 'lib/huggingface_hub.rb', line 198

def hf_hub_url(**kwargs)
  FileDownload.hf_hub_url(**kwargs)
end

.list_datasets(filter: nil, author: nil, search: nil, sort: nil, direction: nil, limit: nil, full: false, timeout: nil) ⇒ Object

Delegates to HfApi.list_datasets



161
162
163
164
165
# File 'lib/huggingface_hub.rb', line 161

def list_datasets(filter: nil, author: nil, search: nil, sort: nil,
                  direction: nil, limit: nil, full: false, timeout: nil)
  HfApi.new.list_datasets(filter: filter, author: author, search: search, sort: sort,
                          direction: direction, limit: limit, full: full, timeout: timeout)
end

.list_models(filter: nil, author: nil, search: nil, sort: nil, direction: nil, limit: nil, full: false, timeout: nil) ⇒ Object

Delegates to HfApi.list_models



153
154
155
156
157
# File 'lib/huggingface_hub.rb', line 153

def list_models(filter: nil, author: nil, search: nil, sort: nil,
                direction: nil, limit: nil, full: false, timeout: nil)
  HfApi.new.list_models(filter: filter, author: author, search: search, sort: sort,
                        direction: direction, limit: limit, full: full, timeout: timeout)
end

.list_spaces(filter: nil, author: nil, search: nil, sort: nil, direction: nil, limit: nil, full: false, timeout: nil) ⇒ Object

Delegates to HfApi.list_spaces



169
170
171
172
173
# File 'lib/huggingface_hub.rb', line 169

def list_spaces(filter: nil, author: nil, search: nil, sort: nil,
                direction: nil, limit: nil, full: false, timeout: nil)
  HfApi.new.list_spaces(filter: filter, author: author, search: search, sort: sort,
                        direction: direction, limit: limit, full: full, timeout: timeout)
end

.logged_in?Boolean

Delegates to Authentication.logged_in?



99
100
101
# File 'lib/huggingface_hub.rb', line 99

def logged_in?
  Authentication.logged_in?
end

.login(token: nil, add_to_git_credential: false) ⇒ Object

Delegates to Authentication.login



81
82
83
# File 'lib/huggingface_hub.rb', line 81

def (token: nil, add_to_git_credential: false)
  Authentication.(token: token, add_to_git_credential: add_to_git_credential)
end

.logoutObject

Delegates to Authentication.logout



87
88
89
# File 'lib/huggingface_hub.rb', line 87

def logout
  Authentication.logout
end

.model_info(repo_id, revision: nil, timeout: nil) ⇒ Object

Delegates to HfApi.model_info



135
136
137
# File 'lib/huggingface_hub.rb', line 135

def model_info(repo_id, revision: nil, timeout: nil)
  HfApi.new.model_info(repo_id, revision: revision, timeout: timeout)
end

.repo_exists(repo_id, repo_type: "model", timeout: nil) ⇒ Object

Delegates to HfApi.repo_exists



177
178
179
# File 'lib/huggingface_hub.rb', line 177

def repo_exists(repo_id, repo_type: "model", timeout: nil)
  HfApi.new.repo_exists(repo_id, repo_type: repo_type, timeout: timeout)
end

.repo_info(repo_id, repo_type: "model", revision: nil, timeout: nil) ⇒ Object

Delegates to HfApi.repo_info



129
130
131
# File 'lib/huggingface_hub.rb', line 129

def repo_info(repo_id, repo_type: "model", revision: nil, timeout: nil)
  HfApi.new.repo_info(repo_id, repo_type: repo_type, revision: revision, timeout: timeout)
end

.scan_cache_dir(**kwargs) ⇒ Object

Delegates to Cache.scan_cache_dir



117
118
119
# File 'lib/huggingface_hub.rb', line 117

def scan_cache_dir(**kwargs)
  Cache.scan_cache_dir(**kwargs)
end

.snapshot_download(**kwargs) ⇒ Object

Delegates to FileDownload.snapshot_download



111
112
113
# File 'lib/huggingface_hub.rb', line 111

def snapshot_download(**kwargs)
  FileDownload.snapshot_download(**kwargs)
end

.space_info(repo_id, revision: nil, timeout: nil) ⇒ Object

Delegates to HfApi.space_info



147
148
149
# File 'lib/huggingface_hub.rb', line 147

def space_info(repo_id, revision: nil, timeout: nil)
  HfApi.new.space_info(repo_id, revision: revision, timeout: timeout)
end

.try_to_load_from_cache(**kwargs) ⇒ Object

Delegates to FileDownload.try_to_load_from_cache



192
193
194
# File 'lib/huggingface_hub.rb', line 192

def try_to_load_from_cache(**kwargs)
  FileDownload.try_to_load_from_cache(**kwargs)
end

.versionString

Returns the library version.

Returns:

  • (String)

    The current version string



57
58
59
# File 'lib/huggingface_hub.rb', line 57

def version
  VERSION
end

.whoami(token: nil) ⇒ Object

Delegates to HfApi.whoami

Raises:

See Also:



93
94
95
# File 'lib/huggingface_hub.rb', line 93

def whoami(token: nil)
  Authentication.whoami(token: token)
end