EllieKini/Herta
Audio-to-Audio
•
Updated
text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 183
values | source_page_title
stringclasses 183
values |
|---|---|---|---|
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.
|
Description
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
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
|
Initialization
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
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.
Listeners
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.
|
Event Listeners
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
If you already have a recent version of `gradio`, then the `gradio_client` is
included as a dependency. But note that this documentation reflects the latest
version of the `gradio_client`, so upgrade if you’re not sure!
The lightweight `gradio_client` package can be installed from pip (or pip3)
and is tested to work with **Python versions 3.9 or higher** :
$ pip install --upgrade gradio_client
|
Installation
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Spaces
Start by connecting instantiating a `Client` object and connecting it to a
Gradio app that is running on Hugging Face Spaces.
from gradio_client import Client
client = Client("abidlabs/en2fr") a Space that translates from English to French
You can also connect to private Spaces by passing in your HF token with the
`hf_token` parameter. You can get your HF token here:
<https://huggingface.co/settings/tokens>
from gradio_client import Client
client = Client("abidlabs/my-private-space", hf_token="...")
|
Connecting to a Gradio App on Hugging Face
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
use
While you can use any public Space as an API, you may get rate limited by
Hugging Face if you make too many requests. For unlimited usage of a Space,
simply duplicate the Space to create a private Space, and then use it to make
as many requests as you’d like!
The `gradio_client` includes a class method: `Client.duplicate()` to make this
process simple (you’ll need to pass in your [Hugging Face
token](https://huggingface.co/settings/tokens) or be logged in using the
Hugging Face CLI):
import os
from gradio_client import Client, file
HF_TOKEN = os.environ.get("HF_TOKEN")
client = Client.duplicate("abidlabs/whisper", hf_token=HF_TOKEN)
client.predict(file("audio_sample.wav"))
>> "This is a test of the whisper speech recognition model."
If you have previously duplicated a Space, re-running `duplicate()` will _not_
create a new Space. Instead, the Client will attach to the previously-created
Space. So it is safe to re-run the `Client.duplicate()` method multiple times.
**Note:** if the original Space uses GPUs, your private Space will as well,
and your Hugging Face account will get billed based on the price of the GPU.
To minimize charges, your Space will automatically go to sleep after 1 hour of
inactivity. You can also set the hardware using the `hardware` parameter of
`duplicate()`.
|
Duplicating a Space for private
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
app
If your app is running somewhere else, just provide the full URL instead,
including the “http://” or “https://“. Here’s an example of making predictions
to a Gradio app that is running on a share URL:
from gradio_client import Client
client = Client("https://bec81a83-5b5c-471e.gradio.live")
|
Connecting a general Gradio
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Once you have connected to a Gradio app, you can view the APIs that are
available to you by calling the `Client.view_api()` method. For the Whisper
Space, we see the following:
Client.predict() Usage Info
---------------------------
Named API endpoints: 1
- predict(audio, api_name="/predict") -> output
Parameters:
- [Audio] audio: filepath (required)
Returns:
- [Textbox] output: str
We see that we have 1 API endpoint in this space, and shows us how to use the
API endpoint to make a prediction: we should call the `.predict()` method
(which we will explore below), providing a parameter `input_audio` of type
`str`, which is a `filepath or URL`.
We should also provide the `api_name='/predict'` argument to the `predict()`
method. Although this isn’t necessary if a Gradio app has only 1 named
endpoint, it does allow us to call different endpoints in a single app if they
are available.
|
Inspecting the API endpoints
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
As an alternative to running the `.view_api()` method, you can click on the
“Use via API” link in the footer of the Gradio app, which shows us the same
information, along with example usage.

The View API page also includes an “API Recorder” that lets you interact with
the Gradio UI normally and converts your interactions into the corresponding
code to run with the Python Client.
|
The “View API” Page
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
The simplest way to make a prediction is simply to call the `.predict()`
function with the appropriate arguments:
from gradio_client import Client
client = Client("abidlabs/en2fr", api_name='/predict')
client.predict("Hello")
>> Bonjour
If there are multiple parameters, then you should pass them as separate
arguments to `.predict()`, like this:
from gradio_client import Client
client = Client("gradio/calculator")
client.predict(4, "add", 5)
>> 9.0
It is recommended to provide key-word arguments instead of positional
arguments:
from gradio_client import Client
client = Client("gradio/calculator")
client.predict(num1=4, operation="add", num2=5)
>> 9.0
This allows you to take advantage of default arguments. For example, this
Space includes the default value for the Slider component so you do not need
to provide it when accessing it with the client.
from gradio_client import Client
client = Client("abidlabs/image_generator")
client.predict(text="an astronaut riding a camel")
The default value is the initial value of the corresponding Gradio component.
If the component does not have an initial value, but if the corresponding
argument in the predict function has a default value of `None`, then that
parameter is also optional in the client. Of course, if you’d like to override
it, you can include it as well:
from gradio_client import Client
client = Client("abidlabs/image_generator")
client.predict(text="an astronaut riding a camel", steps=25)
For providing files or URLs as inputs, you should pass in the filepath or URL
to the file enclosed within `gradio_client.file()`. This takes care of
uploading the file to the Gradio server and ensures that the file is
preprocessed correctly:
from gradio_client import Client, file
client = Client("abidlabs/whisper")
client.predict(
|
Making a prediction
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
to the Gradio server and ensures that the file is
preprocessed correctly:
from gradio_client import Client, file
client = Client("abidlabs/whisper")
client.predict(
audio=file("https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3")
)
>> "My thought I have nobody by a beauty and will as you poured. Mr. Rochester is serve in that so don't find simpus, and devoted abode, to at might in a r—"
|
Making a prediction
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Oe should note that `.predict()` is a _blocking_ operation as it waits for the
operation to complete before returning the prediction.
In many cases, you may be better off letting the job run in the background
until you need the results of the prediction. You can do this by creating a
`Job` instance using the `.submit()` method, and then later calling
`.result()` on the job to get the result. For example:
from gradio_client import Client
client = Client(space="abidlabs/en2fr")
job = client.submit("Hello", api_name="/predict") This is not blocking
Do something else
job.result() This is blocking
>> Bonjour
|
Running jobs asynchronously
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Alternatively, one can add one or more callbacks to perform actions after the
job has completed running, like this:
from gradio_client import Client
def print_result(x):
print("The translated result is: {x}")
client = Client(space="abidlabs/en2fr")
job = client.submit("Hello", api_name="/predict", result_callbacks=[print_result])
Do something else
>> The translated result is: Bonjour
|
Adding callbacks
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
The `Job` object also allows you to get the status of the running job by
calling the `.status()` method. This returns a `StatusUpdate` object with the
following attributes: `code` (the status code, one of a set of defined strings
representing the status. See the `utils.Status` class), `rank` (the current
position of this job in the queue), `queue_size` (the total queue size), `eta`
(estimated time this job will complete), `success` (a boolean representing
whether the job completed successfully), and `time` (the time that the status
was generated).
from gradio_client import Client
client = Client(src="gradio/calculator")
job = client.submit(5, "add", 4, api_name="/predict")
job.status()
>> <Status.STARTING: 'STARTING'>
_Note_ : The `Job` class also has a `.done()` instance method which returns a
boolean indicating whether the job has completed.
|
Status
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
The `Job` class also has a `.cancel()` instance method that cancels jobs that
have been queued but not started. For example, if you run:
client = Client("abidlabs/whisper")
job1 = client.submit(file("audio_sample1.wav"))
job2 = client.submit(file("audio_sample2.wav"))
job1.cancel() will return False, assuming the job has started
job2.cancel() will return True, indicating that the job has been canceled
If the first job has started processing, then it will not be canceled. If the
second job has not yet started, it will be successfully canceled and removed
from the queue.
|
Cancelling Jobs
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Some Gradio API endpoints do not return a single value, rather they return a
series of values. You can get the series of values that have been returned at
any time from such a generator endpoint by running `job.outputs()`:
from gradio_client import Client
client = Client(src="gradio/count_generator")
job = client.submit(3, api_name="/count")
while not job.done():
time.sleep(0.1)
job.outputs()
>> ['0', '1', '2']
Note that running `job.result()` on a generator endpoint only gives you the
_first_ value returned by the endpoint.
The `Job` object is also iterable, which means you can use it to display the
results of a generator function as they are returned from the endpoint. Here’s
the equivalent example using the `Job` as a generator:
from gradio_client import Client
client = Client(src="gradio/count_generator")
job = client.submit(3, api_name="/count")
for o in job:
print(o)
>> 0
>> 1
>> 2
You can also cancel jobs that that have iterative outputs, in which case the
job will finish as soon as the current iteration finishes running.
from gradio_client import Client
import time
client = Client("abidlabs/test-yield")
job = client.submit("abcdef")
time.sleep(3)
job.cancel() job cancels after 2 iterations
|
Generator Endpoints
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Gradio demos can include [session state](https://www.gradio.app/guides/state-
in-blocks), which provides a way for demos to persist information from user
interactions within a page session.
For example, consider the following demo, which maintains a list of words that
a user has submitted in a `gr.State` component. When a user submits a new
word, it is added to the state, and the number of previous occurrences of that
word is displayed:
import gradio as gr
def count(word, list_of_words):
return list_of_words.count(word), list_of_words + [word]
with gr.Blocks() as demo:
words = gr.State([])
textbox = gr.Textbox()
number = gr.Number()
textbox.submit(count, inputs=[textbox, words], outputs=[number, words])
demo.launch()
If you were to connect this this Gradio app using the Python Client, you would
notice that the API information only shows a single input and output:
Client.predict() Usage Info
---------------------------
Named API endpoints: 1
- predict(word, api_name="/count") -> value_31
Parameters:
- [Textbox] word: str (required)
Returns:
- [Number] value_31: float
That is because the Python client handles state automatically for you — as you
make a series of requests, the returned state from one request is stored
internally and automatically supplied for the subsequent request. If you’d
like to reset the state, you can do that by calling `Client.reset_session()`.
|
Demos with Session State
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
The main Client class for the Python client. This class is used to connect
to a remote Gradio app and call its API endpoints.
|
Description
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
from gradio_client import Client
client = Client("abidlabs/whisper-large-v2") connecting to a Hugging Face Space
client.predict("test.mp4", api_name="/predict")
>> What a nice recording! returns the result of the remote API call
client = Client("https://bec81a83-5b5c-471e.gradio.live") connecting to a temporary Gradio share URL
job = client.submit("hello", api_name="/predict") runs the prediction in a background thread
job.result()
>> 49 returns the result of the remote API call (blocking call)
|
Example usage
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
Parameters ▼
src: str
either the name of the Hugging Face Space to load, (e.g. "abidlabs/whisper-
large-v2") or the full URL (including "http" or "https") of the hosted Gradio
app to load (e.g. "http://mydomain.com/app" or
"https://bec81a83-5b5c-471e.gradio.live/").
token: str | None
default `= None`
optional Hugging Face token to use to access private Spaces. By default, the
locally saved token is used if there is one. Find your tokens here:
https://huggingface.co/settings/tokens.
max_workers: int
default `= 40`
maximum number of thread workers that can be used to make requests to the
remote Gradio app simultaneously.
verbose: bool
default `= True`
whether the client should print statements to the console.
auth: tuple[str, str] | None
default `= None`
httpx_kwargs: dict[str, Any] | None
default `= None`
additional keyword arguments to pass to `httpx.Client`, `httpx.stream`,
`httpx.get` and `httpx.post`. This can be used to set timeouts, proxies, http
auth, etc.
headers: dict[str, str] | None
default `= None`
additional headers to send to the remote Gradio app on every request. By
default only the HF authorization and user-agent headers are sent. This
parameter will override the default headers if they have the same keys.
download_files: str | Path | Literal[False]
default `= "/tmp/gradio"`
directory where the client should download output files on the local machine
from the remote API. By default, uses the value of the GRADIO_TEMP_DIR
environment variable which, if not set by the user, is a temporary directory
on your machine. If False, the client does not download files and returns a
FileData dataclass object with the filepath on the remote machine instead.
ssl_verify: bool
default `= True`
if False, skips certificate validation which allows the client to connect to
Gradio apps that are using self-signed ce
|
Initialization
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
n the remote machine instead.
ssl_verify: bool
default `= True`
if False, skips certificate validation which allows the client to connect to
Gradio apps that are using self-signed certificates.
analytics_enabled: bool
default `= True`
Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED
environment variable or default to True.
|
Initialization
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
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 Client component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Client.predict(fn, ···)
Calls the Gradio API and returns the result (this is a blocking call).
Arguments can be provided as positional arguments or as keyword arguments
(latter is recommended). <br>
Client.submit(fn, ···)
Creates and returns a Job object which calls the Gradio API in a background
thread. The job can be used to retrieve the status and result of the remote
API call. Arguments can be provided as positional arguments or as keyword
arguments (latter is recommended). <br>
Client.view_api(fn, ···)
Prints the usage info for the API. If the Gradio app has multiple API
endpoints, the usage info for each endpoint will be printed separately. If
return_format="dict" the info is returned in dictionary format, as shown in
the example below. <br>
Client.duplicate(fn, ···)
Duplicates a Hugging Face Space under your account and returns a Client object
for the new Space. No duplication is created if the Space already exists in
your account (to override this, provide a new name for the new Space using
`to_id`). To use this method, you must provide an `token` or be logged in via
the Hugging Face Hub CLI. <br> The new Space will be private by default and
use the same hardware as the original Space. This can be changed by using the
`private` and `hardware` parameters. For hardware upgrades (beyond the basic
CPU tier), you may be required to provide billing information on Hugging Face:
<https://huggingface.co/settings/billing> <br>
Event Parameters
Par
|
Event Listeners
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
eters. For hardware upgrades (beyond the basic
CPU tier), you may be required to provide billing information on Hugging Face:
<https://huggingface.co/settings/billing> <br>
Event Parameters
Parameters ▼
args: <class 'inspect._empty'>
The positional arguments to pass to the remote API endpoint. The order of the
arguments must match the order of the inputs in the Gradio app.
api_name: str | None
default `= None`
The name of the API endpoint to call starting with a leading slash, e.g.
"/predict". Does not need to be provided if the Gradio app has only one named
API endpoint.
fn_index: int | None
default `= None`
As an alternative to api_name, this parameter takes the index of the API
endpoint to call, e.g. 0. Both api_name and fn_index can be provided, but if
they conflict, api_name will take precedence.
headers: dict[str, str] | None
default `= None`
Additional headers to send to the remote Gradio app on this request. This
parameter will overrides the headers provided in the Client constructor if
they have the same keys.
kwargs: <class 'inspect._empty'>
The keyword arguments to pass to the remote API endpoint.
|
Event Listeners
|
https://gradio.app/docs/python-client/client
|
Python Client - Client Docs
|
ZeroGPU
ZeroGPU spaces are rate-limited to ensure that a single user does not hog all
of the available GPUs. The limit is controlled by a special token that the
Hugging Face Hub infrastructure adds to all incoming requests to Spaces. This
token is a request header called `X-IP-Token` and its value changes depending
on the user who makes a request to the ZeroGPU space.
Let’s say you want to create a space (Space A) that uses a ZeroGPU space
(Space B) programmatically. Normally, calling Space B from Space A with the
Gradio Python client would quickly exhaust Space B’s rate limit, as all the
requests to the ZeroGPU space would be missing the `X-IP-Token` request header
and would therefore be treated as unauthenticated.
In order to avoid this, we need to extract the `X-IP-Token` of the user using
Space A before we call Space B programmatically. Where possible, specifically
in the case of functions that are passed into event listeners directly, Gradio
automatically extracts the `X-IP-Token` from the incoming request and passes
it into the Gradio Client. But if the Client is instantiated outside of such a
function, then you may need to pass in the token manually.
How to do this will be explained in the following section.
|
Explaining Rate Limits for
|
https://gradio.app/docs/python-client/using-zero-gpu-spaces
|
Python Client - Using Zero Gpu Spaces Docs
|
Token
In the following hypothetical example, when a user presses enter in the
textbox, the `generate()` function is called, which calls a second function,
`text_to_image()`. Because the Gradio Client is being instantiated indirectly,
in `text_to_image()`, we will need to extract their token from the `X-IP-
Token` header of the incoming request. We will use this header when
constructing the gradio client.
import gradio as gr
from gradio_client import Client
def text_to_image(prompt, request: gr.Request):
x_ip_token = request.headers['x-ip-token']
client = Client("hysts/SDXL", headers={"x-ip-token": x_ip_token})
img = client.predict(prompt, api_name="/predict")
return img
def generate(prompt, request: gr.Request):
prompt = prompt[:300]
return text_to_image(prompt, request)
with gr.Blocks() as demo:
image = gr.Image()
prompt = gr.Textbox(max_lines=1)
prompt.submit(generate, [prompt], [image])
demo.launch()
|
Avoiding Rate Limits by Manually Passing an IP
|
https://gradio.app/docs/python-client/using-zero-gpu-spaces
|
Python Client - Using Zero Gpu Spaces Docs
|
**Stream From a Gradio app in 5 lines**
Use the `submit` method to get a job you can iterate over.
In python:
from gradio_client import Client
client = Client("gradio/llm_stream")
for result in client.submit("What's the best UI framework in Python?"):
print(result)
In typescript:
import { Client } from "@gradio/client";
const client = await Client.connect("gradio/llm_stream")
const job = client.submit("/predict", {"text": "What's the best UI framework in Python?"})
for await (const msg of job) console.log(msg.data)
**Use the same keyword arguments as the app**
In the examples below, the upstream app has a function with parameters called
`message`, `system_prompt`, and `tokens`. We can see that the client `predict`
call uses the same arguments.
In python:
from gradio_client import Client
client = Client("http://127.0.0.1:7860/")
result = client.predict(
message="Hello!!",
system_prompt="You are helpful AI.",
tokens=10,
api_name="/chat"
)
print(result)
In typescript:
import { Client } from "@gradio/client";
const client = await Client.connect("http://127.0.0.1:7860/");
const result = await client.predict("/chat", {
message: "Hello!!",
system_prompt: "Hello!!",
tokens: 10,
});
console.log(result.data);
**Better Error Messages**
If something goes wrong in the upstream app, the client will raise the same
exception as the app provided that `show_error=True` in the original app's
`launch()` function, or it's a `gr.Error` exception.
|
Ergonomic API 💆
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
Anything you can do in the UI, you can do with the client:
* 🔐Authentication
* 🛑 Job Cancelling
* ℹ️ Access Queue Position and API
* 📕 View the API information
Here's an example showing how to display the queue position of a pending job:
from gradio_client import Client
client = Client("gradio/diffusion_model")
job = client.submit("A cute cat")
while not job.done():
status = job.status()
print(f"Current in position {status.rank} out of {status.queue_size}")
|
Transparent Design 🪟
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
The client can run from pretty much any python and javascript environment
(node, deno, the browser, Service Workers).
Here's an example using the client from a Flask server using gevent:
from gevent import monkey
monkey.patch_all()
from gradio_client import Client
from flask import Flask, send_file
import time
app = Flask(__name__)
imageclient = Client("gradio/diffusion_model")
@app.route("/gen")
def gen():
result = imageclient.predict(
"A cute cat",
api_name="/predict"
)
return send_file(result)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
|
Portable Design ⛺️
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
Changes
**Python**
* The `serialize` argument of the `Client` class was removed and has no effect.
* The `upload_files` argument of the `Client` was removed.
* All filepaths must be wrapped in the `handle_file` method. For example, `caption = client.predict(handle_file('./dog.jpg'))`.
* The `output_dir` argument was removed. It is not specified in the `download_files` argument.
**Javascript**
The client has been redesigned entirely. It was refactored from a function
into a class. An instance can now be constructed by awaiting the `connect`
method.
const app = await Client.connect("gradio/whisper")
The app variable has the same methods as the python class (`submit`,
`predict`, `view_api`, `duplicate`).
|
v1.0 Migration Guide and Breaking
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
`gradio-rs` is a Gradio Client in Rust built by
[@JacobLinCool](https://github.com/JacobLinCool). You can find the repo
[here](https://github.com/JacobLinCool/gradio-rs), and more in depth API
documentation [here](https://docs.rs/gradio/latest/gradio/).
|
Introduction
|
https://gradio.app/docs/third-party-clients/rust-client
|
Third Party Clients - Rust Client Docs
|
Here is an example of using BS-RoFormer model to separate vocals and
background music from an audio file.
use gradio::{PredictionInput, Client, ClientOptions};
[tokio::main]
async fn main() {
if std::env::args().len() < 2 {
println!("Please provide an audio file path as an argument");
std::process::exit(1);
}
let args: Vec<String> = std::env::args().collect();
let file_path = &args[1];
println!("File: {}", file_path);
let client = Client::new("JacobLinCool/vocal-separation", ClientOptions::default())
.await
.unwrap();
let output = client
.predict(
"/separate",
vec![
PredictionInput::from_file(file_path),
PredictionInput::from_value("BS-RoFormer"),
],
)
.await
.unwrap();
println!(
"Vocals: {}",
output[0].clone().as_file().unwrap().url.unwrap()
);
println!(
"Background: {}",
output[1].clone().as_file().unwrap().url.unwrap()
);
}
You can find more examples [here](https://github.com/JacobLinCool/gradio-
rs/tree/main/examples).
|
Usage
|
https://gradio.app/docs/third-party-clients/rust-client
|
Third Party Clients - Rust Client Docs
|
cargo install gradio
gr --help
Take [stabilityai/stable-
diffusion-3-medium](https://huggingface.co/spaces/stabilityai/stable-
diffusion-3-medium) HF Space as an example:
> gr list stabilityai/stable-diffusion-3-medium
API Spec for stabilityai/stable-diffusion-3-medium:
/infer
Parameters:
prompt ( str )
negative_prompt ( str )
seed ( float ) numeric value between 0 and 2147483647
randomize_seed ( bool )
width ( float ) numeric value between 256 and 1344
height ( float ) numeric value between 256 and 1344
guidance_scale ( float ) numeric value between 0.0 and 10.0
num_inference_steps ( float ) numeric value between 1 and 50
Returns:
Result ( filepath )
Seed ( float ) numeric value between 0 and 2147483647
> gr run stabilityai/stable-diffusion-3-medium infer 'Rusty text "AI & CLI" on the snow.' '' 0 true 1024 1024 5 28
Result: https://stabilityai-stable-diffusion-3-medium.hf.space/file=/tmp/gradio/5735ca7775e05f8d56d929d8f57b099a675c0a01/image.webp
Seed: 486085626
For file input, simply use the file path as the argument:
gr run hf-audio/whisper-large-v3 predict 'test-audio.wav' 'transcribe'
output: " Did you know you can try the coolest model on your command line?"
|
Command Line Interface
|
https://gradio.app/docs/third-party-clients/rust-client
|
Third Party Clients - Rust Client Docs
|
Gradio applications support programmatic requests from many environments:
* The [Python Client](/docs/python-client): `gradio-client` allows you to make requests from Python environments.
* The [JavaScript Client](/docs/js-client): `@gradio/client` allows you to make requests in TypeScript from the browser or server-side.
* You can also query gradio apps [directly from cURL](/guides/querying-gradio-apps-with-curl).
|
Gradio Clients
|
https://gradio.app/docs/third-party-clients/introduction
|
Third Party Clients - Introduction Docs
|
We also encourage the development and use of third party clients built by
the community:
* [Rust Client](/docs/third-party-clients/rust-client): `gradio-rs` built by [@JacobLinCool](https://github.com/JacobLinCool) allows you to make requests in Rust.
* [Powershell Client](https://github.com/rrg92/powershai): `powershai` built by [@rrg92](https://github.com/rrg92) allows you to make requests to Gradio apps directly from Powershell. See [here for documentation](https://github.com/rrg92/powershai/blob/main/docs/en-US/providers/HUGGING-FACE.md)
|
Community Clients
|
https://gradio.app/docs/third-party-clients/introduction
|
Third Party Clients - Introduction Docs
|
A Gradio Interface includes a ‘Flag’ button that appears underneath the
output. By default, clicking on the Flag button sends the input and output
data back to the machine where the gradio demo is running, and saves it to a
CSV log file. But this default behavior can be changed. To set what happens
when the Flag button is clicked, you pass an instance of a subclass of
_FlaggingCallback_ to the _flagging_callback_ parameter in the _Interface_
constructor. You can use one of the _FlaggingCallback_ subclasses that are
listed below, or you can create your own, which lets you do whatever you want
with the data that is being flagged.
SimpleCSVLogger
gradio.SimpleCSVLogger(···)
|
Description
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
A simplified implementation of the FlaggingCallback abstract class provided
for illustrative purposes. Each flagged sample (both the input and output
data) is logged to a CSV file on the machine running the gradio app.
|
Description
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
import gradio as gr
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label",
flagging_callback=SimpleCSVLogger())
CSVLogger
gradio.CSVLogger(···)
|
Example Usage
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
The default implementation of the FlaggingCallback abstract class in
gradio>=5.0. Each flagged sample (both the input and output data) is logged to
a CSV file with headers on the machine running the gradio app. Unlike
ClassicCSVLogger, this implementation is concurrent-safe and it creates a new
dataset file every time the headers of the CSV (derived from the labels of the
components) change. It also only creates columns for "username" and "flag" if
the flag_option and username are provided, respectively.
|
Description
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
import gradio as gr
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label",
flagging_callback=CSVLogger())
|
Example Usage
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
Parameters ▼
simplify_file_data: bool
default `= True`
If True, the file data will be simplified before being written to the CSV
file. If CSVLogger is being used to cache examples, this is set to False to
preserve the original FileData class
verbose: bool
default `= True`
If True, prints messages to the console about the dataset file creation
dataset_file_name: str | None
default `= None`
The name of the dataset file to be created (should end in ".csv"). If None,
the dataset file will be named "dataset1.csv" or the next available number.
[Using Flagging](../../guides/using-flagging/)
|
Initialization
|
https://gradio.app/docs/gradio/flagging
|
Gradio - Flagging Docs
|
Displays an interactive table of parameters and their descriptions and
default values with syntax highlighting. For each parameter, the user should
provide a type (e.g. a `str`), a human-readable description, and a default
value. As this component does not accept user input, it is rarely used as an
input component. Internally, this component is used to display the parameters
of components in the Custom Component Gallery (<https://www.gradio.app/custom-
components/gallery).>
|
Description
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
**As input component** : (Rarely used) passes value as a `dict[str, dict]`.
The key in the outer dictionary is the parameter name, while the inner
dictionary has keys "type", "description", and "default" for each parameter.
Your function should accept one of these types:
def predict(
value: dict[str, Parameter]
)
...
**As output component** : Expects value as a `dict[str, dict]`. The key in
the outer dictionary is the parameter name, while the inner dictionary has
keys "type", "description", and "default" for each parameter.
Your function should return one of these types:
def predict(···) -> dict[str, Parameter]
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Parameters ▼
value: dict[str, Parameter] | None
default `= None`
A dictionary of dictionaries. The key in the outer dictionary is the parameter
name, while the inner dictionary has keys "type", "description", and "default"
for each parameter. Markdown links are supported in "description".
language: Literal['python', 'typescript']
default `= "python"`
The language to display the code in. One of "python" or "typescript".
linkify: list[str] | None
default `= None`
A list of strings to linkify. If any of these strings is found in the
description, it will be rendered as a link.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
er()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
header: str | None
default `= "Parameters"`
The header to display above the table of parameters, also includes a toggle
button that closes/opens all details at once. If None, no header will be
displayed.
anchor_links: bool | str
default `= False`
If True, creates anchor links for each parameter that can be used to link
directly to that parameter. If a string, creates anchor links with the given
string as the prefix to prevent conflicts with other ParamViewer components.
max_height: int | str | None
default `= None`
The maximum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If content exceeds the height,
the parameter table will scroll vertically while the header remains fixed in
place. If content is shorter than the height, the component will shrink to fit
the content.
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Shortcuts
gradio.ParamViewer
Interface String Shortcut `"paramviewer"`
Initialization Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
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 ParamViewer component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
ParamViewer.change(fn, ···)
Triggered when the value of the ParamViewer changes either because of user
input (e.g. a user types in a textbox) OR because of a function update (e.g.
an image receives a value from the output of an event trigger). See `.input()`
for a listener that is only triggered by user input.
ParamViewer.upload(fn, ···)
This listener is triggered when the user uploads a file into the ParamViewer.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
rns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: in
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
[Documenting Custom Comp
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
[Documenting Custom Components](../../guides/documenting-custom-components/)
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Creates an audio component that can be used to upload/record audio (as an
input) or display audio (as an output).
|
Description
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
**As input component** : passes audio as one of these formats (depending on
`type`): a `str` filepath, or `tuple` of (sample rate in Hz, audio data as
numpy array). If the latter, the audio data is a 16-bit `int` array whose
values range from -32768 to 32767 and shape of the audio data array is
(samples,) for mono audio or (samples, channels) for multi-channel audio.
Your function should accept one of these types:
def predict(
value: str | tuple[int, np.ndarray] | None
)
...
**As output component** : expects audio data in any of these formats: a
`str` or `pathlib.Path` filepath or URL to an audio file, or a `bytes` object
(recommended for streaming), or a `tuple` of (sample rate in Hz, audio data as
numpy array). Note: if audio is supplied as a numpy array, the audio will be
normalized by its peak value to avoid distortion or clipping in the resulting
audio.
Your function should return one of these types:
def predict(···) -> str | Path | bytes | tuple[int, np.ndarray] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
Parameters ▼
value: str | Path | tuple[int, np.ndarray] | Callable | None
default `= None`
A path, URL, or [sample_rate, numpy array] tuple (sample rate in Hz, audio
data as a float or int numpy array) for the default value that Audio component
is going to take. If a function is provided, the function will be called each
time the app loads to set the initial value of this component.
sources: list[Literal['upload', 'microphone']] | Literal['upload', 'microphone'] | None
default `= None`
A list of sources permitted for audio. "upload" creates a box where user can
drop an audio file, "microphone" creates a microphone input. The first element
in the list will be used as the default source. If None, defaults to
["upload", "microphone"], or ["microphone"] if `streaming` is True.
type: Literal['numpy', 'filepath']
default `= "numpy"`
The format the audio file is converted to before being passed into the
prediction function. "numpy" converts the audio to a tuple consisting of: (int
sample rate, numpy.array for the data), "filepath" passes a str path to a
temporary file containing the audio.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
|
Initialization
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
Relative width compared to adjacent Components in a Row. For example, if
Component A has scale=2, and Component B has scale=1, A will be twice as wide
as B. Should be an integer.
min_width: int
default `= 160`
Minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
If True, will allow users to upload and edit an audio file. If False, can only
be used to play audio. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM If
"hidden", component will be visually hidden and not take up space in the
layout but still exist in the DOM.
streaming: bool
default `= False`
If set to True when used in a `live` interface as an input, will automatically
stream webcam feed. When used set as an output, takes audio chunks yield from
the backend and combines them into one streaming audio output.
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list
|
Initialization
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
if False, component will not be rendered in the Blocks context. Should be used
if the intention is to assign event listeners now but render the component
later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
format: Literal['wav', 'mp3'] | None
default `= None`
the file extension with which to save audio files. Either 'wav' or 'mp3'. wav
files are lossless but will tend to be larger files. mp3 files tend to be
smaller. This parameter applies both when this component is used as an input
(and `type` is "filepath") to determine which file format to convert user-
provided audio to, and when this component is used as an output to determine
the format of audio returned to the user. If None, no file format conversion
is done and the audio is kept as is. In the case where output audio is
returned from the prediction function as numpy array and no `format` is
provided, it will be returned as a "wav" file.
au
|
Initialization
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
and the audio is kept as is. In the case where output audio is
returned from the prediction function as numpy array and no `format` is
provided, it will be returned as a "wav" file.
autoplay: bool
default `= False`
Whether to automatically play the audio when the component is used as an
output. Note: browsers will not autoplay audio files if the user has not
interacted with the page yet.
editable: bool
default `= True`
If True, allows users to manipulate the audio file if the component is
interactive. Defaults to True.
buttons: list[Literal['download', 'share'] | Button] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "download", "share", or a gr.Button() instance. The "download"
button allows the user to save the audio to their device. The "share" button
allows the user to share the audio via Hugging Face Spaces Discussions. Custom
gr.Button() instances will appear in the toolbar with their configured icon
and/or label, and clicking them will trigger any .click() events registered on
the button. By default, only the "download" and "share" buttons are shown.
waveform_options: WaveformOptions | dict | None
default `= None`
A dictionary of options for the waveform display. Options include:
waveform_color (str), waveform_progress_color (str), skip_length (int),
trim_region_color (str). Default is None, which uses the default values for
these options. See `gr.WaveformOptions` docs.
loop: bool
default `= False`
If True, the audio will loop when it reaches the end and continue playing from
the beginning.
recording: bool
default `= False`
If True, the audio component will be set to record audio from the microphone
if the source is set to "microphone". Defaults to False.
subtitles: str | Path | list[dict[str, Any]] | None
default `= None`
A subtitle file (srt, vtt, or json) for the audio,
|
Initialization
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
hone
if the source is set to "microphone". Defaults to False.
subtitles: str | Path | list[dict[str, Any]] | None
default `= None`
A subtitle file (srt, vtt, or json) for the audio, or a list of subtitle
dictionaries in the format [{"text": str, "timestamp": [start, end]}] where
timestamps are in seconds. JSON files should contain an array of subtitle
objects.
playback_position: float
default `= 0`
The starting playback position in seconds. This value is also updated as the
audio plays, reflecting the current playback position.
|
Initialization
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
Shortcuts
gradio.Audio
Interface String Shortcut `"audio"`
Initialization Uses default values
gradio.Microphone
Interface String Shortcut `"microphone"`
Initialization Uses sources=["microphone"]
|
Shortcuts
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
generate_tonereverse_audio
|
Demos
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
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 Audio component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Audio.stream(fn, ···)
This listener is triggered when the user streams the Audio.
Audio.change(fn, ···)
Triggered when the value of the Audio changes either because of user input
(e.g. a user types in a textbox) OR because of a function update (e.g. an
image receives a value from the output of an event trigger). See `.input()`
for a listener that is only triggered by user input.
Audio.clear(fn, ···)
This listener is triggered when the user clears the Audio using the clear
button for the component.
Audio.play(fn, ···)
This listener is triggered when the user plays the media in the Audio.
Audio.pause(fn, ···)
This listener is triggered when the media in the Audio stops for any reason.
Audio.stop(fn, ···)
This listener is triggered when the user reaches the end of the media playing
in the Audio.
Audio.pause(fn, ···)
This listener is triggered when the media in the Audio stops for any reason.
Audio.start_recording(fn, ···)
This listener is triggered when the user starts recording with the Audio.
Audio.pause_recording(fn, ···)
This listener is triggered when the user pauses recording with the Audio.
Audio.stop_recording(fn, ···)
This listener is triggered when the user stops recording with the Audio.
Audio.upload(fn, ···)
This listener is triggered when the user uploads a file into the Audio.
Audio.input(fn, ···)
This listener is tr
|
Event Listeners
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
r stops recording with the Audio.
Audio.upload(fn, ···)
This listener is triggered when the user uploads a file into the Audio.
Audio.input(fn, ···)
This listener is triggered when the user changes the value of the Audio.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_p
|
Event Listeners
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
f False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "minimal"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
c
|
Event Listeners
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'pr
|
Event Listeners
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
Helper Classes
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
|
gradio.WaveformOptions(···)
Description
A dataclass for specifying options for the waveform display in the Audio
component. An instance of this class can be passed into the `waveform_options`
parameter of `gr.Audio`.
Initialization
Parameters ▼
waveform_color: str | None
default `= None`
The color (as a hex string or valid CSS color) of the full waveform
representing the amplitude of the audio. Defaults to a light gray color.
waveform_progress_color: str | None
default `= None`
The color (as a hex string or valid CSS color) that the waveform fills with to
as the audio plays. Defaults to the accent color.
trim_region_color: str | None
default `= None`
The color (as a hex string or valid CSS color) of the trim region. Defaults to
the accent color.
show_recording_waveform: bool
default `= True`
If True, shows a waveform when recording audio or playing audio. If False,
uses the default browser audio players. For streamed audio, the default
browser audio player is always used.
skip_length: int | float
default `= 5`
The percentage (between 0 and 100) of the audio to skip when clicking on the
skip forward / skip backward buttons.
sample_rate: int
default `= 44100`
The output sample rate (in Hz) of the audio after editing.
|
WaveformOptions
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
Validates that the audio length is within the specified min and max length (in
seconds). You can use this to construct a validator that will check if the
user-provided audio is either too short or too long.
import gradio as gr
demo = gr.Interface(
lambda x: x,
inputs="audio",
outputs="audio",
validator=lambda audio: gr.validators.is_audio_correct_length(audio, min_length=1, max_length=5)
)
demo.launch()
Initialization
Parameters ▼
audio: tuple[int, 'np.ndarray']
A tuple of (sample rate in Hz, audio data as numpy array).
min_length: float | None
Minimum length of audio in seconds. If None, no minimum length check is
performed.
max_length: float | None
Maximum length of audio in seconds. If None, no maximum length check is
performed.
[Streaming Inputs](../../guides/streaming-inputs/)[Streaming
Outputs](../../guides/streaming-outputs/)[Automatic Voice
Detection](../../guides/automatic-voice-detection/)[Real Time Speech
Recognition](../../guides/real-time-speech-recognition/)
|
is_audio_correct_length
|
https://gradio.app/docs/gradio/audio
|
Gradio - Audio Docs
|
Tab (or its alias TabItem) is a layout element. Components defined within
the Tab will be visible when this tab is selected tab.
|
Description
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
with gr.Blocks() as demo:
with gr.Tab("Lion"):
gr.Image("lion.jpg")
gr.Button("New Lion")
with gr.Tab("Tiger"):
gr.Image("tiger.jpg")
gr.Button("New Tiger")
|
Example Usage
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
Parameters ▼
label: str | I18nData | None
default `= None`
The visual label for the tab
visible: bool | Literal['hidden']
default `= True`
If False, Tab will be hidden.
interactive: bool
default `= True`
If False, Tab will not be clickable.
id: int | str | None
default `= None`
An optional identifier for the tab, required if you wish to control the
selected tab from a predict function.
elem_id: str | None
default `= None`
An optional string that is assigned as the id of the <div> containing the
contents of the Tab layout. The same string followed by "-button" is attached
to the Tab button. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional string or list of strings that are assigned as the class of this
component in the HTML DOM. Can be used for targeting CSS styles.
scale: int | None
default `= None`
relative size compared to adjacent elements. 1 or greater indicates the Tab
will expand in size.
render: bool
default `= True`
If False, this layout will not be rendered in the Blocks context. Should be
used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
preserved_by_key: list[str] | str | None
default `= None`
render_children: bool
default `= False`
If True, the children of this Tab will be rendered on the page (but hidden)
when the Tab is visible but inactive. This can be useful if you want to ensure
that any components (e.g. videos or audio) within the Tab are pre-loaded
before the user clicks on the Tab.
|
Initialization
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
Methods
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Tab.select(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.%20--%
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Event listener for when the user selects the Tab. Uses event data
gradio.SelectData to carry `value` referring to the label of the Tab, and
`selected` to refer to state of the Tab. See
https://www.gradio.app/main/docs/gradio/eventdata documentation for more
details.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corre
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
le | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress anim
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
ner is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
c"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
[Controlling Layout](../../guides/controlling-layout/)
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Tab.select(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.%20--%
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Event listener for when the user selects the Tab. Uses event data
gradio.SelectData to carry `value` referring to the label of the Tab, and
`selected` to refer to state of the Tab. See
https://www.gradio.app/main/docs/gradio/eventdata documentation for more
details.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corre
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
le | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress anim
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
ner is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
c"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
select
|
https://gradio.app/docs/gradio/tab
|
Gradio - Tab Docs
|
Any code in a `if gr.NO_RELOAD` code-block will not be re-evaluated when
the source file is reloaded. This is helpful for importing modules that do not
like to be reloaded (tiktoken, numpy) as well as database connections and long
running set up code.
|
Description
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
import gradio as gr
if gr.NO_RELOAD:
from transformers import pipeline
pipe = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
gr.Interface.from_pipeline(pipe).launch()
|
Example Usage
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
Sidebar is a collapsible panel that renders child components on the left
side of the screen within a Blocks layout.
|
Description
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
with gr.Blocks() as demo:
with gr.Sidebar():
gr.Textbox()
gr.Button()
|
Example Usage
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
Parameters ▼
label: str | I18nData | None
default `= None`
name of the sidebar. Not displayed to the user.
open: bool
default `= True`
if True, sidebar is open by default.
visible: bool | Literal['hidden']
default `= True`
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional string or list of strings that are assigned as the class of this
component in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, this layout will not be rendered in the Blocks context. Should be
used if the intention is to assign event listeners now but render the
component later.
width: int | str
default `= 320`
The width of the sidebar, specified in pixels if a number is passed, or in CSS
units if a string is passed.
position: Literal['left', 'right']
default `= "left"`
The position of the sidebar in the layout, either "left" or "right". Defaults
to "left".
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= None`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
Methods
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Sidebar.expand(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.%2
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Sidebar is expanded.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | B
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animat
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
defaul
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
ators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | t
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Sidebar.collapse(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Sidebar is collapsed.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
nds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress ani
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
on at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
def
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
nerators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
No dataset card yet