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

FlaggingCallback

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

Methods

setup

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.
Sequence[Component]
required
Set of components that will provide flagged data.
str
required
A string containing the path to the directory where the flagging file should be stored.

flag

This method should be overridden by the FlaggingCallback subclass. This gets called every time the flag button is pressed.
list[Any]
required
The data to be flagged.
str | None
default:"None"
In the case that flagging_options are provided, the flag option that is being used.
str | None
default:"None"
The username of the user that is flagging the data, if logged in.
int
The total number of samples that have been flagged.

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

ClassicCSVLogger

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

bool
default:"True"
If True, the file data will be simplified before being written to the CSV file.

Example

CSVLogger

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

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.
bool
default:"True"
If True, prints messages to the console about the dataset file creation.
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.

Example

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

str
required
Path to the directory where flagged data is stored.

flag

LikeData
required
The like/dislike data from the event.
list
required
The chat messages.

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

FlaggingCallback
required
The flagging callback to use.
str
required
The label for the flag button.
str | None
required
The value associated with this flag option.
bool
default:"True"
Whether to provide visual feedback when the flag button is clicked.