How flagging works
When a user flags data in your Interface:- A CSV file logs the flagged inputs and outputs
- If the interface involves file data (images, audio, etc.), folders are created to store those files
- All flagged data is saved in the directory specified by
flagging_dir
Basic flagging setup
The flag button appears by default in yourInterface. You can control its behavior:
Flagging modes
You can control when and how flagging occurs with theflagging_mode parameter:
manual (default)
manual (default)
Users see a flag button and must click it to flag data:
auto
auto
Every submission is automatically flagged along with its output:Users won’t see a flag button - all interactions are logged automatically.
never
never
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:Custom flagging directory
Specify where flagged data is stored:Flagging options
Allow users to provide a reason when flagging by passing a list of strings toflagging_options:
Custom flag labels and values
You can customize both the button labels and the values stored in the CSV:Custom flagging callbacks
By default, Gradio usesCSVLogger to save flagged data. You can create custom flagging behavior by providing a FlaggingCallback subclass:
FlaggingCallback interface
FlaggingCallback interface
Your custom callback must implement two methods:setup(components, flagging_dir)
- Called once at the beginning of
Interface.launch() components: List of input/output componentsflagging_dir: Directory path for storing flagged data
- Called every time the flag button is pressed
flag_data: List of data to be flaggedflag_option: Selected option ifflagging_optionsprovidedusername: Username if user is logged in- Returns: Total number of flagged samples (int)
SimpleCSVLogger example
Gradio providesSimpleCSVLogger as a basic example:
CSVLogger has more features.
Loading flagged data as examples
You can use flagged data as examples by pointing to the flagged directory:Next steps
Interface class
Learn more about the Interface class
Examples
Working with examples in interfaces