# `HuggingfaceClient.Hub.Metadata`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/hub/metadata/metadata.ex#L1)

Model Cards and metadata management for HuggingFace repositories.

Model cards are README.md files with structured YAML front-matter containing
metadata about models (tasks, languages, license, evaluation results, etc.).

See: https://huggingface.co/docs/hub/model-cards

## Example

    # Read a model's card metadata
    {:ok, metadata} = HuggingfaceClient.get_model_card_metadata("bert-base-uncased")
    IO.puts("License: #{metadata["license"]}")
    IO.puts("Language: #{inspect(metadata["language"])}")

    # Update metadata tags
    {:ok, _commit} = HuggingfaceClient.update_repo_metadata("my-org/my-model",
      metadata: %{
        "language"     => ["en", "fr"],
        "license"      => "apache-2.0",
        "tags"         => ["text-classification"],
        "pipeline_tag" => "text-classification"
      },
      access_token: "hf_..."
    )

# `get_metadata`

```elixir
@spec get_metadata(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets just the structured metadata from a repository's README front-matter.

## Example

    {:ok, meta} = HuggingfaceClient.get_model_card_metadata("bert-base-uncased")
    IO.puts("Tasks: #{inspect(meta["pipeline_tag"])}")
    IO.puts("License: #{meta["license"]}")

# `push_eval_results`

```elixir
@spec push_eval_results(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Pushes training results/evaluation metrics to a model's metadata.

Adds or updates the `model-index` section of the model card with
evaluation results from various datasets.

## Example

    {:ok, _} = HuggingfaceClient.push_eval_results("my-org/my-model",
      results: [
        %{
          "task"    => %{"type" => "text-classification"},
          "dataset" => %{"name" => "glue", "type" => "glue", "config" => "mnli"},
          "metrics" => [
            %{"type" => "accuracy", "value" => 0.847, "name" => "Accuracy"}
          ]
        }
      ],
      access_token: "hf_..."
    )

# `read_model_card`

```elixir
@spec read_model_card(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Reads and parses the model card / README.md for a repository.

Returns the full README content as a string, along with parsed metadata.

## Example

    {:ok, card} = HuggingfaceClient.read_model_card("gpt2")
    IO.puts(card["content"])
    IO.inspect(card["metadata"])

# `save`

```elixir
@spec save(keyword()) :: :ok | {:error, Exception.t()}
```

Saves metadata to a local file (YAML front-matter format).

Equivalent to Python's `metadata_save()`. Useful for creating model cards
locally before pushing to Hub.

## Options
- `:metadata` — metadata map to save (required)
- `:path` — local file path to save to (required)

## Example
    :ok = HuggingfaceClient.Hub.Metadata.save(
      path: "README.md",
      metadata: %{
        "pipeline_tag" => "text-generation",
        "language" => ["en"],
        "license" => "mit"
      }
    )

# `update`

```elixir
@spec update(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Updates specific metadata fields in a repository's model card.

This is the Elixir equivalent of Python's `metadata_update()`. Only updates the
YAML front-matter of the README.md, leaving the rest of the file unchanged.

## Options
- `:metadata` — map of metadata fields to update (required)
- `:overwrite` — overwrite existing keys (default: `false`)
- `:create_pr` — create a PR instead of committing directly (default: `false`)
- `:commit_message` — commit message
- `:type` — repo type (default: `:model`)
- `:access_token`

## Example
    {:ok, _} = HuggingfaceClient.Hub.Metadata.update("my-org/my-model",
      metadata: %{
        "pipeline_tag" => "text-generation",
        "language" => ["en", "fr"],
        "license" => "apache-2.0",
        "tags" => ["llm", "chat"]
      },
      overwrite: true,
      access_token: token
    )

    # Create a PR with metadata changes
    {:ok, pr} = HuggingfaceClient.Hub.Metadata.update("someone/model",
      metadata: %{"pipeline_tag" => "text-classification"},
      create_pr: true,
      access_token: token
    )

# `update_metadata`

```elixir
@spec update_metadata(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Updates metadata in a repository's README.md.

Merges the provided metadata into the existing YAML front-matter,
creating the README.md if it doesn't exist.

## Options

- `:metadata` — map of metadata to merge (required)
- `:create_pr` — if `true`, create a PR instead of committing directly
- `:commit_message` — custom commit message
- `:type` — repo type (default: `:model`)
- `:access_token`

## Example

    {:ok, commit} = HuggingfaceClient.update_repo_metadata("my-org/my-model",
      metadata: %{
        "language"     => ["en"],
        "license"      => "mit",
        "tags"         => ["pytorch", "text-classification"],
        "pipeline_tag" => "text-classification"
      },
      commit_message: "Update metadata",
      access_token: "hf_..."
    )

---

*Consult [api-reference.md](api-reference.md) for complete listing*
