Introducing Gradio 5.0

Read More

New to Gradio? Start here: Getting Started

See the Release History

Job

gradio_client.Job(···)

Description

A Job is a wrapper over the Future class that represents a prediction call that has been submitted by the Gradio client. This class is not meant to be instantiated directly, but rather is created by the Client.submit() method.
A Job object includes methods to get the status of the prediction call, as well to get the outputs of the prediction call. Job objects are also iterable, and can be used in a loop to get the outputs of prediction calls as they become available for generator endpoints.

Initialization

Parameters
future: Future

The future object that represents the prediction call, created by the Client.submit() method

communicator: Communicator | None
default = None

The communicator object that is used to communicate between the client and the background thread running the job

verbose: bool
default = True

Whether to print any status-related messages to the console

space_id: str | None
default = None

The space ID corresponding to the Client object that created this Job object

Event Listeners

Description

Event listeners allow you to respond to user interactions with the UI components you've defined in a Gradio Blocks app. When a user interacts with an element, such as changing a slider value or uploading an image, a function is called.

Supported Event Listeners

The Job component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.

Listener Description

Job.result(fn, ···)

Return the result of the call that the future represents. Raises CancelledError: If the future was cancelled, TimeoutError: If the future didn't finish executing before the given timeout, and Exception: If the call raised then that exception will be raised. <br>

Job.outputs(fn, ···)

Returns a list containing the latest outputs from the Job. <br> If the endpoint has multiple output components, the list will contain a tuple of results. Otherwise, it will contain the results without storing them in tuples. <br> For endpoints that are queued, this list will contain the final job output even if that endpoint does not use a generator function. <br>

Job.status(fn, ···)

Returns the latest status update from the Job in the form of a StatusUpdate object, which contains the following fields: code, rank, queue_size, success, time, eta, and progress_data. <br> progress_data is a list of updates emitted by the gr.Progress() tracker of the event handler. Each element of the list has the following fields: index, length, unit, progress, desc. If the event handler does not have a gr.Progress() tracker, the progress_data field will be None. <br>

Event Parameters

Parameters
timeout: float | None
default = None

The number of seconds to wait for the result if the future isn't done. If None, then there is no limit on the wait time.