Introducing Gradio Clients

Watch
  1. Helpers
  2. on

New to Gradio? Start here: Getting Started

See the Release History

on

gradio.on(···)

Description

Sets up an event listener that triggers a function when the specified event(s) occur. This is especially useful when the same function should be triggered by multiple events. Only a single API endpoint is generated for all events in the triggers list.

Example Usage

import gradio as gr

with gr.Blocks() as demo:
    with gr.Row():
        input = gr.Textbox()
        button = gr.Button("Submit")
    output = gr.Textbox()
    gr.on(
        triggers=[button.click, input.submit],
        fn=lambda x: x,
        inputs=[input],
        outputs=[output]
    )

demo.launch()

Initialization

Parameters