Custom Components GalleryNEW
ExploreCustom Components GalleryNEW
ExploreNew to Gradio? Start here: Getting Started
See the Release History
To install Gradio from main, run the following command:
pip install https://gradio-builds.s3.amazonaws.com/98c1cbcd0e3b66a8d2463820d3ce157efe0a032d/gradio-4.31.4-py3-none-any.whl
*Note: Setting share=True
in
launch()
will not work.
gradio.Examples(examples, inputs, ยทยทยท)
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 listener so that clicking on an example populates the input/output components. Optionally handles example caching for fast inference.
Parameter | Description |
---|---|
examples 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 but it should be within the directory with the python file running the gradio app. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs. |
inputs Component | list[Component] required | the component or list of components corresponding to the examples |
outputs Component | list[Component] | None default: None | optionally, provide the component or list of components corresponding to the output of the examples. Required if |
fn Callable | None default: None | optionally, provide the function to run to generate the outputs corresponding to the examples. Required if |
cache_examples bool | Literal['lazy'] | 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. Can also be set by the GRADIO_CACHE_EXAMPLES environment variable, which takes a case-insensitive value, one of: |
examples_per_page int default: 10 | how many examples to show per page. |
label str | None default: "Examples" | the label to use for the examples component (by default, "Examples") |
elem_id str | None default: None | an optional string that is assigned as the id of this component in the HTML DOM. |
run_on_click 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. Has no effect if cache_examples is True. |
preprocess bool default: True | if True, preprocesses the example input before running the prediction function and caching the output. Only applies if |
postprocess bool default: True | if True, postprocesses the example output after running the prediction function and before caching. Only applies if |
api_name str | Literal[False] default: "load_example" | Defines how the event associated with clicking on the examples appears in the API docs. Can be a string or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that |
batch bool default: False | If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. Used only if cache_examples is not False. |