1. Helpers
  2. Dependency

New 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/32b1d6ffe9e753ad563cc3f4f77a0bfbf89c022c/gradio-6.5.1-py3-none-any.whl

*Note: Setting share=True in launch() will not work.

Dependency

Description

The Dependency object is usually not created directly but is returned when an event listener is set up. It contains the configuration data for the event listener, and can be used to set up additional event listeners that depend on the completion of the current event listener using .then(), .success(), and .failure().

Example Usage

import gradio as gr

with gr.Blocks() as demo: 
    first_textbox = gr.Textbox()
    second_textbox = gr.Textbox()
    button = gr.Button("Submit")

    dependency = button.click(lambda x: "Hello, " + x, first_textbox, second_textbox)
    dependency.success(lambda: gr.Info("Greeting successful"), None, None)
    dependency.failure(lambda: gr.Warning("Greeting failed"), None, None)

demo.launch()

Demos