Skip to main content
The “Flag” button allows users to mark inputs with interesting outputs, such as erroneous or unexpected model behavior, for you to review later.

How flagging works

When a user flags data in your Interface:
  1. A CSV file logs the flagged inputs and outputs
  2. If the interface involves file data (images, audio, etc.), folders are created to store those files
  3. All flagged data is saved in the directory specified by flagging_dir

Basic flagging setup

The flag button appears by default in your Interface. You can control its behavior:

Flagging modes

You can control when and how flagging occurs with the flagging_mode parameter:
Users see a flag button and must click it to flag data:
Every submission is automatically flagged along with its output:
Users won’t see a flag button - all interactions are logged automatically.
Flagging is completely disabled:
You can also set the GRADIO_FLAGGING_MODE environment variable to control flagging mode globally.

Flagged data structure

For a simple calculator interface, flagged data is stored like this:
flagged/logs.csv:
For interfaces with file inputs/outputs (like images), the structure includes data folders:
flagged/logs.csv:

Custom flagging directory

Specify where flagged data is stored:
The directory is created automatically if it doesn’t exist.

Flagging options

Allow users to provide a reason when flagging by passing a list of strings to flagging_options:
Users select one option when flagging, and it’s saved as an additional column in the CSV:

Custom flag labels and values

You can customize both the button labels and the values stored in the CSV:
The first element of each tuple is the button label shown to users, and the second is the value stored in the CSV.

Custom flagging callbacks

By default, Gradio uses CSVLogger to save flagged data. You can create custom flagging behavior by providing a FlaggingCallback subclass:
Your custom callback must implement two methods:setup(components, flagging_dir)
  • Called once at the beginning of Interface.launch()
  • components: List of input/output components
  • flagging_dir: Directory path for storing flagged data
flag(flag_data, flag_option=None, username=None)
  • Called every time the flag button is pressed
  • flag_data: List of data to be flagged
  • flag_option: Selected option if flagging_options provided
  • username: Username if user is logged in
  • Returns: Total number of flagged samples (int)

SimpleCSVLogger example

Gradio provides SimpleCSVLogger as a basic example:
This is a simplified implementation provided for illustrative purposes. The default CSVLogger has more features.

Loading flagged data as examples

You can use flagged data as examples by pointing to the flagged directory:
This is helpful for reviewing and demonstrating edge cases.

Next steps

Interface class

Learn more about the Interface class

Examples

Working with examples in interfaces