> ## 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.

# Helpers

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

## Examples

```python theme={null}
gr.Examples(
    examples,
    inputs,
    outputs=None,
    fn=None,
    cache_examples=None,
    cache_mode=None,
    examples_per_page=10,
    label="Examples",
    elem_id=None,
    run_on_click=False,
    preprocess=True,
    postprocess=True,
    api_visibility="undocumented",
    api_name="load_example",
    api_description=None,
    batch=False,
    example_labels=None,
    visible=True,
    preload=0
)
```

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

<ParamField path="examples" type="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.
</ParamField>

<ParamField path="inputs" type="Component | Sequence[Component]" required>
  The component or list of components corresponding to the examples.
</ParamField>

<ParamField path="outputs" type="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.
</ParamField>

<ParamField path="fn" type="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.
</ParamField>

<ParamField path="cache_examples" type="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.
</ParamField>

<ParamField path="cache_mode" type="Literal['eager', 'lazy'] | None" default="None">
  If "lazy", examples are cached after their first use. If "eager", all examples are cached at app launch.
</ParamField>

<ParamField path="examples_per_page" type="int" default="10">
  How many examples to show per page.
</ParamField>

<ParamField path="label" type="str | I18nData | None" default="'Examples'">
  The label to use for the examples component.
</ParamField>

<ParamField path="elem_id" type="str | None" default="None">
  An optional string that is assigned as the id of this component in the HTML DOM.
</ParamField>

<ParamField path="run_on_click" type="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.
</ParamField>

<ParamField path="preprocess" type="bool" default="True">
  If True, preprocesses the example input before running the prediction function and caching the output.
</ParamField>

<ParamField path="postprocess" type="bool" default="True">
  If True, postprocesses the example output after running the prediction function and before caching.
</ParamField>

<ParamField path="example_labels" type="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.
</ParamField>

<ParamField path="visible" type="bool | Literal['hidden']" default="True">
  If False, the examples component will be hidden in the UI.
</ParamField>

<ParamField path="preload" type="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.
</ParamField>

### Example

```python theme={null}
import gradio as gr

def calculator(num1, operation, num2):
    if operation == "add":
        return num1 + num2
    elif operation == "subtract":
        return num1 - num2
    elif operation == "multiply":
        return num1 * num2
    elif operation == "divide":
        return num1 / num2

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            num1 = gr.Number()
            operation = gr.Radio(["add", "subtract", "multiply", "divide"])
            num2 = gr.Number()
        output = gr.Number()
    
    btn = gr.Button("Calculate")
    btn.click(calculator, [num1, operation, num2], output)
    
    gr.Examples(
        examples=[
            [5, "add", 3],
            [10, "subtract", 2],
            [4, "multiply", 6],
            [8, "divide", 2]
        ],
        inputs=[num1, operation, num2],
        outputs=output,
        fn=calculator,
    )

demo.launch()
```

## Progress

```python theme={null}
gr.Progress(track_tqdm=False)
```

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

<ParamField path="track_tqdm" type="bool" default="False">
  If True, the Progress object will track any tqdm.tqdm iterations with the tqdm library in the function.
</ParamField>

### Methods

#### **call**

```python theme={null}
progress(progress, desc=None, total=None, unit="steps")
```

Updates progress tracker with progress and message text.

<ParamField path="progress" type="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.
</ParamField>

<ParamField path="desc" type="str | None" default="None">
  Description to display.
</ParamField>

<ParamField path="total" type="int | float | None" default="None">
  Estimated total number of steps.
</ParamField>

<ParamField path="unit" type="str" default="'steps'">
  Unit of iterations.
</ParamField>

#### tqdm

```python theme={null}
progress.tqdm(iterable, desc=None, total=None, unit="steps")
```

Attaches progress tracker to iterable, like tqdm.

<ParamField path="iterable" type="Iterable | None">
  Iterable to attach progress tracker to.
</ParamField>

<ParamField path="desc" type="str | None" default="None">
  Description to display.
</ParamField>

<ParamField path="total" type="int | float | None" default="None">
  Estimated total number of steps.
</ParamField>

<ParamField path="unit" type="str" default="'steps'">
  Unit of iterations.
</ParamField>

### Example

```python theme={null}
import gradio as gr
import time

def my_function(x, progress=gr.Progress()):
    progress(0, desc="Starting...")
    time.sleep(1)
    for i in progress.tqdm(range(100)):
        time.sleep(0.1)
    return x

gr.Interface(my_function, gr.Textbox(), gr.Textbox()).launch()
```

## update

```python theme={null}
gr.update(
    elem_id=None,
    elem_classes=None,
    visible=None,
    **kwargs
)
```

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

<ParamField path="elem_id" type="str | None" default="None">
  Use this to update the id of the component in the HTML DOM.
</ParamField>

<ParamField path="elem_classes" type="list[str] | str | None" default="None">
  Use this to update the classes of the component in the HTML DOM.
</ParamField>

<ParamField path="visible" type="bool | Literal['hidden'] | None" default="None">
  Use this to update the visibility of the component.
</ParamField>

<ParamField path="kwargs" type="Any">
  Any other keyword arguments to update the component's properties.
</ParamField>

### Example

```python theme={null}
import gradio as gr

with gr.Blocks() as demo:
    radio = gr.Radio([1, 2, 4], label="Set the value of the number")
    number = gr.Number(value=2, interactive=True)
    radio.change(fn=lambda value: gr.update(value=value), inputs=radio, outputs=number)

demo.launch()
```

## skip

```python theme={null}
gr.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

```python theme={null}
import gradio as gr

def conditional_update(value):
    if value > 10:
        return value * 2
    else:
        return gr.skip()

with gr.Blocks() as demo:
    inp = gr.Number()
    out = gr.Number()
    btn = gr.Button("Submit")
    btn.click(conditional_update, inp, out)

demo.launch()
```

## validate

```python theme={null}
gr.validate(is_valid, message)
```

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

### Parameters

<ParamField path="is_valid" type="bool" required>
  Whether the value is valid.
</ParamField>

<ParamField path="message" type="str" required>
  The validation message to display.
</ParamField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.