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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
Use this file to discover all available pages before exploring further.
Basic usage
Add examples to an Interface by providing a list of lists to theexamples 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: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.
Multiple inputs with log.csv
For multiple inputs, the directory must contain a Then reference the directory:
log.csv file with example values:Partial examples
Sometimes your app has many input components, but you only want to provide examples for a subset of them. PassNone 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:Caching examples
You may want to cache example outputs so users can quickly try them without waiting for your model to run.cache_examples=True
cache_examples=True
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.Lazy caching
Lazy caching
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.
Cache mode configuration
Cache mode configuration
Control when caching happens with
cache_mode:"eager"- All examples cached at app launch (default)"lazy"- Examples cached after first use
Example labels
Instead of rendering example values, you can provide custom labels: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=Trueandcache_mode="eager") - None of the input components have a developer-provided
value
False to disable preloading:
Examples with state
Next steps
Interface class
Learn more about the Interface class
Flagging
Allow users to flag interesting outputs