text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 182
values | source_page_title
stringclasses 182
values |
|---|---|---|---|
unction 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/markdown
|
Gradio - Markdown Docs
|
Creates a textarea for user to enter string input or display string output.
|
Description
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
**As input component** : Passes text value as a `str` into the function.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a `str` returned from function and sets
textarea value to it.
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
Parameters ▼
value: str | I18nData | Callable | None
default `= None`
text to show in textbox. If a function is provided, the function will be
called each time the app loads to set the initial value of this component.
type: Literal['text', 'password', 'email']
default `= "text"`
The type of textbox. One of: 'text' (which allows users to enter any text),
'password' (which masks text entered by the user), 'email' (which suggests
email input to the browser). For "password" and "email" types, `lines` must be
1 and `max_lines` must be None or 1.
lines: int
default `= 1`
minimum number of line rows to provide in textarea.
max_lines: int | None
default `= None`
maximum number of line rows to provide in textarea. Must be at least `lines`.
If not provided, the maximum number of lines is max(lines, 20) for "text"
type, and 1 for "password" and "email" types.
placeholder: str | I18nData | 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.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`
|
Initialization
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
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 the label. If False, the copy button is hidden as well
as well as the 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 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 no
|
Initialization
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
argeting 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 (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
|
Initialization
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
rue. 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.
buttons: list[Literal['copy']] | None
default `= None`
A list of buttons to show for the component. Currently, the only valid option
is "copy". The "copy" button allows the user to copy the text in the textbox.
Only applies if show_label is True. By default, no buttons are shown.
max_length: int | None
default `= None`
maximum number of characters (including newlines) allowed in the textbox. If
None, there is no maximum length.
submit_btn: str | bool | None
default `= False`
If False, will not show a submit button. If True, will show a submit button
with an icon. If a string, will use that string as the submit button text.
When the submit button is shown, the border of the textbox will be removed,
which is useful for creating a chat interface.
stop_btn: str | bool | None
default `= False`
If False, will not show a stop button. If True, will show a stop button with
an icon. If a string, will use that string as the stop button text. When the
stop button is shown, the border of the textbox will be removed, which is
useful for creating a chat interface.
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/textbox
|
Gradio - Textbox Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Textbox`| "textbox"| Uses default values
`gradio.TextArea`| "textarea"| Uses lines=7
|
Shortcuts
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
hello_worlddiff_textssentence_builder
|
Demos
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox 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 Textbox component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Textbox.change(fn, ···)`| Triggered when the value of the Textbox 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.
`Textbox.input(fn, ···)`| This listener is triggered when the user changes the
value of the Textbox.
`Textbox.select(fn, ···)`| Event listener for when the user selects or
deselects the Textbox. Uses event data gradio.SelectData to carry `value`
referring to the label of the Textbox, and `selected` to refer to state of the
Textbox. See EventData documentation on how to use this event data
`Textbox.submit(fn, ···)`| This listener is triggered when the user presses
the Enter key while the Textbox is focused.
`Textbox.focus(fn, ···)`| This listener is triggered when the Textbox is
focused.
`Textbox.blur(fn, ···)`| This listener is triggered when the Textbox is
unfocused/blurred.
`Textbox.stop(fn, ···)`| This listener is triggered when the user reaches the
end of the media playing in the Textbox.
`Textbox.copy(fn, ···)`| This listener is triggered when the user copies
content from the Textbox. Uses event data gradio.CopyData to carry information
about the copied content. See EventData documentation on how to use this event
data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when th
|
Event Listeners
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
a documentation on how to use this event
data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_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 run
|
Event Listeners
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
ess: 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 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_even
|
Event Listeners
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', '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
|
Event Listeners
|
https://gradio.app/docs/gradio/textbox
|
Gradio - Textbox Docs
|
'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/textbox
|
Gradio - Textbox Docs
|
Creates a video component that can be used to upload/record videos (as an
input) or display videos (as an output). For the video to be playable in the
browser it must have a compatible container and codec combination. Allowed
combinations are .mp4 with h264 codec, .ogg with theora codec, and .webm with
vp9 codec. If the component detects that the output video would not be
playable in the browser it will attempt to convert it to a playable mp4 video.
If the conversion fails, the original video is returned.
|
Description
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
**As input component** : Passes the uploaded video as a `str` filepath or
URL whose extension can be modified by `format`.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a `str` or `pathlib.Path` filepath to a video which is displayed, or a `Tuple[str | pathlib.Path, str | pathlib.Path | None]` where the first element is a filepath to a video and the second element is an optional filepath to a subtitle file.
Your function should return one of these types:
def predict(···) -> str | Path | tuple[str | Path, str | Path | None] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
Parameters ▼
value: str | Path | Callable | None
default `= None`
path or URL for the default value that Video component is going to take. Or
can be callable, in which case the function will be called whenever the app
loads to set the initial value of the component.
format: str | None
default `= None`
the file extension with which to save video, such as 'avi' or 'mp4'. This
parameter applies both when this component is used as an input to determine
which file format to convert user-provided video to, and when this component
is used as an output to determine the format of video returned to the user. If
None, no file format conversion is done and the video is kept as is. Use 'mp4'
to ensure browser playability.
sources: list[Literal['upload', 'webcam']] | Literal['upload', 'webcam'] | None
default `= None`
list of sources permitted for video. "upload" creates a box where user can
drop a video file, "webcam" allows user to record a video from their webcam.
If None, defaults to both ["upload, "webcam"].
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 video
file, but will affect the displayed video.
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 video
file, but will affect the displayed video.
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 reca
|
Initialization
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
nd
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.
interactive: bool | None
default `= None`
if True, will allow users to upload a video; if False, can only be used to
display videos. 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 i
|
Initialization
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
e 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.
webcam_options: WebcamOptions | None
default `= None`
A `gr.WebcamOptions` instance that allows developers to specify custom media
constraints for the webcam stream. This parameter provides flexibility to
control the video stream's properties, such as resolution and front or rear
camera on mobile devices. See $demo/webcam_constraints
include_audio: bool | None
default `= None`
whether the component should record/retain the audio track for a video. By
default, audio is excluded for webcam videos and included for uploaded videos.
autoplay: bool
d
|
Initialization
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
lt `= None`
whether the component should record/retain the audio track for a video. By
default, audio is excluded for webcam videos and included for uploaded videos.
autoplay: bool
default `= False`
whether to automatically play the video when the component is used as an
output. Note: browsers will not autoplay video files if the user has not
interacted with the page yet.
buttons: list[Literal['download', 'share']] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "download" and "share". The "download" button allows the user to
save the video to their device. The "share" button allows the user to share
the video via Hugging Face Spaces Discussions. By default, no buttons are
shown if the component is interactive and both buttons are shown if the
component is not interactive.
loop: bool
default `= False`
if True, the video will loop when it reaches the end and continue playing from
the beginning.
streaming: bool
default `= False`
when used set as an output, takes video chunks yielded from the backend and
combines them into one streaming video output. Each chunk should be a video
file with a .ts extension using an h.264 encoding. Mp4 files are also accepted
but they will be converted to h.264 encoding.
watermark: WatermarkOptions | None
default `= None`
A `gr.WatermarkOptions` instance that includes an image file and position to
be used as a watermark on the video. The image is not scaled and is displayed
on the provided position on the video. Valid formats for the image are: jpeg,
png.
subtitles: str | Path | list[dict[str, Any]] | None
default `= None`
A subtitle file (srt, vtt, or json) for the video, or a list of subtitle
dictionaries in the format [{"text": str, "timestamp": [start, end]}] where
timestamps are in seconds. JSON files should contain an array of subtitle
objects.
|
Initialization
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
r a list of subtitle
dictionaries in the format [{"text": str, "timestamp": [start, end]}] where
timestamps are in seconds. JSON files should contain an array of subtitle
objects.
|
Initialization
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Video`| "video"| Uses default values
`gradio.PlayableVideo`| "playablevideo"| Uses format="mp4"
|
Shortcuts
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
video_identity_2
|
Demos
|
https://gradio.app/docs/gradio/video
|
Gradio - Video 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 Video component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Video.change(fn, ···)`| Triggered when the value of the Video 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.
`Video.clear(fn, ···)`| This listener is triggered when the user clears the
Video using the clear button for the component.
`Video.start_recording(fn, ···)`| This listener is triggered when the user
starts recording with the Video.
`Video.stop_recording(fn, ···)`| This listener is triggered when the user
stops recording with the Video.
`Video.stop(fn, ···)`| This listener is triggered when the user reaches the
end of the media playing in the Video.
`Video.play(fn, ···)`| This listener is triggered when the user plays the
media in the Video.
`Video.pause(fn, ···)`| This listener is triggered when the media in the Video
stops for any reason.
`Video.end(fn, ···)`| This listener is triggered when the user reaches the end
of the media playing in the Video.
`Video.upload(fn, ···)`| This listener is triggered when the user uploads a
file into the Video.
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 v
|
Event Listeners
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Componen
|
Event Listeners
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
s well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that ar
|
Event Listeners
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
|
Event Listeners
|
https://gradio.app/docs/gradio/video
|
Gradio - Video Docs
|
PI 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/video
|
Gradio - Video Docs
|
Helper Classes
|
https://gradio.app/docs/gradio/video
|
Gradio - Video 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/video
|
Gradio - Video Docs
|
Validates that the audio length is within the specified min and max length (in
seconds). You can use this to construct a validator that will check if the
user-provided audio is either too short or too long.
import gradio as gr
demo = gr.Interface(
lambda x: x,
inputs="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
|
This function allows you to pass custom warning messages to the user. You
can do so simply by writing `gr.Warning('message here')` in your function, and
when that line is executed the custom message will appear in a modal on the
demo. The modal is yellow by default and has the heading: "Warning." Queue
must be enabled for this behavior; otherwise, the warning will be printed to
the console using the `warnings` library.
|
Description
|
https://gradio.app/docs/gradio/warning
|
Gradio - Warning Docs
|
import gradio as gr
def hello_world():
gr.Warning('This is a warning message.')
return "hello world"
with gr.Blocks() as demo:
md = gr.Markdown()
demo.load(hello_world, inputs=None, outputs=[md])
demo.queue().launch()
|
Example Usage
|
https://gradio.app/docs/gradio/warning
|
Gradio - Warning Docs
|
Parameters ▼
message: str
default `= "Warning issued."`
The warning message to be displayed to the user. Can be HTML, which will be
rendered in the modal.
duration: float | None
default `= 10`
The duration in seconds that the warning message should be displayed for. If
None or 0, the message will be displayed indefinitely until the user closes
it.
visible: bool
default `= True`
Whether the error message should be displayed in the UI.
title: str
default `= "Warning"`
The title to be displayed to the user at the top of the modal.
|
Initialization
|
https://gradio.app/docs/gradio/warning
|
Gradio - Warning Docs
|
blocks_chained_events
|
Demos
|
https://gradio.app/docs/gradio/warning
|
Gradio - Warning Docs
|
Creates a chatbot that displays user-submitted messages and responses.
Supports a subset of Markdown including bold, italics, code, tables. Also
supports audio/video/image files, which are displayed in the Chatbot, and
other kinds of files which are displayed as links. This component is usually
used as an output component.
|
Description
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
The data format accepted by the Chatbot is dictated by the `type` parameter.
This parameter can take two values, `'tuples'` and `'messages'`. The
`'tuples'` type is deprecated and will be removed in a future version of
Gradio.
|
Behavior
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
If the `type` is `'messages'`, then the data sent to/from the chatbot will be
a list of dictionaries with `role` and `content` keys. This format is
compliant with the format expected by most LLM APIs (HuggingChat, OpenAI,
Claude). The `role` key is either `'user'` or `'assistant'` and the `content`
key can be one of the following should be a string (rendered as markdown/html)
or a Gradio component (useful for displaying files).
As an example:
import gradio as gr
history = [
{"role": "assistant", "content": "I am happy to provide you that report and plot."},
{"role": "assistant", "content": gr.Plot(value=make_plot_from_file('quaterly_sales.txt'))}
]
with gr.Blocks() as demo:
gr.Chatbot(history, type="messages")
demo.launch()
For convenience, you can use the `ChatMessage` dataclass so that your text
editor can give you autocomplete hints and typechecks.
import gradio as gr
history = [
gr.ChatMessage(role="assistant", content="How can I help you?"),
gr.ChatMessage(role="user", content="Can you make me a plot of quarterly sales?"),
gr.ChatMessage(role="assistant", content="I am happy to provide you that report and plot.")
]
with gr.Blocks() as demo:
gr.Chatbot(history, type="messages")
demo.launch()
|
Message format
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
Parameters ▼
value: list[MessageDict | Message] | Callable | None
default `= None`
Default list of messages to show in chatbot, where each message is of the
format {"role": "user", "content": "Help me."}. Role can be one of "user",
"assistant", or "system". Content should be either text, or media passed as a
Gradio component, e.g. {"content": gr.Image("lion.jpg")}. 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. 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 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
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
ide
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.
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.
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.
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 hav
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
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.
height: int | str | None
default `= 400`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. If messages exceed the height, the component
will scroll.
resizable: bool
default `= False`
If True, the user of the Gradio app can resize the chatbot by dragging the
bottom right corner.
max_height: int | str | None
default `= None`
The maximum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If messages exceed the height,
the component will scroll. If messages are shorter than the height, the
component 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 component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If messages exceed the height,
the component will expand to fit the content. Will not have any effect if
`height` is set and is larger than `min_height`.
editable: Literal['user', 'all'] | None
default `= None`
Allows user to edit messages in the chatbot. If set to "user", allows editing
of user messages. If set to "all", allows editing of assistant messages as
well.
latex_delimiters: list[dict[str, str | bool]] | None
default `= None`
A list of dicts of the form {"left": open delimiter (str), "right": close
delimiter (str), "display": whether to display in newline (bool)} that will be
used to render LaTeX expressions. If not provided, `latex_delimiters` is set
to `[{ "
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
pen delimiter (str), "right": close
delimiter (str), "display": whether to display in newline (bool)} that will be
used to render LaTeX expressions. If not provided, `latex_delimiters` is set
to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions
enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass
in an empty list to disable LaTeX rendering. For more information, see the
[KaTeX documentation](https://katex.org/docs/autorender.html).
rtl: bool
default `= False`
If True, sets the direction of the rendered text to right-to-left. Default is
False, which renders text left-to-right.
buttons: list[Literal['share', 'copy', 'copy_all']] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "share", "copy", and "copy_all". The "share" button allows the
user to share outputs to Hugging Face Spaces Discussions. The "copy" button
makes a copy button appear next to each individual chatbot message. The
"copy_all" button appears at the component level and allows the user to copy
all chatbot messages. By default, "share" and "copy_all" buttons are shown.
watermark: str | None
default `= None`
If provided, this text will be appended to the end of messages copied from the
chatbot, after a blank line. Useful for indicating that the message is
generated by an AI model.
avatar_images: tuple[str | Path | None, str | Path | None] | None
default `= None`
Tuple of two avatar image paths or URLs for user and bot (in that order). Pass
None for either the user or bot image to skip. Must be within the working
directory of the Gradio app or an external URL.
sanitize_html: bool
default `= True`
If False, will disable HTML sanitization for chatbot messages. This is not
recommended, as it can lead to security vulnerabilities.
render_markdown: bool
default `= True`
If False, will disable Markd
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
sable HTML sanitization for chatbot messages. This is not
recommended, as it can lead to security vulnerabilities.
render_markdown: bool
default `= True`
If False, will disable Markdown rendering for chatbot messages.
feedback_options: list[str] | tuple[str, ...] | None
default `= ('Like', 'Dislike')`
A list of strings representing the feedback options that will be displayed to
the user. The exact case-sensitive strings "Like" and "Dislike" will render as
thumb icons, but any other choices will appear under a separate flag icon.
feedback_value: list[str | None] | None
default `= None`
A list of strings representing the feedback state for entire chat. Only works
when type="messages". Each entry in the list corresponds to that assistant
message, in order, and the value is the feedback given (e.g. "Like",
"Dislike", or any custom feedback option) or None if no feedback was given for
that message.
line_breaks: bool
default `= True`
If True (default), will enable Github-flavored Markdown line breaks in chatbot
messages. If False, single new lines will be ignored. Only applies if
`render_markdown` is True.
layout: Literal['panel', 'bubble'] | None
default `= None`
If "panel", will display the chatbot in a llm style layout. If "bubble", will
display the chatbot with message bubbles, with the user and bot messages on
alterating sides. Will default to "bubble".
placeholder: str | None
default `= None`
a placeholder message to display in the chatbot when it is empty. Centered
vertically and horizontally in the Chatbot. Supports Markdown and HTML. If
None, no placeholder is displayed.
examples: list[ExampleMessage] | None
default `= None`
A list of example messages to display in the chatbot before any user/assistant
messages are shown. Each example should be a dictionary with an optional
"text" key representing the message that should be populated in th
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
messages to display in the chatbot before any user/assistant
messages are shown. Each example should be a dictionary with an optional
"text" key representing the message that should be populated in the Chatbot
when clicked, an optional "files" key, whose value should be a list of files
to populate in the Chatbot, an optional "icon" key, whose value should be a
filepath or URL to an image to display in the example box, and an optional
"display_text" key, whose value should be the text to display in the example
box. If "display_text" is not provided, the value of "text" will be displayed.
allow_file_downloads: <class 'inspect._empty'>
default `= True`
If True, will show a download button for chatbot messages that contain media.
Defaults to True.
group_consecutive_messages: bool
default `= True`
If True, will display consecutive messages from the same role in the same
bubble. If False, will display each message in a separate bubble. Defaults to
True.
allow_tags: list[str] | bool
default `= True`
If a list of tags is provided, these tags will be preserved in the output
chatbot messages, even if `sanitize_html` is `True`. For example, if this list
is ["thinking"], the tags `<thinking>` and `</thinking>` will not be removed.
If True, all custom tags (non-standard HTML tags) will be preserved. If False,
no tags will be preserved. Default value is 'True'.
reasoning_tags: list[tuple[str, str]] | None
default `= None`
If provided, a list of tuples of (open_tag, close_tag) strings. Any text
between these tags will be extracted and displayed in a separate collapsible
message with metadata={"title": "Reasoning"}. For example, [("<thinking>",
"</thinking>")] will extract content between <thinking> and </thinking> tags.
Each thinking block will be displayed as a separate collapsible message before
the main response. If None (default), no automatic extraction is performed.
like_user_message: boo
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
tags.
Each thinking block will be displayed as a separate collapsible message before
the main response. If None (default), no automatic extraction is performed.
like_user_message: bool
default `= False`
If True, will show like/dislike buttons for user messages as well. Defaults to
False.
|
Initialization
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Chatbot`| "chatbot"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
**Displaying Thoughts/Tool Usage**
When `type` is `messages`, you can provide additional metadata regarding any
tools used to generate the response. This is useful for displaying the thought
process of LLM agents. For example,
def generate_response(history):
history.append(
ChatMessage(role="assistant",
content="The weather API says it is 20 degrees Celcius in New York.",
metadata={"title": "🛠️ Used tool Weather API"})
)
return history
Would be displayed as following:

You can also specify metadata with a plain python dictionary,
def generate_response(history):
history.append(
dict(role="assistant",
content="The weather API says it is 20 degrees Celcius in New York.",
metadata={"title": "🛠️ Used tool Weather API"})
)
return history
**Using Gradio Components Inside`gr.Chatbot`**
The `Chatbot` component supports using many of the core Gradio components
(such as `gr.Image`, `gr.Plot`, `gr.Audio`, and `gr.HTML`) inside of the
chatbot. Simply include one of these components in your list of tuples. Here’s
an example:
import gradio as gr
def load():
return [
("Here's an audio", gr.Audio("https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/audio/audio_sample.wav")),
("Here's an video", gr.Video("https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/videos/world.mp4"))
]
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
button = gr.Button("Load audio and video")
button.click(load, None, chatbot)
demo.launch()
|
Examples
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
chatbot_simplechatbot_streamingchatbot_with_toolschatbot_core_components
|
Demos
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot 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 Chatbot component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Chatbot.change(fn, ···)`| Triggered when the value of the Chatbot 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.
`Chatbot.select(fn, ···)`| Event listener for when the user selects or
deselects the Chatbot. Uses event data gradio.SelectData to carry `value`
referring to the label of the Chatbot, and `selected` to refer to state of the
Chatbot. See EventData documentation on how to use this event data
`Chatbot.like(fn, ···)`| This listener is triggered when the user
likes/dislikes from within the Chatbot. This event has EventData of type
gradio.LikeData that carries information, accessible through LikeData.index
and LikeData.value. See EventData documentation on how to use this event data.
`Chatbot.retry(fn, ···)`| This listener is triggered when the user clicks the
retry button in the chatbot message.
`Chatbot.undo(fn, ···)`| This listener is triggered when the user clicks the
undo button in the chatbot message.
`Chatbot.example_select(fn, ···)`| This listener is triggered when the user
clicks on an example from within the Chatbot. This event has SelectData of
type gradio.SelectData that carries information, accessible through
SelectData.index and SelectData.value. See SelectData documentation on how to
use this event data.
`Chatbot.option_select(fn, ···)`| This listener is triggered when
|
Event Listeners
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
s information, accessible through
SelectData.index and SelectData.value. See SelectData documentation on how to
use this event data.
`Chatbot.option_select(fn, ···)`| This listener is triggered when the user
clicks on an option from within the Chatbot. This event has SelectData of type
gradio.SelectData that carries information, accessible through
SelectData.index and SelectData.value. See SelectData documentation on how to
use this event data.
`Chatbot.clear(fn, ···)`| This listener is triggered when the user clears the
Chatbot using the clear button for the component.
`Chatbot.copy(fn, ···)`| This listener is triggered when the user copies
content from the Chatbot. Uses event data gradio.CopyData to carry information
about the copied content. See EventData documentation on how to use this event
data
`Chatbot.edit(fn, ···)`| This listener is triggered when the user edits the
Chatbot (e.g. image) using the built-in editor.
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 strin
|
Event Listeners
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
e 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 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
*re
|
Event Listeners
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
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 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.
|
Event Listeners
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
fault `= 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 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 inpu
|
Event Listeners
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
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/chatbot
|
Gradio - Chatbot Docs
|
Helper Classes
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
|
gradio.ChatMessage(···)
Description
A dataclass that represents a message in the Chatbot component (with
type="messages"). The only required field is `content`. The value of
`gr.Chatbot` is a list of these dataclasses.
Parameters ▼
content: MessageContent | list[MessageContent]
The content of the message. Can be a string, a file dict, a gradio component,
or a list of these types to group these messages together.
role: Literal['user', 'assistant', 'system']
default `= "assistant"`
The role of the message, which determines the alignment of the message in the
chatbot. Can be "user", "assistant", or "system". Defaults to "assistant".
metadata: MetadataDict
default `= _HAS_DEFAULT_FACTORY_CLASS()`
The metadata of the message, which is used to display intermediate thoughts /
tool usage. Should be a dictionary with the following keys: "title" (required
to display the thought), and optionally: "id" and "parent_id" (to nest
thoughts), "duration" (to display the duration of the thought), "status" (to
display the status of the thought).
options: list[OptionDict]
default `= _HAS_DEFAULT_FACTORY_CLASS()`
The options of the message. A list of Option objects, which are dictionaries
with the following keys: "label" (the text to display in the option), and
optionally "value" (the value to return when the option is selected if
different from the label).
|
ChatMessage
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
A typed dictionary to represent metadata for a message in the Chatbot
component. An instance of this dictionary is used for the `metadata` field in
a ChatMessage when the chat message should be displayed as a thought.
Keys ▼
title: str
The title of the 'thought' message. Only required field.
id: int | str
The ID of the message. Only used for nested thoughts. Nested thoughts can be
nested by setting the parent_id to the id of the parent thought.
parent_id: int | str
The ID of the parent message. Only used for nested thoughts.
log: str
A string message to display next to the thought title in a subdued font.
duration: float
The duration of the message in seconds. Appears next to the thought title in a
subdued font inside a parentheses.
status: Literal['pending', 'done']
if set to `'pending'`, a spinner appears next to the thought title and the
accordion is initialized open. If `status` is `'done'`, the thought accordion
is initialized closed. If `status` is not provided, the thought accordion is
initialized open and no spinner is displayed.
|
MetadataDict
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
A typed dictionary to represent an option in a ChatMessage. A list of these
dictionaries is used for the `options` field in a ChatMessage.
Keys ▼
value: str
The value to return when the option is selected.
label: str
The text to display in the option, if different from the value.
|
OptionDict
|
https://gradio.app/docs/gradio/chatbot
|
Gradio - Chatbot Docs
|
The gr.LikeData class is a subclass of gr.EventData that specifically
carries information about the `.like()` event. When gr.LikeData is added as a
type hint to an argument of an event listener method, a gr.LikeData 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/likedata
|
Gradio - Likedata Docs
|
import gradio as gr
def test(value, like_data: gr.LikeData):
return {
"chatbot_value": value,
"liked_message": like_data.value,
"liked_index": like_data.index,
"liked_or_disliked_as_bool": like_data.liked
}
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def")])
t = gr.JSON()
c.like(test, c, t)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
Parameters ▼
index: int | tuple[int, int]
The index of the liked/disliked item. Is a tuple if the component is two
dimensional.
value: Any
The value of the liked/disliked item.
liked: bool
True if the item was liked, False if disliked, or string value if any other
feedback.
|
Attributes
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
chatbot_core_components_simple
|
Demos
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
Creates a set of (string or numeric type) radio buttons of which only one
can be selected.
|
Description
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
**As input component** : Passes the value of the selected radio button as a `str | int | float`, or its index as an `int` into the function, depending on `type`.
Your function should accept one of these types:
def predict(
value: str | int | float | None
)
...
**As output component** : Expects a `str | int | float` corresponding to the value of the radio button to be selected
Your function should return one of these types:
def predict(···) -> str | int | float | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
Parameters ▼
choices: list[str | int | float | tuple[str, str | int | float]] | None
default `= None`
A list of string or numeric options to select from. An option can also be a
tuple of the form (name, value), where name is the displayed name of the radio
button and value is the value to be passed to the function, or returned by the
function.
value: str | int | float | Callable | None
default `= None`
The option selected by default. If None, no option is selected by default. If
a function is provided, the function will be called each time the app loads to
set the initial value of this component.
type: Literal['value', 'index']
default `= "value"`
Type of value to be returned by component. "value" returns the string of the
choice selected, "index" returns the index of the choice selected.
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.
|
Initialization
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
Relative width compared to adjacent Components in a Row. For example, if
Component A has scale=2, and Component B has scale=1, A will be twice as wide
as B. Should be an integer.
min_width: int
default `= 160`
Minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
If True, choices in this radio group will be selectable; if False, selection
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, Compon
|
Initialization
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
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.
rtl: bool
default `= False`
If True, the radio buttons will be displayed in right-to-left order. Default
is False.
|
Initialization
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Radio`| "radio"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
sentence_builderblocks_essay
|
Demos
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio 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 Radio component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Radio.select(fn, ···)`| Event listener for when the user selects or deselects
the Radio. Uses event data gradio.SelectData to carry `value` referring to the
label of the Radio, and `selected` to refer to state of the Radio. See
EventData documentation on how to use this event data
`Radio.change(fn, ···)`| Triggered when the value of the Radio 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.
`Radio.input(fn, ···)`| This listener is triggered when the user changes the
value of the Radio.
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 o
|
Event Listeners
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
ction 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 gradio app.
batch: bool
default `= False`
If True,
|
Event Listeners
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
ed.
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 submission after the
pending event is complete.
js: str |
|
Event Listeners
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
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 validation function to run before the main function. If provided,
this functi
|
Event Listeners
|
https://gradio.app/docs/gradio/radio
|
Gradio - Radio Docs
|
ntical 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/radio
|
Gradio - Radio Docs
|
Button that clears the value of a component or a list of components when
clicked. It is instantiated with the list of components to clear.
|
Description
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton 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/clearbutton
|
Gradio - Clearbutton Docs
|
Parameters ▼
components: None | list[Component] | Component
default `= None`
value: str
default `= "Clear"`
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']
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.
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
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 o
|
Initialization
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton Docs
|
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 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.
api_name: str
|
Initialization
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton Docs
|
ent 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.
api_name: str | None
default `= None`
api_visibility: Literal['public', 'private', 'undocumented']
default `= "undocumented"`
|
Initialization
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.ClearButton`| "clearbutton"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton 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 ClearButton component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`ClearButton.add(fn, ···)`| Adds a component or list of components to the list
of components that will be cleared when the button is clicked.
`ClearButton.click(fn, ···)`| Triggered when the Button is clicked.
Event Parameters
Parameters ▼
components: None | Component | list[Component]
|
Event Listeners
|
https://gradio.app/docs/gradio/clearbutton
|
Gradio - Clearbutton Docs
|
The gr.DownloadData class is a subclass of gr.EventData that specifically
carries information about the `.download()` event. When gr.DownloadData is
added as a type hint to an argument of an event listener method, a
gr.DownloadData 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/downloaddata
|
Gradio - Downloaddata Docs
|
import gradio as gr
def on_download(download_data: gr.DownloadData):
return f"Downloaded file: {download_data.file.path}"
with gr.Blocks() as demo:
files = gr.File()
textbox = gr.Textbox()
files.download(on_download, None, textbox)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/downloaddata
|
Gradio - Downloaddata Docs
|
Parameters ▼
file: FileData
The file that was downloaded, as a FileData object.
|
Attributes
|
https://gradio.app/docs/gradio/downloaddata
|
Gradio - Downloaddata Docs
|
Component to select a date and (optionally) a time.
|
Description
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
**As input component** : Passes text value as a `str` into the function.
Your function should accept one of these types:
def predict(
value: float | datetime | str | None
)
...
**As output component** : Expects a tuple pair of datetimes.
Your function should return one of these types:
def predict(···) -> float | datetime | str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
Parameters ▼
value: float | str | datetime | None
default `= None`
default value for datetime.
include_time: bool
default `= True`
If True, the component will include time selection. If False, only date
selection will be available.
type: Literal['timestamp', 'datetime', 'string']
default `= "timestamp"`
The type of the value. Can be "timestamp", "datetime", or "string". If
"timestamp", the value will be a number representing the start and end date in
seconds since epoch. If "datetime", the value will be a datetime object. If
"string", the value will be the date entered by the user.
timezone: str | None
default `= None`
The timezone to use for timestamps, such as "US/Pacific" or "Europe/Paris". If
None, the timezone will be the local timezone.
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.
show_label: bool | None
default `= None`
if True, will display label.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: float | None
default `= None`
If `value` is a callable, run the function 'every' number of seconds while the
client connection is open. Has no effect otherwise. The event can be accessed
(e.g. to cancel it) via this component's .load_event attribute.
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 B
|
Initialization
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
nents. 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.
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
interactive: bool | None
default `= None`
elem_id: str | None
default `= None`
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/datetime
|
Gradio - Datetime Docs
|
y 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/datetime
|
Gradio - Datetime Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.DateTime`| "datetime"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime 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 DateTime component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`DateTime.change(fn, ···)`| Triggered when the value of the DateTime 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.
`DateTime.submit(fn, ···)`| This listener is triggered when the user presses
the Enter key while the DateTime is focused.
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 str
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
ion 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 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
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
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 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_l
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
rontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
y 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/datetime
|
Gradio - Datetime 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/imageslider
|
Gradio - Imageslider Docs
|
**As input component** : Passes the uploaded image as a tuple of
`numpy.array`, `PIL.Image` or `str` filepath depending on `type`.
Your function should accept one of these types:
def predict(
value: tuple[
str | PIL.Image.Image | np.ndarray | None, str | PIL.Image.Image | np.ndarray | None
]
)
...
**As output component** : Expects a tuple of `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/imageslider
|
Gradio - Imageslider Docs
|
Parameters ▼
value: image_tuple | Callable | None
default `= None`
A tuple of PIL Image, numpy array, path or URL for the default value that
ImageSlider component is going to take, this pair of images should be of equal
size. 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 tuple
of 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 tuple
of 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 types (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The for
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
image_mode will be inferred
from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The format the images are converted to before being passed into the prediction
function. "numpy" converts the images to numpy arrays with shape (height,
width, 3) and values from 0 to 255, "pil" converts the images to PIL image
objects, "filepath" passes str paths to temporary files containing the images.
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 | 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 display label.
buttons: list[Literal['download', 'fullscreen']] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "download" and "fullscreen". The "download" button allows the user
to download the image. The "fullscreen" button allows the user to view the
image in fullscreen mode. By default, all buttons are shown.
container: bool
default `= True`
If T
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
the user
to download the image. The "fullscreen" button allows the user to view the
image 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
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,
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.