Skip to main content
Providing examples makes it easier for users to try your demo and understand the types of inputs your model expects. Examples appear below the UI components and can be clicked to populate the interface.

Basic usage

Add examples to an Interface by providing a list of lists to the examples keyword argument:

Example format

Each sublist within the outer list represents a data sample, and each element within the sublist represents an input for each input component:
  • The inputs must be ordered in the same order as the prediction function expects them
  • Each element corresponds to one input component
  • If your interface only has one input component, you can provide examples as a regular list instead of a list of lists

Loading from a directory

You can specify a path to a directory containing your examples:
1

Single file-type input

If your Interface takes only a single file-type input (e.g., an image classifier), simply pass a directory filepath:
The Interface will load all images in the directory as examples.
2

Multiple inputs with log.csv

For multiple inputs, the directory must contain a log.csv file with example values:
Then reference the directory:
3

Loading flagged data

This approach is helpful when browsing flagged data. Simply point to the flagged directory:

Partial examples

Sometimes your app has many input components, but you only want to provide examples for a subset of them. Pass None for data samples corresponding to components you want to exclude:

Pagination

Examples are automatically paginated when you have many of them. Control the number per page:
This is useful for browsing and interacting with large datasets through Gradio.

Caching examples

You may want to cache example outputs so users can quickly try them without waiting for your model to run.
When set to True, your Gradio app runs all examples and saves outputs when you call launch():
The cache is saved in a gradio_cached_examples directory by default. Set the GRADIO_EXAMPLES_CACHE environment variable to use a custom directory path.
With lazy caching, each example is cached only after first use by any user:
This is helpful if your prediction function is long-running and you don’t want to wait during app startup.
Control when caching happens with cache_mode:
  • "eager" - All examples cached at app launch (default)
  • "lazy" - Examples cached after first use
On HuggingFace Spaces, eager mode is default except for ZeroGPU Spaces which use lazy mode.
Once the cache is generated, it won’t update automatically in future launches. If examples or function logic change, delete the cache folder to rebuild it.Cached examples don’t support certain features like gr.Progress(), gr.Info(), or gr.Warning() in the UI.

Example labels

Instead of rendering example values, you can provide custom labels:
The length of example_labels should match the number of examples.

Preloading examples

You can preload a specific example when the app first loads:
Preloading only works when:
  • Examples are cached eagerly (cache_examples=True and cache_mode="eager")
  • None of the input components have a developer-provided value
Set to False to disable preloading:

Examples with state

Cache examples cannot be used with state inputs and outputs. Gradio automatically sets cache_examples=False when state components are detected.

Next steps

Interface class

Learn more about the Interface class

Flagging

Allow users to flag interesting outputs