HfHub.Repo (HfHub v0.2.0)

Copy Markdown View Source

Repository management operations for HuggingFace Hub.

Provides create, delete, update, and move operations for repositories (models, datasets, and spaces).

Examples

# Create a new model repository
{:ok, url} = HfHub.Repo.create("my-org/my-model", private: true)

# Create a space with Gradio
{:ok, url} = HfHub.Repo.create("my-space",
  repo_type: :space,
  space_sdk: "gradio"
)

# Delete a repository
:ok = HfHub.Repo.delete("my-org/old-model")

# Update settings
:ok = HfHub.Repo.update_settings("my-model", private: true, gated: :auto)

# Move/rename a repository
{:ok, url} = HfHub.Repo.move("old-name", "new-org/new-name")

Summary

Functions

Creates a new repository on the Hugging Face Hub.

Deletes a repository.

Checks if a repository exists.

Checks if a file exists in a repository.

Moves (renames) a repository.

Updates repository settings.

Types

gated()

@type gated() :: :auto | :manual | false

repo_type()

@type repo_type() :: :model | :dataset | :space

space_hardware()

@type space_hardware() :: String.t()

space_sdk()

@type space_sdk() :: String.t()

Functions

create(repo_id, opts \\ [])

@spec create(
  String.t(),
  keyword()
) :: {:ok, HfHub.Repo.RepoUrl.t()} | {:error, term()}

Creates a new repository on the Hugging Face Hub.

Options

  • :token - Authentication token
  • :repo_type - Type of repository (:model, :dataset, :space). Defaults to :model.
  • :private - Whether the repository should be private. Defaults to false.
  • :exist_ok - If true, do not error if repo already exists. Defaults to false.
  • :space_sdk - SDK to use for spaces ("gradio", "streamlit", "docker", "static").
  • :space_hardware - Hardware to use for spaces.

Examples

{:ok, url} = HfHub.Repo.create("my-model")
{:ok, url} = HfHub.Repo.create("my-dataset", repo_type: :dataset)

delete(repo_id, opts \\ [])

@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Deletes a repository.

Options

  • :token - Authentication token
  • :repo_type - Type of repository. Defaults to :model.
  • :missing_ok - If true, do not error if repo does not exist. Defaults to false.

exists?(repo_id, opts \\ [])

@spec exists?(
  String.t(),
  keyword()
) :: boolean()

Checks if a repository exists.

Using HEAD request to check existence. For models: /repo_id For datasets: /datasets/repo_id For spaces: /spaces/repo_id

file_exists?(repo_id, filename, opts \\ [])

@spec file_exists?(String.t(), String.t(), keyword()) :: boolean()

Checks if a file exists in a repository.

move(from_repo, to_repo, opts \\ [])

@spec move(String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Repo.RepoUrl.t()} | {:error, term()}

Moves (renames) a repository.

Options

  • :token - Authentication token
  • :repo_type - Type of repository. Defaults to :model.

revision_exists?(repo_id, revision, opts \\ [])

@spec revision_exists?(String.t(), String.t(), keyword()) :: boolean()

Checks if a revision exists.

Uses the repo info endpoint to check for valid revision. This is effectively checking if we can get info about a specific revision.

update_settings(repo_id, opts \\ [])

@spec update_settings(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Updates repository settings.

Options

  • :token - Authentication token
  • :repo_type - Type of repository. Defaults to :model.
  • :private - Set visibility
  • :gated - Set gated status (:auto, :manual, false)