# Auto-Assign

## Overview

When publishing many figures, naming each one manually can be tedious. Auto-assign lets GoFigr use AI to automatically title your figures and organize them into the right place.

## How It Works

1. You publish a figure with `auto_assign=True`
2. GoFigr creates a temporary "Untitled" figure and processes the data
3. In the background, AI analyzes the figure image and generates a descriptive title
4. If an existing figure in the same analysis has a matching title, the revision is **moved** to that figure automatically
5. If the title is new, the temporary figure is **renamed** to the generated title

This means you can publish many figures in a loop without worrying about naming or deduplication—GoFigr handles it for you.

## Usage

### With a Publisher

Enable auto-assign on the publisher to apply it to all figures:

```python
from gofigr.publisher import Publisher

pub = Publisher(workspace="Analytics", analysis="Penguins", auto_assign=True)
pub.publish(fig)
```

Or enable it per call:

```python
pub.publish(fig, auto_assign=True)
```

### With Clean Room

Auto-assign works with `@reproducible` the same way:

```python
pub = Publisher(workspace="Analytics", analysis="Penguins", auto_assign=True)

@reproducible(publisher=pub)
def my_plot(data, species: str = "Adelie"):
    filtered = data[data['species'] == species]
    sns.histplot(data=filtered, x='flipper_length_mm')

my_plot(penguins)
```

### With Jupyter Auto-Publishing

If you use `configure(auto_publish=True)` in Jupyter, you can enable auto-assign globally:

```python
%load_ext gofigr
configure(auto_assign=True)
```

## What You See in the Browser

While the AI is assigning a title, the revision view shows a shimmer placeholder where the title would be, with a countdown indicator ("Assigning title in 5s"). Once the title is assigned, it appears automatically—no page reload needed.

If the revision is moved to an existing figure, the view updates to reflect the new figure seamlessly.

## Deduplication

Auto-assign doesn't just name figures—it also deduplicates them. If you publish a figure that looks like an existing one in the same analysis, the new revision is added to the existing figure rather than creating a duplicate. This keeps your analysis organized even when publishing from loops or automated pipelines.

## When to Use

* **Batch publishing** — publishing many figures in a loop where manual naming is impractical
* **Exploratory workflows** — when you're generating figures rapidly and want to organize later
* **Automated pipelines** — CI/CD or scheduled jobs that produce figures without human intervention
* **Jupyter notebooks** — publish every cell's output without interrupting your flow
