text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 183
values | source_page_title
stringclasses 183
values |
|---|---|---|---|
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="video",
outputs="video",
validator=lambda video: gr.validators.is_video_correct_length(video, min_length=1, max_length=5)
)
demo.launch()
Initialization
Parameters ▼
video: <class 'str'>
The path to the video file.
min_length: float | None
Minimum length of video in seconds. If None, no minimum length check is
performed.
max_length: float | None
Maximum length of video in seconds. If None, no maximum length check is
performed.
|
is_video_correct_length
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
Sets up an event listener that triggers a function when the specified
event(s) occur. This is especially useful when the same function should be
triggered by multiple events. Only a single API endpoint is generated for all
events in the triggers list.
|
Description
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
import gradio as gr
with gr.Blocks() as demo:
with gr.Row():
input = gr.Textbox()
button = gr.Button("Submit")
output = gr.Textbox()
gr.on(
triggers=[button.click, input.submit],
fn=lambda x: x,
inputs=[input],
outputs=[output]
)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
Parameters ▼
triggers: list[EventListenerCallable] | EventListenerCallable | None
default `= None`
List of triggers to listen to, e.g. [btn.click, number.change]. If None, will
run on app load and changes to any inputs.
fn: Callable[..., Any] | 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_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".
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`
scroll_to_output: bool
default `
|
Initialization
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
e (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
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 (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 postproces
|
Initialization
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
ata 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', 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 c
|
Initialization
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
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.
time_limit: int | None
default `= None`
The time limit for the function to run. Parameter only used for the
`.stream()` event.
stream_every: float
default `= 0.5`
The latency (in seconds) at which stream chunks are sent to the backend.
Defaults to 0.5 seconds. Parameter only used for the `.stream()` event.
key: int | str | tuple[int | str, ...] | None
default `= None`
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.
|
Initialization
|
https://gradio.app/docs/gradio/on
|
Gradio - On Docs
|
The gr.CopyData class is a subclass of gr.EventData that specifically
carries information about the `.copy()` event. When gr.CopyData is added as a
type hint to an argument of an event listener method, a gr.CopyData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
|
Description
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
import gradio as gr
def on_copy(copy_data: gr.CopyData):
return f"Copied text: {copy_data.value}"
with gr.Blocks() as demo:
textbox = gr.Textbox("Hello World!")
copied = gr.Textbox()
textbox.copy(on_copy, None, copied)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
Parameters ▼
value: Any
The value that was copied.
|
Attributes
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
Row is a layout element within Blocks that renders all children
horizontally.
|
Description
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
with gr.Blocks() as demo:
with gr.Row():
gr.Image("lion.jpg", scale=2)
gr.Image("tiger.jpg", scale=1)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
Parameters ▼
variant: Literal['default', 'panel', 'compact']
default `= "default"`
row type, 'default' (no background), 'panel' (gray background color and
rounded corners), or 'compact' (rounded corners and no internal gap).
visible: bool | Literal['hidden']
default `= True`
If False, row will be hidden.
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.
scale: int | None
default `= None`
relative height compared to adjacent elements. 1 or greater indicates the Row
will expand in height, and any child columns will also expand to fill the
height.
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.
height: int | str | None
default `= None`
The height of the row, specified in pixels if a number is passed, or in CSS
units if a string is passed. If content exceeds the height, the row will
scroll vertically. If not set, the row will expand to fit the content.
max_height: int | str | None
default `= None`
The maximum height of the row, specified in pixels if a number is passed, or
in CSS units if a string is passed. If content exceeds the height, the row
will scroll vertically. If content is shorter than the height, the row will
shrink to fit the content. Will not have any effect if `height` is set and is
smaller than `max_height`.
min_height: int | str | None
default `= None`
The minimum height of the row, specified in pixels if a number is passed, or
in CSS units if a string is
|
Initialization
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
is
smaller than `max_height`.
min_height: int | str | None
default `= None`
The minimum height of the row, specified in pixels if a number is passed, or
in CSS units if a string is passed. If content exceeds the height, the row
will expand to fit the content. Will not have any effect if `height` is set
and is larger than `min_height`.
equal_height: bool
default `= False`
If True, makes every child element have equal height
show_progress: bool
default `= False`
If True, shows progress animation when being updated.
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/row
|
Gradio - Row Docs
|
Constructs a Gradio app automatically from a Hugging Face model/Space repo
name or a 3rd-party API provider. Note that if a Space repo is loaded, certain
high-level attributes of the Blocks (e.g. custom `css`, `js`, and `head`
attributes) will not be loaded.
|
Description
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
import gradio as gr
demo = gr.load("gradio/question-answering", src="spaces")
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
Parameters ▼
name: str
the name of the model (e.g. "google/vit-base-patch16-224") or Space (e.g.
"flax-community/spanish-gpt2"). This is the first parameter passed into the
`src` function. Can also be formatted as {src}/{repo name} (e.g.
"models/google/vit-base-patch16-224") if `src` is not provided.
src: Callable[[str, str | None], Blocks] | Literal['models', 'spaces', 'huggingface'] | None
default `= None`
function that accepts a string model `name` and a string or None `token` and
returns a Gradio app. Alternatively, this parameter takes one of two strings
for convenience: "models" (for loading a Hugging Face model through the
Inference API) or "spaces" (for loading a Hugging Face Space). If None, uses
the prefix of the `name` parameter to determine `src`.
token: str | None
default `= None`
optional token that is passed as the second parameter to the `src` function.
If not explicitly provided, will use the HF_TOKEN environment variable or
fallback to the locally-saved HF token when loading models but not Spaces
(when loading Spaces, only provide a token if you are loading a trusted
private Space as the token can be read by the Space you are loading). Find
your HF tokens here: https://huggingface.co/settings/tokens.
accept_token: bool | LoginButton
default `= False`
if True, a Textbox component is first rendered to allow the user to provide a
token, which will be used instead of the `token` parameter when calling the
loaded model or Space. Can also provide an instance of a gr.LoginButton in the
same Blocks scope, which allows the user to login with a Hugging Face account
whose token will be used instead of the `token` parameter when calling the
loaded model or Space.
provider: PROVIDER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova", "fal-ai", etc). Should be one of the
providers suppo
|
Initialization
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
DER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova", "fal-ai", etc). Should be one of the
providers supported by `huggingface_hub.InferenceClient`. This parameter is
only used when `src` is "models"
kwargs: <class 'inspect._empty'>
additional keyword parameters to pass into the `src` function. If `src` is
"models" or "Spaces", these parameters are passed into the `gr.Interface` or
`gr.ChatInterface` constructor.
|
Initialization
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
Creates a color picker for user to select a color as string input. Can be
used as an input to pass a color value to a function or as an output to
display a color value.
|
Description
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
**As input component** : Passes selected color value as a hex `str` into
the function.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a hex `str` returned from function and
sets color picker value to it.
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
Parameters ▼
value: str | Callable | None
default `= None`
default color hex code to provide in color picker. If a function is provided,
the function will be called each time the app loads to set the initial value
of this component.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` 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 corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
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.
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 size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a cer
|
Initialization
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
to top-level Components
in Blocks where fill_height=True.
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 be rendered as an editable color picker; if False, editing will
be disabled. 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
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 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
|
Initialization
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
ender()
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/colorpicker
|
Gradio - Colorpicker Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.ColorPicker`| "colorpicker"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
color_picker
|
Demos
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker 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 ColorPicker component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`ColorPicker.change(fn, ···)`| Triggered when the value of the ColorPicker
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.
`ColorPicker.input(fn, ···)`| This listener is triggered when the user changes
the value of the ColorPicker.
`ColorPicker.submit(fn, ···)`| This listener is triggered when the user
presses the Enter key while the ColorPicker is focused.
`ColorPicker.focus(fn, ···)`| This listener is triggered when the ColorPicker
is focused.
`ColorPicker.blur(fn, ···)`| This listener is triggered when the ColorPicker
is unfocused/blurred.
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 | BlockConte
|
Event Listeners
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
ult `= 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 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 g
|
Event Listeners
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
ue, 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
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 submi
|
Event Listeners
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
missions 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 | 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 validatio
|
Event Listeners
|
https://gradio.app/docs/gradio/colorpicker
|
Gradio - Colorpicker Docs
|
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/colorpicker
|
Gradio - Colorpicker Docs
|
Creates a file explorer component that allows users to browse files on the
machine hosting the Gradio app. As an input component, it also allows users to
select files to be used as input to a function, while as an output component,
it displays selected files.
|
Description
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
**As input component** : Passes the selected file or directory as a `str`
path (relative to `root`) or `list[str}` depending on `file_count`
Your function should accept one of these types:
def predict(
value: list[str] | str | None
)
...
**As output component** : Expects function to return a `str` path to a
file, or `list[str]` consisting of paths to files.
Your function should return one of these types:
def predict(···) -> str | list[str] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
Parameters ▼
glob: str
default `= "**/*"`
The glob-style pattern used to select which files to display, e.g. "*" to
match all files, "*.png" to match all .png files, "**/*.txt" to match any .txt
file in any subdirectory, etc. The default value matches all files and folders
recursively. See the Python glob documentation at
https://docs.python.org/3/library/glob.html for more information.
value: str | list[str] | Callable | None
default `= None`
The file (or list of files, depending on the `file_count` parameter) to show
as "selected" when the component is first loaded. If a callable is provided,
it will be called when the app loads to set the initial value of the
component. If not provided, no files are shown as selected.
file_count: Literal['single', 'multiple']
default `= "multiple"`
Whether to allow single or multiple files to be selected. If "single", the
component will return a single absolute file path as a string. If "multiple",
the component will return a list of absolute file paths as a list of strings.
root_dir: str | Path
default `= "."`
Path to root directory to select files from. If not provided, defaults to
current working directory. Raises ValueError if the directory does not exist.
ignore_glob: str | None
default `= None`
The glob-style, case-sensitive pattern that will be used to exclude files from
the list. For example, "*.py" will exclude all .py files from the list. See
the Python glob documentation at https://docs.python.org/3/library/glob.html
for more information.
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
|
Initialization
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
onent. 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.
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 size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
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.
height: int | str | None
default `= None`
The maximum height of the file component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If more files are uploaded than
can fit in the height, a scrollbar will appear.
max_height: int | str | None
default `= 500`
min_height: int | str | None
default `= None`
interactive: bool | None
default `= None`
if True, will allow users to select file(s); if False, will only display
file
|
Initialization
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
min_height: int | str | None
default `= None`
interactive: bool | None
default `= None`
if True, will allow users to select file(s); if False, will only display
files. 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
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 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-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.FileExplorer`| "fileexplorer"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer 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 FileExplorer component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`FileExplorer.change(fn, ···)`|
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,
|
Event Listeners
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
teral[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 (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 runni
|
Event Listeners
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
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: 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
|
Event Listeners
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
ny 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.
|
Event Listeners
|
https://gradio.app/docs/gradio/fileexplorer
|
Gradio - Fileexplorer Docs
|
Creates a textarea for users to enter string input or display string output
and also allows for the uploading of multimedia files.
|
Description
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
**As input component** : Passes text value and list of file(s) as a `dict`
into the function.
Your function should accept one of these types:
def predict(
value: MultimodalValue | None
)
...
**As output component** : Expects a `dict` with "text" and "files", both
optional. The files array is a list of file paths or URLs.
Your function should return one of these types:
def predict(···) -> MultimodalValue | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
Parameters ▼
value: str | dict[str, str | list] | Callable | None
default `= None`
Default value to show in MultimodalTextbox. A string value, or a dictionary of
the form {"text": "sample text", "files": [{path: "files/file.jpg", orig_name:
"file.jpg", url: "http://image_url.jpg", size: 100}]}. 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. "upload" creates a button where users can click
to upload or drop files, "microphone" creates a microphone input. If None,
defaults to ["upload"].
file_types: list[str] | None
default `= None`
List of file extensions or types of files to be uploaded (e.g. ['image',
'.json', '.mp4']). "file" allows any file to be uploaded, "image" allows only
image files to be uploaded, "audio" allows only audio files to be uploaded,
"video" allows only video files to be uploaded, "text" allows only text files
to be uploaded.
file_count: Literal['single', 'multiple', 'directory']
default `= "single"`
if single, allows user to upload one file. If "multiple", user uploads
multiple files. If "directory", user uploads all files in selected directory.
Return type will be list for each file in case of "multiple" or "directory".
lines: int
default `= 1`
minimum number of line rows to provide in textarea.
max_lines: int
default `= 20`
maximum number of line rows to provide in textarea.
placeholder: str | None
default `= None`
placeholder hint to provide behind textarea.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.
|
Initialization
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
e`
the label for this component, displayed above the component if `show_label` is
`True` 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 corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
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.
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 size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
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 be rendered as an editable textbox; if False, editing will be
disabled. If not provided, this is inferred based on
|
Initialization
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
cted first.
interactive: bool | None
default `= None`
if True, will be rendered as an editable textbox; if False, editing will be
disabled. 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
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.
autofocus: bool
default `= False`
If True, will focus on the textbox when the page loads. Use this carefully, as
it can cause usability issues for sighted and non-sighted users.
autoscroll: bool
default `= True`
If True, will automatically scroll to the bottom of the textbox when the value
changes, unless the user scrolls up. If False, will not scroll to the bottom
of the textbox when the value changes.
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 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
|
Initialization
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
rved_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.
text_align: Literal['left', 'right'] | None
default `= None`
How to align the text in the textbox, can be: "left", "right", or None
(default). If None, the alignment is left if `rtl` is False, or right if `rtl`
is True. Can only be changed if `type` is "text".
rtl: bool
default `= False`
If True and `type` is "text", sets the direction of the text to right-to-left
(cursor appears on the left of the text). Default is False, which renders
cursor on the right.
submit_btn: str | bool | None
default `= True`
If False, will not show a submit button. If a string, will use that string as
the submit button text.
stop_btn: str | bool | None
default `= False`
If True, will show a stop button (useful for streaming demos). If a string,
will use that string as the stop button text.
max_plain_text_length: int
default `= 1000`
Maximum length of plain text in the textbox. If the text exceeds this length,
the text will be pasted as a file. Default is 1000.
html_attributes: InputHTMLAttributes | None
default `= None`
An instance of gr.InputHTMLAttributes, which can be used to set HTML
attributes for the input/textarea elements. Example:
InputHTMLAttributes(autocorrect="off", spellcheck=False) to disable
autocorrect and spellcheck.
|
Initialization
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.MultimodalTextbox`| "multimodaltextbox"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
chatbot_multimodal
|
Demos
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox 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 MultimodalTextbox component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener| Description
---|---
`MultimodalTextbox.change(fn, ···)`| Triggered when the value of the
MultimodalTextbox 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.
`MultimodalTextbox.input(fn, ···)`| This listener is triggered when the user
changes the value of the MultimodalTextbox.
`MultimodalTextbox.select(fn, ···)`| Event listener for when the user selects
or deselects the MultimodalTextbox. Uses event data gradio.SelectData to carry
`value` referring to the label of the MultimodalTextbox, and `selected` to
refer to state of the MultimodalTextbox. See EventData documentation on how to
use this event data
`MultimodalTextbox.submit(fn, ···)`| This listener is triggered when the user
presses the Enter key while the MultimodalTextbox is focused.
`MultimodalTextbox.focus(fn, ···)`| This listener is triggered when the
MultimodalTextbox is focused.
`MultimodalTextbox.blur(fn, ···)`| This listener is triggered when the
MultimodalTextbox is unfocused/blurred.
`MultimodalTextbox.stop(fn, ···)`| This listener is triggered when the user
reaches the end of the media playing in the MultimodalTextbox.
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 f
|
Event Listeners
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
ters
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_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 run
|
Event Listeners
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
o 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.
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 .clic
|
Event Listeners
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
ist 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', '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
c
|
Event Listeners
|
https://gradio.app/docs/gradio/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
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/multimodaltextbox
|
Gradio - Multimodaltextbox Docs
|
The gr.SelectData class is a subclass of gr.EventData that specifically
carries information about the `.select()` event. When gr.SelectData is added
as a type hint to an argument of an event listener method, a gr.SelectData
object will automatically be passed as the value of that argument. The
attributes of this object contains information about the event that triggered
the listener.
|
Description
|
https://gradio.app/docs/gradio/selectdata
|
Gradio - Selectdata Docs
|
import gradio as gr
with gr.Blocks() as demo:
table = gr.Dataframe([[1, 2, 3], [4, 5, 6]])
gallery = gr.Gallery([("cat.jpg", "Cat"), ("dog.jpg", "Dog")])
textbox = gr.Textbox("Hello World!")
statement = gr.Textbox()
def on_select(evt: gr.SelectData):
return f"You selected {evt.value} at {evt.index} from {evt.target}"
table.select(on_select, None, statement)
gallery.select(on_select, None, statement)
textbox.select(on_select, None, statement)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/selectdata
|
Gradio - Selectdata Docs
|
Parameters ▼
index: int | tuple[int, int]
The index of the selected item. Is a tuple if the component is two dimensional
or selection is a range.
value: Any
The value of the selected item.
row_value: list[float | str]
The value of the entire row that the selected item belongs to, as a 1-D list.
Only implemented for the `Dataframe` component, returns None for other
components.
col_value: list[float | str]
The value of the entire column that the selected item belongs to, as a 1-D
list. Only implemented for the `Dataframe` component, returns None for other
components.
selected: bool
True if the item was selected, False if deselected.
|
Attributes
|
https://gradio.app/docs/gradio/selectdata
|
Gradio - Selectdata Docs
|
gallery_selectionstictactoe
|
Demos
|
https://gradio.app/docs/gradio/selectdata
|
Gradio - Selectdata Docs
|
Creates an image component that can be used to upload images (as an input)
or display images (as an output).
|
Description
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
**As input component** : Passes the uploaded image as a `numpy.array`,
`PIL.Image` or `str` filepath depending on `type`.
Your function should accept one of these types:
def predict(
value: np.ndarray | PIL.Image.Image | str | None
)
...
**As output component** : Expects a `numpy.array`, `PIL.Image`, or `str` or
`pathlib.Path` filepath to an image which is displayed.
Your function should return one of these types:
def predict(···) -> np.ndarray | PIL.Image.Image | str | Path | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
Parameters ▼
value: str | PIL.Image.Image | np.ndarray | Callable | None
default `= None`
A `PIL.Image`, `numpy.array`, `pathlib.Path`, or `str` filepath or URL for the
default value that Image 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.
format: str
default `= "webp"`
File format (e.g. "png" or "gif"). Used to save image if it does not already
have a valid format (e.g. if the image is being returned to the frontend as a
numpy array or PIL Image). The format should be supported by the PIL library.
Applies both when this component is used as an input or output. This parameter
has no effect on SVG files.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None
default `= "RGB"`
The pixel format and color depth that the image should be loaded and
preprocessed as. "RGB" will load the image as a color image, or "L" as black-
and-white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html
for other supported image modes and their meaning. This parameter has no
effect on SVG or GIF files. If set to None, the image_mode will be inferred
from the image file type (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
sources: list[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboa
|
Initialization
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
erred
from the image file type (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
sources: list[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | None
default `= None`
List of sources for the image. "upload" creates a box where user can drop an
image file, "webcam" allows user to take snapshot from their webcam,
"clipboard" allows users to paste an image from the clipboard. If None,
defaults to ["upload", "webcam", "clipboard"] if streaming is False, otherwise
defaults to ["webcam"].
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The format the image is converted before being passed into the prediction
function. "numpy" converts the image to a numpy array with shape (height,
width, 3) and values from 0 to 255, "pil" converts the image to a PIL image
object, "filepath" passes a str path to a temporary file containing the image.
To support animated GIFs in input, the `type` should be set to "filepath" or
"pil". To support SVGs, the `type` should be set to "filepath".
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.
show_label: bool | None
default `= None`
if True, will disp
|
Initialization
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
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.
buttons: list[Literal['download', 'share', 'fullscreen']] | None
default `= None`
A list of buttons to show in the corner of the component. Valid options are
"download" to download the image, "share" to share to Hugging Face Spaces
Discussions, and "fullscreen" to view in fullscreen mode. By default, all
buttons are shown.
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 size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
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 image; if False, can only be
used to display images. 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
streaming: bool
default `= False`
If True when used in a `live` interface, will automatically stream webcam
feed. Only valid is source is 'webcam'. If the component is an output
component, will automatically convert im
|
Initialization
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
ault `= False`
If True when used in a `live` interface, will automatically stream webcam
feed. Only valid is source is 'webcam'. If the component is an output
component, will automatically convert images to base64.
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 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-rendered based on the values
provided during constructor.
webcam_options: WebcamOptions | None
default `= None`
placeholder: str | None
default `= None`
Custom text for the upload area. Overrides default upload messages when
provided. Accepts new lines and `` to designate a heading.
watermark: WatermarkOptions | None
default `= None`
If provided and this component is used to display a `value` image, the
`watermark` image will be displayed on the bottom right of the `value` image,
10 pixels from the bottom
|
Initialization
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
None
default `= None`
If provided and this component is used to display a `value` image, the
`watermark` image will be displayed on the bottom right of the `value` image,
10 pixels from the bottom and 10 pixels from the right. The watermark image
will not be resized. Supports `PIL.Image`, `numpy.array`, `pathlib.Path`, and
`str` filepaths. SVGs and GIFs are not supported as `watermark` images nor can
they be watermarked.
|
Initialization
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Image`| "image"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
The `gr.Image` component can process or display any image format that is
[supported by the PIL
library](https://pillow.readthedocs.io/en/stable/handbook/image-file-
formats.html), including animated GIFs. In addition, it also supports the SVG
image format.
When the `gr.Image` component is used as an input component, the image is
converted into a `str` filepath, a `PIL.Image` object, or a `numpy.array`,
depending on the `type` parameter. However, animated GIF and SVG images are
treated differently:
* Animated `GIF` images can only be converted to `str` filepaths or `PIL.Image` objects. If they are converted to a `numpy.array` (which is the default behavior), only the first frame will be used. So if your demo expects an input `GIF` image, make sure to set the `type` parameter accordingly, e.g.
import gradio as gr
demo = gr.Interface(
fn=lambda x:x,
inputs=gr.Image(type="filepath"),
outputs=gr.Image()
)
demo.launch()
* For `SVG` images, the `type` parameter is ignored altogether and the image is always returned as an image filepath. This is because `SVG` images cannot be processed as `PIL.Image` or `numpy.array` objects.
|
`GIF` and `SVG` Image Formats
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
sepia_filterfake_diffusion
|
Demos
|
https://gradio.app/docs/gradio/image
|
Gradio - Image 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 Image component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Image.clear(fn, ···)`| This listener is triggered when the user clears the
Image using the clear button for the component.
`Image.change(fn, ···)`| Triggered when the value of the Image 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.
`Image.stream(fn, ···)`| This listener is triggered when the user streams the
Image.
`Image.select(fn, ···)`| Event listener for when the user selects or deselects
the Image. Uses event data gradio.SelectData to carry `value` referring to the
label of the Image, and `selected` to refer to state of the Image. See
EventData documentation on how to use this event data
`Image.upload(fn, ···)`| This listener is triggered when the user uploads a
file into the Image.
`Image.input(fn, ···)`| This listener is triggered when the user changes the
value of the Image.
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]
|
Event Listeners
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
uld 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 animation on all of the output components.
|
Event Listeners
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
onent | 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
default `= None`
If "once" (default for all events
|
Event Listeners
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
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 | tuple[int | str, ...] | None
default `= None`
|
Event Listeners
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
"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/image
|
Gradio - Image Docs
|
Helper Classes
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
|
gradio.WebcamOptions(···)
Description
A dataclass for specifying options for the webcam tool in the ImageEditor
component. An instance of this class can be passed to the `webcam_options`
parameter of `gr.ImageEditor`.
Initialization
Parameters ▼
mirror: bool
default `= True`
If True, the webcam will be mirrored.
constraints: dict[str, Any] | None
default `= None`
A dictionary of constraints for the webcam.
|
Webcam Options
|
https://gradio.app/docs/gradio/image
|
Gradio - Image Docs
|
Creates a button that can be assigned arbitrary .click() events. The value
(label) of the button can be used as an input to the function (rarely used) or
set via the output of a function.
|
Description
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
**As input component** : (Rarely used) the `str` corresponding to the
button label when the button is clicked
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : string corresponding to the button label
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
Parameters ▼
value: str | I18nData | Callable
default `= "Run"`
default text for the button to display. If a function is provided, the
function will be called each time the app loads to set the initial value of
this component.
every: Timer | float | None
default `= None`
continuously 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.
variant: Literal['primary', 'secondary', 'stop', 'huggingface']
default `= "secondary"`
sets the background and text color of the button. Use 'primary' for main call-
to-action buttons, 'secondary' for a more subdued style, 'stop' for a stop
button, 'huggingface' for a black background with white text, consistent with
Hugging Face's button styles.
size: Literal['sm', 'md', 'lg']
default `= "lg"`
size of the button. Can be "sm", "md", or "lg".
icon: str | Path | None
default `= None`
URL or path to the icon file to display within the button. If None, no icon
will be displayed.
link: str | None
default `= None`
URL to open when the button is clicked. If None, no link will be used.
link_target: Literal['_self', '_blank', '_parent', '_top']
default `= "_self"`
determines where to open the linked URL. "_self" (default, same tab), "_blank"
(new tab), "_parent" (parent frame), "_top" (top frame).
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
in
|
Initialization
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
iteral['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
interactive: bool
default `= True`
if False, the Button will be in a disabled state.
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 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-rendered based on the values
provided during constructor.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen sp
|
Initialization
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
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.
|
Initialization
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Button`| "button"| Uses default values
`gradio.ClearButton`| "clearbutton"| Uses default values
`gradio.DeepLinkButton`| "deeplinkbutton"| Uses default values
`gradio.DuplicateButton`| "duplicatebutton"| Uses default values
`gradio.LoginButton`| "loginbutton"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/button
|
Gradio - Button 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 Button component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Button.click(fn, ···)`| Triggered when the Button is clicked.
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 giv
|
Event Listeners
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
cription: 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 (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 co
|
Event Listeners
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
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: 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.
|
Event Listeners
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
n 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.
|
Event Listeners
|
https://gradio.app/docs/gradio/button
|
Gradio - Button Docs
|
The gr.EditData class is a subclass of gr.Event data that specifically
carries information about the `.edit()` event. When gr.EditData is added as a
type hint to an argument of an event listener method, a gr.EditData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
|
Description
|
https://gradio.app/docs/gradio/editdata
|
Gradio - Editdata Docs
|
import gradio as gr
def edit(edit_data: gr.EditData, history: list[gr.MessageDict]):
history_up_to_edit = history[:edit_data.index]
history_up_to_edit[-1] = edit_data.value
return history_up_to_edit
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.undo(edit, chatbot, chatbot)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/editdata
|
Gradio - Editdata Docs
|
Parameters ▼
index: int | tuple[int, int]
The index of the message that was edited.
previous_value: Any
The previous content of the message that was edited.
value: Any
The new content of the message that was edited.
|
Attributes
|
https://gradio.app/docs/gradio/editdata
|
Gradio - Editdata Docs
|
Gradio includes pre-built components that can be used as inputs or outputs
in your Interface or Blocks with a single line of code. Components include
preprocessing steps that convert user data submitted through browser to
something that be can used by a Python function, and postprocessing steps to
convert values returned by a Python function into something that can be
displayed in a browser.
Consider an example with three inputs (Textbox, Number, and Image) and two
outputs (Number and Gallery), below is a diagram of what our preprocessing
will send to the function and what our postprocessing will require from it.

|
Introduction
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
Components also come with certain events that they support. These are
methods that are triggered with user actions. Below is a table showing which
events are supported for each component. All events are also listed (with
parameters) in the component’s docs.
| copy| pause_recording| clear| upload| release| change| stop_recording| undo|
double_click| preview_open| delete| pause| retry| end| edit| input| submit|
load| expand| like| stream| click| blur| start_recording| stop|
example_select| apply| tick| key_up| download| focus| option_select| select|
preview_close| collapse| play
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---
[AnnotatedImage](annotatedimage)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Audio](audio)| ✕| ✓| ✓| ✓| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✓|
✕| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓
[BrowserState](browserstate)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Button](button)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Chatbot](chatbot)| ✓| ✕| ✓| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕|
✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕| ✕
[Checkbox](checkbox)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[CheckboxGroup](checkboxgroup)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[ClearButton](clearbutton)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Code](code)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕|
✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕
[ColorPicker](colorpicker)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
| ✕| ✕| ✕
[Code](code)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕|
✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕
[ColorPicker](colorpicker)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓|
✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕
[Dataframe](dataframe)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Dataset](dataset)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[DateTime](datetime)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[DeepLinkButton](deeplinkbutton)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Dialogue](dialogue)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[DownloadButton](downloadbutton)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Dropdown](dropdown)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕|
✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✓| ✕| ✕| ✕
[DuplicateButton](duplicatebutton)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[File](file)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✓| ✕| ✕| ✕
[FileExplorer](fileexplorer)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[ImageEditor](imageeditor)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Gallery](gallery)| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕
[HighlightedText](highlightedtext)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕
[HighlightedText](highlightedtext)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[HTML](html)| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✕| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓|
✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✓| ✕| ✓| ✓
[Image](image)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✓|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[ImageSlider](imageslider)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕|
✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[JSON](json)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Label](label)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[LoginButton](loginbutton)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Markdown](markdown)| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Model3D](model3d)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Textbox](textbox)| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕|
✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕
[MultimodalTextbox](multimodaltextbox)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕
[BarPlot](barplot)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[LinePlot](lineplot)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[ScatterPlot](scatterplot)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Navbar](navbar)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
ScatterPlot](scatterplot)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Navbar](navbar)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Number](number)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕| ✕|
✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕
[ParamViewer](paramviewer)| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Plot](plot)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Radio](radio)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕
[Slider](slider)| ✕| ✕| ✕| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[State](state)| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Timer](timer)| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[UploadButton](uploadbutton)| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
[Video](video)| ✕| ✕| ✓| ✓| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✓| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✓
[SimpleImage](simpleimage)| ✕| ✕| ✓| ✓| ✕| ✓| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕|
✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕| ✕
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
Accordion is a layout element which can be toggled to show/hide the
contained content.
|
Description
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
with gr.Accordion("See Details"):
gr.Markdown("lorem ipsum")
|
Example Usage
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
Parameters ▼
label: str | I18nData | None
default `= None`
name of accordion section.
open: bool
default `= True`
if True, accordion 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.
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/accordion
|
Gradio - Accordion Docs
|
Methods
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion 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.Accordion.expand(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion 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 Accordion 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
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
onds 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 an
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
ion 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
de
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.