> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
> Use this file to discover all available pages before exploring further.

# Flagging

Gradio provides several flagging callback classes to handle user feedback and data logging.

## FlaggingCallback

```python theme={null}
class FlaggingCallback(ABC)
```

An abstract class for defining the methods that any FlaggingCallback should have.

### Methods

#### setup

```python theme={null}
setup(components, flagging_dir)
```

This method should be overridden and ensure that everything is set up correctly for flag(). This method gets called once at the beginning of the Interface.launch() method.

<ParamField path="components" type="Sequence[Component]" required>
  Set of components that will provide flagged data.
</ParamField>

<ParamField path="flagging_dir" type="str" required>
  A string containing the path to the directory where the flagging file should be stored.
</ParamField>

#### flag

```python theme={null}
flag(flag_data, flag_option=None, username=None)
```

This method should be overridden by the FlaggingCallback subclass. This gets called every time the flag button is pressed.

<ParamField path="flag_data" type="list[Any]" required>
  The data to be flagged.
</ParamField>

<ParamField path="flag_option" type="str | None" default="None">
  In the case that flagging\_options are provided, the flag option that is being used.
</ParamField>

<ParamField path="username" type="str | None" default="None">
  The username of the user that is flagging the data, if logged in.
</ParamField>

<ResponseField name="returns" type="int">
  The total number of samples that have been flagged.
</ResponseField>

## SimpleCSVLogger

```python theme={null}
gr.SimpleCSVLogger()
```

A simplified implementation of the FlaggingCallback abstract class. Each flagged sample (both the input and output data) is logged to a CSV file on the machine running the gradio app.

### Example

```python theme={null}
import gradio as gr

def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}

demo = gr.Interface(
    fn=image_classifier,
    inputs="image",
    outputs="label",
    flagging_callback=gr.SimpleCSVLogger()
)
```

## ClassicCSVLogger

```python theme={null}
gr.ClassicCSVLogger(simplify_file_data=True)
```

The classic implementation of the FlaggingCallback abstract class in Gradio versions before 5.0. Each flagged sample (both the input and output data) is logged to a CSV file with headers on the machine running the gradio app.

### Parameters

<ParamField path="simplify_file_data" type="bool" default="True">
  If True, the file data will be simplified before being written to the CSV file.
</ParamField>

### Example

```python theme={null}
import gradio as gr

def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}

demo = gr.Interface(
    fn=image_classifier,
    inputs="image",
    outputs="label",
    flagging_callback=gr.ClassicCSVLogger()
)
```

## CSVLogger

```python theme={null}
gr.CSVLogger(
    simplify_file_data=True,
    verbose=True,
    dataset_file_name=None
)
```

The default implementation of the FlaggingCallback abstract class in gradio>=5.0. Each flagged sample (both the input and output data) is logged to a CSV file with headers on the machine running the gradio app. This implementation is concurrent-safe and creates a new dataset file every time the headers of the CSV change.

### Parameters

<ParamField path="simplify_file_data" type="bool" default="True">
  If True, the file data will be simplified before being written to the CSV file. If CSVLogger is being used to cache examples, this is set to False to preserve the original FileData class.
</ParamField>

<ParamField path="verbose" type="bool" default="True">
  If True, prints messages to the console about the dataset file creation.
</ParamField>

<ParamField path="dataset_file_name" type="str | None" default="None">
  The name of the dataset file to be created (should end in ".csv"). If None, the dataset file will be named "dataset1.csv" or the next available number.
</ParamField>

### Example

```python theme={null}
import gradio as gr

def image_classifier(inp):
    return {'cat': 0.3, 'dog': 0.7}

demo = gr.Interface(
    fn=image_classifier,
    inputs="image",
    outputs="label",
    flagging_callback=gr.CSVLogger()
)
```

## ChatCSVLogger

```python theme={null}
class ChatCSVLogger
```

Flagging callback for chat conversations. Flagged conversations and like/dislike reactions are logged to a CSV file on the machine running the gradio app.

### Methods

#### setup

```python theme={null}
setup(flagging_dir)
```

<ParamField path="flagging_dir" type="str" required>
  Path to the directory where flagged data is stored.
</ParamField>

#### flag

```python theme={null}
flag(like_data, messages)
```

<ParamField path="like_data" type="LikeData" required>
  The like/dislike data from the event.
</ParamField>

<ParamField path="messages" type="list" required>
  The chat messages.
</ParamField>

## FlagMethod

```python theme={null}
class FlagMethod
```

Helper class that contains the flagging options and calls the flagging method. Also provides visual feedback to the user when flag is clicked.

### Constructor

```python theme={null}
FlagMethod(
    flagging_callback,
    label,
    value,
    visual_feedback=True
)
```

<ParamField path="flagging_callback" type="FlaggingCallback" required>
  The flagging callback to use.
</ParamField>

<ParamField path="label" type="str" required>
  The label for the flag button.
</ParamField>

<ParamField path="value" type="str | None" required>
  The value associated with this flag option.
</ParamField>

<ParamField path="visual_feedback" type="bool" default="True">
  Whether to provide visual feedback when the flag button is clicked.
</ParamField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.