Skip to main content
Gradio provides several helper functions and classes to enhance your interface functionality.

Examples

This class is a wrapper over the Dataset component and can be used to create Examples for Blocks/Interfaces. Populates the Dataset component with examples and assigns event listeners so that clicking on an example populates the input/output components.

Parameters

list[Any] | list[list[Any]] | str
required
Example inputs that can be clicked to populate specific components. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided.
Component | Sequence[Component]
required
The component or list of components corresponding to the examples.
Component | Sequence[Component] | None
default:"None"
Optionally, provide the component or list of components corresponding to the output of the examples. Required if cache_examples is not False.
Callable | None
default:"None"
Optionally, provide the function to run to generate the outputs corresponding to the examples. Required if cache_examples is not False.
bool | None
default:"None"
If True, caches examples in the server for fast runtime in examples. If “lazy”, then examples are cached after their first use.
Literal['eager', 'lazy'] | None
default:"None"
If “lazy”, examples are cached after their first use. If “eager”, all examples are cached at app launch.
int
default:"10"
How many examples to show per page.
str | I18nData | None
default:"'Examples'"
The label to use for the examples component.
str | None
default:"None"
An optional string that is assigned as the id of this component in the HTML DOM.
bool
default:"False"
If cache_examples is False, clicking on an example does not run the function when an example is clicked. Set this to True to run the function when an example is clicked.
bool
default:"True"
If True, preprocesses the example input before running the prediction function and caching the output.
bool
default:"True"
If True, postprocesses the example output after running the prediction function and before caching.
list[str] | None
default:"None"
A list of labels for each example. If provided, the length of this list should be the same as the number of examples.
bool | Literal['hidden']
default:"True"
If False, the examples component will be hidden in the UI.
int | Literal[False]
default:"0"
If an integer is provided, the example at that index will be preloaded when the Gradio app is first loaded.

Example

Progress

The Progress class provides a custom progress tracker that is used in a function signature. To attach a Progress tracker to a function, simply add a parameter right after the input parameters that has a default value set to a gr.Progress() instance.

Parameters

bool
default:"False"
If True, the Progress object will track any tqdm.tqdm iterations with the tqdm library in the function.

Methods

call

Updates progress tracker with progress and message text.
float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If tuple, first number represents steps completed, and second value represents total steps or None if unknown. If None, hides progress bar.
str | None
default:"None"
Description to display.
int | float | None
default:"None"
Estimated total number of steps.
str
default:"'steps'"
Unit of iterations.

tqdm

Attaches progress tracker to iterable, like tqdm.
Iterable | None
Iterable to attach progress tracker to.
str | None
default:"None"
Description to display.
int | float | None
default:"None"
Estimated total number of steps.
str
default:"'steps'"
Unit of iterations.

Example

update

Updates a component’s properties. When a function passed into a Gradio Interface or Blocks events returns a value, it typically updates the value of the output component. But it is also possible to update the properties of an output component by returning gr.update(...) with any arbitrary parameters to update.

Parameters

str | None
default:"None"
Use this to update the id of the component in the HTML DOM.
list[str] | str | None
default:"None"
Use this to update the classes of the component in the HTML DOM.
bool | Literal['hidden'] | None
default:"None"
Use this to update the visibility of the component.
Any
Any other keyword arguments to update the component’s properties.

Example

skip

A special function that can be returned from a Gradio function to skip updating the output component. This may be useful when you want to update the output component conditionally.

Example

validate

A special function that can be returned from a Gradio function to set the validation error of an output component.

Parameters

bool
required
Whether the value is valid.
str
required
The validation message to display.