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

HuggingFace TensorBoard Logger — push TensorBoard logs to the Hub.

Allows you to track experiment metrics and push TensorBoard logs to a
HuggingFace repository, making them viewable in the Hub's embedded TensorBoard.

See: https://huggingface.co/docs/huggingface_hub/package_reference/tensorboard

## Example

    # Create a logger
    logger = HuggingfaceClient.TensorBoard.new("my-org/my-model",
      logdir: "./runs/exp1",
      access_token: "hf_..."
    )

    # Log scalars (call during training)
    HuggingfaceClient.TensorBoard.log_scalar(logger, "train/loss", 0.245, step: 100)
    HuggingfaceClient.TensorBoard.log_scalar(logger, "eval/accuracy", 0.923, step: 100)

    # Push logs to Hub
    {:ok, url} = HuggingfaceClient.TensorBoard.push(logger)
    IO.puts("TensorBoard available at: #{url}")

# `t`

```elixir
@type t() :: %HuggingfaceClient.Hub.TensorBoard{
  logdir: String.t(),
  path_in_repo: String.t(),
  private: boolean(),
  repo_id: String.t(),
  repo_type: atom(),
  token: String.t() | nil
}
```

# `log_scalar`

```elixir
@spec log_scalar(t(), String.t(), float(), keyword()) :: :ok
```

Logs a scalar metric value. Writes to local logdir.

In production, combine with a real TensorBoard library (e.g. `:tensorflow`).
This creates a simple JSON log as a fallback.

## Example
    HuggingfaceClient.TensorBoard.log_scalar(logger, "train/loss", 0.245, step: 100)
    HuggingfaceClient.TensorBoard.log_scalar(logger, "eval/f1", 0.89, step: 100)

# `new`

```elixir
@spec new(
  String.t(),
  keyword()
) :: t()
```

Creates a new TensorBoard logger connected to a Hub repository.

## Options
- `:logdir` — local directory for TensorBoard logs (default: `"./runs"`)
- `:access_token` — HF API token
- `:repo_type` — `:model` | `:dataset` | `:space` (default: `:model`)
- `:path_in_repo` — directory in the repo (default: `"runs"`)
- `:private` — create repo as private if it doesn't exist (default: `false`)

## Example
    logger = HuggingfaceClient.TensorBoard.new("my-org/my-training-run",
      logdir: "./tb_logs",
      access_token: token
    )

# `push`

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

Pushes all TensorBoard log files from `logdir` to the Hub repository.

Creates the repository if it doesn't exist.

## Example
    {:ok, url} = HuggingfaceClient.TensorBoard.push(logger,
      commit_message: "Epoch 10 training logs"
    )
    IO.puts("View at: #{url}")

# `read_scalars`

```elixir
@spec read_scalars(t()) :: [map()]
```

Reads logged scalars from the local logdir.

## Example
    scalars = HuggingfaceClient.TensorBoard.read_scalars(logger)
    loss_values = Enum.filter(scalars, fn s -> s["tag"] == "train/loss" end)

# `upload_logs`

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

Uploads TensorBoard log files from the logdir to the Hub.

## Example
    {:ok, url} = HuggingfaceClient.TensorBoard.upload_logs(logger)

---

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