text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 183
values | source_page_title
stringclasses 183
values |
|---|---|---|---|
enerators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
one, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Accordion.collapse(···)
Description
%20Copyright%202022%20Fonticons,%20In
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Accordion is collapsed.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Compon
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
esponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
mation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
r 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".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int |
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
s 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.
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Accordion.expand(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Accordion is expanded.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
onds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress an
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
ion at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
de
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
enerators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
one, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
expand
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Accordion.collapse(···)
Description
%20Copyright%202022%20Fonticons,%20In
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Accordion is collapsed.
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Compon
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
esponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
mation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
r 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".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int |
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
s 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.
|
collapse
|
https://gradio.app/docs/gradio/accordion
|
Gradio - Accordion Docs
|
Creates a numeric field for user to enter numbers as input or display
numeric output.
|
Description
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
**As input component** : Passes field value as a `float` or `int` into the
function, depending on `precision`.
Your function should accept one of these types:
def predict(
value: float | int | None
)
...
**As output component** : Expects an `int` or `float` returned from the
function and sets field value to it.
Your function should return one of these types:
def predict(···) -> float | int | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
Parameters ▼
value: float | Callable | None
default `= None`
default value. If None, the component will be empty and show the `placeholder`
if is set. If no `placeholder` is set, the component will show 0. If a
function is provided, the function will be called each time the app loads to
set the initial value of this component.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
placeholder: str | I18nData | None
default `= None`
placeholder hint to provide behind number input.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applie
|
Initialization
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
`
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 editable; if False, editing will be disabled. If not
provided, this is inferred based on whether the component is used as an input
or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
funct
|
Initialization
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
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.
precision: int | None
default `= None`
Precision to round input/output to. If set to 0, will round to nearest integer
and convert type to int. If None, no rounding happens.
minimum: float | None
default `= None`
Minimum value. Only applied when component is used as an input. If a user
provides a smaller value, a gr.Error exception is raised by the backend.
maximum: float | None
default `= None`
Maximum value. Only applied when component is used as an input. If a user
provides a larger value, a gr.Error exception is raised by the backend.
step: float
default `= 1`
The interval between allowed numbers in the component. Can be used along with
optional parameters `minimum` and `maximum` to create a range of legal values
starting from `minimum` and incrementing according to this parameter.
|
Initialization
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Number`| "number"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
tax_calculatorblocks_simple_squares
|
Demos
|
https://gradio.app/docs/gradio/number
|
Gradio - Number 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 Number component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Number.change(fn, ···)`| Triggered when the value of the Number 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.
`Number.input(fn, ···)`| This listener is triggered when the user changes the
value of the Number.
`Number.submit(fn, ···)`| This listener is triggered when the user presses the
Enter key while the Number is focused.
`Number.focus(fn, ···)`| This listener is triggered when the Number is
focused.
`Number.blur(fn, ···)`| This listener is triggered when the Number is
unfocused/blurred.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `=
|
Event Listeners
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
s. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= Fals
|
Event Listeners
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
as been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
|
Event Listeners
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided
|
Event Listeners
|
https://gradio.app/docs/gradio/number
|
Gradio - Number Docs
|
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/number
|
Gradio - Number Docs
|
Creates a dropdown of choices from which a single entry or multiple entries
can be selected (as an input component) or displayed (as an output component).
|
Description
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
**As input component** : Passes the value of the selected dropdown choice as a `str | int | float` or its index as an `int` into the function, depending on `type`. Or, if `multiselect` is True, passes the values of the selected dropdown choices as a list of corresponding values/indices instead.
Your function should accept one of these types:
def predict(
value: str | int | float | list[str | int | float] | list[int | None] | None
)
...
**As output component** : Expects a `str | int | float` corresponding to the value of the dropdown entry to be selected. Or, if `multiselect` is True, expects a `list` of values corresponding to the selected dropdown entries.
Your function should return one of these types:
def predict(···) -> str | int | float | list[str | int | float] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
Parameters ▼
choices: list[str | int | float | tuple[str, str | int | float]] | None
default `= None`
a list of string or numeric options to choose from. An option can also be a
tuple of the form (name, value), where name is the displayed name of the
dropdown choice and value is the value to be passed to the function, or
returned by the function.
value: str | int | float | list[str | int | float] | Callable | DefaultValue | None
default `= DefaultValue()`
the value selected in dropdown. If `multiselect` is true, this should be list,
otherwise a single string or number from among `choices`. By default, the
first choice in `choices` is initally selected. If set explicitly to None, no
value is initally selected. 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.
multiselect: bool | None
default `= None`
if True, multiple choices can be selected.
allow_custom_value: bool
default `= False`
if True, allows user to enter a custom value that is not in the list of
choices.
max_choices: int | None
default `= None`
maximum number of choices that can be selected. If None, no limit is enforced.
filterable: bool
default `= True`
if True, user will be able to type into the dropdown and filter the choices by
typing. Can only be set to False if `allow_custom_value` is False.
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 compon
|
Initialization
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
`show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: Timer | float | None
default `= None`
continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
if True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, choices in this dropdown 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.
|
Initialization
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
ne`
if True, choices in this dropdown 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 be rendered in the Blocks context. Should be used
if the intention is to assign event listeners now but render the component
later.
key: int | str | tuple[int | str, ...] | None
default `= None`
preserved_by_key: list[str] | str | None
default `= "value"`
|
Initialization
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Dropdown`| "dropdown"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
sentence_builder
|
Demos
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown 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 Dropdown component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Dropdown.change(fn, ···)`| Triggered when the value of the Dropdown 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.
`Dropdown.input(fn, ···)`| This listener is triggered when the user changes
the value of the Dropdown.
`Dropdown.select(fn, ···)`| Event listener for when the user selects or
deselects the Dropdown. Uses event data gradio.SelectData to carry `value`
referring to the label of the Dropdown, and `selected` to refer to state of
the Dropdown. See EventData documentation on how to use this event data
`Dropdown.focus(fn, ···)`| This listener is triggered when the Dropdown is
focused.
`Dropdown.blur(fn, ···)`| This listener is triggered when the Dropdown is
unfocused/blurred.
`Dropdown.key_up(fn, ···)`| This listener is triggered when the user presses a
key while the Dropdown 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 | Bl
|
Event Listeners
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output componen
|
Event Listeners
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
ess_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default fo
|
Event Listeners
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
defa
|
Event Listeners
|
https://gradio.app/docs/gradio/dropdown
|
Gradio - Dropdown Docs
|
y 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/dropdown
|
Gradio - Dropdown Docs
|
This component displays a table of value spreadsheet-like component. Can be
used to display data as an output component, or as an input to collect data
from the user.
|
Description
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
**As input component** : Passes the uploaded spreadsheet data as a
`pandas.DataFrame`, `numpy.array`, `polars.DataFrame`, or native 2D Python
`list[list]` depending on `type`
Your function should accept one of these types:
def predict(
value: pd.DataFrame | np.ndarray | pl.DataFrame | list[list]
)
...
**As output component** : Expects data in any of these formats:
`pandas.DataFrame`, `pandas.Styler`, `numpy.array`, `polars.DataFrame`,
`list[list]`, `list`, or a `dict` with keys 'data' (and optionally 'headers'),
or `str` path to a csv, which is rendered as the spreadsheet.
Your function should return one of these types:
def predict(···) -> pd.DataFrame | Styler | np.ndarray | pl.DataFrame | list | list[list] | dict | str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
Parameters ▼
value: pd.DataFrame | Styler | np.ndarray | pl.DataFrame | list | list[list] | dict | str | Callable | None
default `= None`
Default value to display in the DataFrame. Supports pandas, numpy, polars, and
list of lists. If a Styler is provided, it will be used to set the displayed
value in the DataFrame (e.g. to set precision of numbers) if the `interactive`
is False. If a Callable function is provided, the function will be called
whenever the app loads to set the initial value of the component.
headers: list[str] | None
default `= None`
List of str header names. These are used to set the column headers of the
dataframe if the value does not have headers. If None, no headers are shown.
row_count: int | None
default `= None`
The number of rows to initially display in the dataframe. If None, the number
of rows is determined automatically based on the `value`.
row_limits: tuple[int | None, int | None] | None
default `= None`
A tuple of two integers specifying the minimum and maximum number of rows that
can be created in the dataframe via the UI. If the first element is None,
there is no minimum number of rows. If the second element is None, there is no
maximum number of rows. Only applies if `interactive` is True.
col_count: None
default `= None`
This parameter is deprecated. Please use `column_count` instead.
column_count: int | None
default `= None`
The number of columns to initially display in the dataframe. If None, the
number of columns is determined automatically based on the `value`.
column_limits: tuple[int | None, int | None] | None
default `= None`
A tuple of two integers specifying the minimum and maximum number of columns
that can be created in the dataframe via the UI. If the first element is None,
there is no minimum number of columns. If the second element is None, there is
no maximum number of columns. Only applies if
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
t can be created in the dataframe via the UI. If the first element is None,
there is no minimum number of columns. If the second element is None, there is
no maximum number of columns. Only applies if `interactive` is True.
datatype: Literal['str', 'number', 'bool', 'date', 'markdown', 'html', 'image', 'auto'] | list[Literal['str', 'number', 'bool', 'date', 'markdown', 'html']]
default `= "str"`
Datatype of values in sheet. Can be provided per column as a list of strings,
or for the entire sheet as a single string. Valid datatypes are "str",
"number", "bool", "date", and "markdown". Boolean columns will display as
checkboxes. If the datatype "auto" is used, the column datatypes are
automatically selected based on the value input if possible.
type: Literal['pandas', 'numpy', 'array', 'polars']
default `= "pandas"`
Type of value to be returned by component. "pandas" for pandas dataframe,
"numpy" for numpy array, "polars" for polars dataframe, or "array" for a
Python list of lists.
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 `[{ "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). Only applies to
columns whose datatype is "markdown".
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
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
e 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.
show_label: bool | None
default `= None`
if True, will display label.
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.
max_height: int | str
default `= 500`
The maximum height of the dataframe, specified in pixels if a number is
passed, or in CSS units if a string is passed. If more rows are created than
can fit in the height, a scrollbar will appear.
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 edit the dataframe; if False, can only be used to
display data. 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, co
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
used to
display data. If not provided, this is inferred based on whether the component
is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
wrap: bool
default `= False`
If True, the text in table cells will wrap when appropriate. If False and the
`column_width` parameter is not set, the column widths will expand based on
the cell contents and the table may need to be horizontally scrolled. If
`column_width` is set, then any overflow text will be hidden.
line_breaks: bool
default `= True`
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
nd based on
the cell contents and the table may need to be horizontally scrolled. If
`column_width` is set, then any overflow text will be hidden.
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 for columns
of type "markdown."
column_widths: list[str | int] | None
default `= None`
An optional list representing the width of each column. The elements of the
list should be in the format "100px" (ints are also accepted and converted to
pixel values) or "10%". The percentage width is calculated based on the
viewport width of the table. If not provided, the column widths will be
automatically determined based on the content of the cells.
buttons: list[Literal['fullscreen', 'copy']] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "fullscreen" and "copy". The "fullscreen" button allows the user
to view the table in fullscreen mode. The "copy" button allows the user to
copy the table data to the clipboard. By default, all buttons are shown.
show_row_numbers: bool
default `= False`
If True, will display row numbers in a separate column.
max_chars: int | None
default `= None`
Maximum number of characters to display in each cell before truncating
(single-clicking a cell value will still reveal the full content). If None, no
truncation is applied.
show_search: Literal['none', 'search', 'filter']
default `= "none"`
Show a search input in the toolbar. If "search", a search input is shown. If
"filter", a search input and filter buttons are shown. If "none", no search
input is shown.
pinned_columns: int | None
default `= None`
If provided, will pin the specified number of columns from the left.
static_columns: list[int] | None
default `= None`
List o
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
pinned_columns: int | None
default `= None`
If provided, will pin the specified number of columns from the left.
static_columns: list[int] | None
default `= None`
List of column indices (int) that should not be editable. Only applies when
interactive=True. When specified, col_count is automatically set to "fixed"
and columns cannot be inserted or deleted.
|
Initialization
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Dataframe`| "dataframe"| Uses default values
`gradio.Numpy`| "numpy"| Uses type="numpy"
`gradio.Matrix`| "matrix"| Uses type="array"
`gradio.List`| "list"| Uses type="array", col_count=1
|
Shortcuts
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
filter_recordsmatrix_transposetax_calculatorsort_records
|
Demos
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe 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 Dataframe component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Dataframe.change(fn, ···)`| Triggered when the value of the Dataframe 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.
`Dataframe.input(fn, ···)`| This listener is triggered when the user changes
the value of the Dataframe.
`Dataframe.select(fn, ···)`| Event listener for when the user selects or
deselects the Dataframe. Uses event data gradio.SelectData to carry `value`
referring to the label of the Dataframe, and `selected` to refer to state of
the Dataframe. See EventData documentation on how to use this event data
`Dataframe.edit(fn, ···)`| This listener is triggered when the user edits the
Dataframe (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
|
Event Listeners
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
onent | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
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 ev
|
Event Listeners
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
ss animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pend
|
Event Listeners
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
e
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
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
|
Event Listeners
|
https://gradio.app/docs/gradio/dataframe
|
Gradio - Dataframe Docs
|
| 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/dataframe
|
Gradio - Dataframe Docs
|
Button that triggers a Spaces Duplication, when the demo is on Hugging Face
Spaces. Does nothing locally.
|
Description
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton 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/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
Parameters ▼
value: str
default `= "Duplicate Space"`
default text for the button to display. If a function is provided, the
function will be called each time the app loads to set the initial value of
this component.
every: Timer | float | None
default `= None`
continuously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
variant: Literal['primary', 'secondary', 'stop', 'huggingface']
default `= "huggingface"`
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 `= "sm"`
size of the button. Can be "sm", "md", or "lg".
icon: str | Path | None
default `= None`
URL or path to the icon file to display within the button. If None, no icon
will be displayed.
link: str | None
default `= None`
URL to open when the button is clicked. If None, no link will be used.
link_target: Literal['_self', '_blank', '_parent', '_top']
default `= "_self"`
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 op
|
Initialization
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
he layout but still exist in the DOM
interactive: bool
default `= True`
if False, the Button will be in a disabled state.
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
an optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
if False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
scale: int | None
default `= 0`
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 respect
|
Initialization
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
m pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
|
Initialization
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.DuplicateButton`| "duplicatebutton"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton 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 DuplicateButton component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener| Description
---|---
`DuplicateButton.click(fn, ···)`| Triggered when the Button is clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API
|
Event Listeners
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (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 p
|
Event Listeners
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
t
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: 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` par
|
Event Listeners
|
https://gradio.app/docs/gradio/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
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/duplicatebutton
|
Gradio - Duplicatebutton Docs
|
Creates a component to displays a base image and colored annotations on top
of that image. Annotations can take the from of rectangles (e.g. object
detection) or masks (e.g. image segmentation). As this component does not
accept user input, it is rarely used as an input component.
|
Description
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
**As input component** : Passes its value as a `tuple` consisting of a
`str` filepath to a base image and `list` of annotations. Each annotation
itself is `tuple` of a mask (as a `str` filepath to image) and a `str` label.
Your function should accept one of these types:
def predict(
value: tuple[str, list[tuple[str, str]]] | None
)
...
**As output component** : Expects a a tuple of a base image and list of
annotations: a `tuple[Image, list[Annotation]]`. The `Image` itself can be
`str` filepath, `numpy.ndarray`, or `PIL.Image`. Each `Annotation` is a
`tuple[Mask, str]`. The `Mask` can be either a `tuple` of 4 `int`'s
representing the bounding box coordinates (x1, y1, x2, y2), or 0-1 confidence
mask in the form of a `numpy.ndarray` of the same shape as the image, while
the second element of the `Annotation` tuple is a `str` label.
Your function should return one of these types:
def predict(···) -> tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Parameters ▼
value: tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
default `= None`
Tuple of base image and list of (annotation, label) pairs.
format: str
default `= "webp"`
Format used to save images before it is returned to the front end, such as
'jpeg' or 'png'. This parameter only takes effect when the base image is
returned from the prediction function as a numpy array or a PIL Image. The
format should be supported by the PIL library.
show_legend: bool
default `= True`
If True, will show a legend of the annotations.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
color_map: dict[str, str] | None
default `= None`
A dictionary mapping labels to colors. The colors must be specified as hex
codes.
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] |
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ct 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 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.
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
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
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.
buttons: list[Literal['fullscreen']] | None
default `= None`
A list of buttons to show for the component. Currently, the only valid option
is "fullscreen". The "fullscreen" button allows the user to view the image in
fullscreen mode. By default, all buttons are shown.
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.AnnotatedImage`| "annotatedimage"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
image_segmentation
|
Demos
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage 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 AnnotatedImage component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener| Description
---|---
`AnnotatedImage.select(fn, ···)`| Event listener for when the user selects or
deselects the AnnotatedImage. Uses event data gradio.SelectData to carry
`value` referring to the label of the AnnotatedImage, and `selected` to refer
to state of the AnnotatedImage. 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 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 fu
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
h (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this eve
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
uts', 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/annotatedimage
|
Gradio - Annotatedimage Docs
|
he main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
A Gradio request object that can be used to access the request headers,
cookies, query parameters and other information about the request from within
the prediction function. The class is a thin wrapper around the
fastapi.Request class. Attributes of this class include: `headers`, `client`,
`query_params`, `session_hash`, and `path_params`. If auth is enabled, the
`username` attribute can be used to get the logged in user. In some
environments, the dict-like attributes (e.g. `requests.headers`,
`requests.query_params`) of this class are automatically converted to
dictionaries, so we recommend converting them to dictionaries before accessing
attributes for consistent behavior in different environments.
|
Description
|
https://gradio.app/docs/gradio/request
|
Gradio - Request Docs
|
import gradio as gr
def echo(text, request: gr.Request):
if request:
print("Request headers dictionary:", request.headers)
print("IP address:", request.client.host)
print("Query parameters:", dict(request.query_params))
print("Session hash:", request.session_hash)
return text
io = gr.Interface(echo, "textbox", "textbox").launch()
|
Example Usage
|
https://gradio.app/docs/gradio/request
|
Gradio - Request Docs
|
Parameters ▼
request: fastapi.Request | None
default `= None`
A fastapi.Request
username: str | None
default `= None`
The username of the logged in user (if auth is enabled)
session_hash: str | None
default `= None`
The session hash of the current session. It is unique for each page load.
|
Initialization
|
https://gradio.app/docs/gradio/request
|
Gradio - Request Docs
|
request_ip_headers
|
Demos
|
https://gradio.app/docs/gradio/request
|
Gradio - Request Docs
|
ZeroGPU
ZeroGPU spaces are rate-limited to ensure that a single user does not hog all
of the available GPUs. The limit is controlled by a special token that the
Hugging Face Hub infrastructure adds to all incoming requests to Spaces. This
token is a request header called `X-IP-Token` and its value changes depending
on the user who makes a request to the ZeroGPU space.
Let’s say you want to create a space (Space A) that uses a ZeroGPU space
(Space B) programmatically. Normally, calling Space B from Space A with the
Gradio Python client would quickly exhaust Space B’s rate limit, as all the
requests to the ZeroGPU space would be missing the `X-IP-Token` request header
and would therefore be treated as unauthenticated.
In order to avoid this, we need to extract the `X-IP-Token` of the user using
Space A before we call Space B programmatically. Where possible, specifically
in the case of functions that are passed into event listeners directly, Gradio
automatically extracts the `X-IP-Token` from the incoming request and passes
it into the Gradio Client. But if the Client is instantiated outside of such a
function, then you may need to pass in the token manually.
How to do this will be explained in the following section.
|
Explaining Rate Limits for
|
https://gradio.app/docs/python-client/using-zero-gpu-spaces
|
Python Client - Using Zero Gpu Spaces Docs
|
Token
In the following hypothetical example, when a user presses enter in the
textbox, the `generate()` function is called, which calls a second function,
`text_to_image()`. Because the Gradio Client is being instantiated indirectly,
in `text_to_image()`, we will need to extract their token from the `X-IP-
Token` header of the incoming request. We will use this header when
constructing the gradio client.
import gradio as gr
from gradio_client import Client
def text_to_image(prompt, request: gr.Request):
x_ip_token = request.headers['x-ip-token']
client = Client("hysts/SDXL", headers={"x-ip-token": x_ip_token})
img = client.predict(prompt, api_name="/predict")
return img
def generate(prompt, request: gr.Request):
prompt = prompt[:300]
return text_to_image(prompt, request)
with gr.Blocks() as demo:
image = gr.Image()
prompt = gr.Textbox(max_lines=1)
prompt.submit(generate, [prompt], [image])
demo.launch()
|
Avoiding Rate Limits by Manually Passing an IP
|
https://gradio.app/docs/python-client/using-zero-gpu-spaces
|
Python Client - Using Zero Gpu Spaces Docs
|
A Job is a wrapper over the Future class that represents a prediction call
that has been submitted by the Gradio client. This class is not meant to be
instantiated directly, but rather is created by the Client.submit() method.
A Job object includes methods to get the status of the prediction call, as
well to get the outputs of the prediction call. Job objects are also iterable,
and can be used in a loop to get the outputs of prediction calls as they
become available for generator endpoints.
|
Description
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
Parameters ▼
future: Future
The future object that represents the prediction call, created by the
Client.submit() method
communicator: Communicator | None
default `= None`
The communicator object that is used to communicate between the client and the
background thread running the job
verbose: bool
default `= True`
Whether to print any status-related messages to the console
space_id: str | None
default `= None`
The space ID corresponding to the Client object that created this Job object
|
Initialization
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Job component supports the following event listeners. Each event listener
takes the same parameters, which are listed in the Event Parameters table
below.
Listener| Description
---|---
`Job.result(fn, ···)`| Return the result of the call that the future
represents. Raises CancelledError: If the future was cancelled, TimeoutError:
If the future didn't finish executing before the given timeout, and Exception:
If the call raised then that exception will be raised. <br>
`Job.outputs(fn, ···)`| Returns a list containing the latest outputs from the
Job. <br> If the endpoint has multiple output components, the list will
contain a tuple of results. Otherwise, it will contain the results without
storing them in tuples. <br> For endpoints that are queued, this list will
contain the final job output even if that endpoint does not use a generator
function. <br>
`Job.status(fn, ···)`| Returns the latest status update from the Job in the
form of a StatusUpdate object, which contains the following fields: code,
rank, queue_size, success, time, eta, and progress_data. <br> progress_data is
a list of updates emitted by the gr.Progress() tracker of the event handler.
Each element of the list has the following fields: index, length, unit,
progress, desc. If the event handler does not have a gr.Progress() tracker,
the progress_data field will be None. <br>
Event Parameters
Parameters ▼
timeout: float | None
default `= None`
The number of seconds to wait for the result if the future isn't done. If
None, then there is no limit on the wait time.
|
Event Listeners
|
https://gradio.app/docs/python-client/job
|
Python Client - Job Docs
|
**Stream From a Gradio app in 5 lines**
Use the `submit` method to get a job you can iterate over.
In python:
from gradio_client import Client
client = Client("gradio/llm_stream")
for result in client.submit("What's the best UI framework in Python?"):
print(result)
In typescript:
import { Client } from "@gradio/client";
const client = await Client.connect("gradio/llm_stream")
const job = client.submit("/predict", {"text": "What's the best UI framework in Python?"})
for await (const msg of job) console.log(msg.data)
**Use the same keyword arguments as the app**
In the examples below, the upstream app has a function with parameters called
`message`, `system_prompt`, and `tokens`. We can see that the client `predict`
call uses the same arguments.
In python:
from gradio_client import Client
client = Client("http://127.0.0.1:7860/")
result = client.predict(
message="Hello!!",
system_prompt="You are helpful AI.",
tokens=10,
api_name="/chat"
)
print(result)
In typescript:
import { Client } from "@gradio/client";
const client = await Client.connect("http://127.0.0.1:7860/");
const result = await client.predict("/chat", {
message: "Hello!!",
system_prompt: "Hello!!",
tokens: 10,
});
console.log(result.data);
**Better Error Messages**
If something goes wrong in the upstream app, the client will raise the same
exception as the app provided that `show_error=True` in the original app's
`launch()` function, or it's a `gr.Error` exception.
|
Ergonomic API 💆
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
Anything you can do in the UI, you can do with the client:
* 🔐Authentication
* 🛑 Job Cancelling
* ℹ️ Access Queue Position and API
* 📕 View the API information
Here's an example showing how to display the queue position of a pending job:
from gradio_client import Client
client = Client("gradio/diffusion_model")
job = client.submit("A cute cat")
while not job.done():
status = job.status()
print(f"Current in position {status.rank} out of {status.queue_size}")
|
Transparent Design 🪟
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
The client can run from pretty much any python and javascript environment
(node, deno, the browser, Service Workers).
Here's an example using the client from a Flask server using gevent:
from gevent import monkey
monkey.patch_all()
from gradio_client import Client
from flask import Flask, send_file
import time
app = Flask(__name__)
imageclient = Client("gradio/diffusion_model")
@app.route("/gen")
def gen():
result = imageclient.predict(
"A cute cat",
api_name="/predict"
)
return send_file(result)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
|
Portable Design ⛺️
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
Changes
**Python**
* The `serialize` argument of the `Client` class was removed and has no effect.
* The `upload_files` argument of the `Client` was removed.
* All filepaths must be wrapped in the `handle_file` method. For example, `caption = client.predict(handle_file('./dog.jpg'))`.
* The `output_dir` argument was removed. It is not specified in the `download_files` argument.
**Javascript**
The client has been redesigned entirely. It was refactored from a function
into a class. An instance can now be constructed by awaiting the `connect`
method.
const app = await Client.connect("gradio/whisper")
The app variable has the same methods as the python class (`submit`,
`predict`, `view_api`, `duplicate`).
|
v1.0 Migration Guide and Breaking
|
https://gradio.app/docs/python-client/version-1-release
|
Python Client - Version 1 Release Docs
|
If you already have a recent version of `gradio`, then the `gradio_client` is
included as a dependency. But note that this documentation reflects the latest
version of the `gradio_client`, so upgrade if you’re not sure!
The lightweight `gradio_client` package can be installed from pip (or pip3)
and is tested to work with **Python versions 3.9 or higher** :
$ pip install --upgrade gradio_client
|
Installation
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Spaces
Start by connecting instantiating a `Client` object and connecting it to a
Gradio app that is running on Hugging Face Spaces.
from gradio_client import Client
client = Client("abidlabs/en2fr") a Space that translates from English to French
You can also connect to private Spaces by passing in your HF token with the
`hf_token` parameter. You can get your HF token here:
<https://huggingface.co/settings/tokens>
from gradio_client import Client
client = Client("abidlabs/my-private-space", hf_token="...")
|
Connecting to a Gradio App on Hugging Face
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
use
While you can use any public Space as an API, you may get rate limited by
Hugging Face if you make too many requests. For unlimited usage of a Space,
simply duplicate the Space to create a private Space, and then use it to make
as many requests as you’d like!
The `gradio_client` includes a class method: `Client.duplicate()` to make this
process simple (you’ll need to pass in your [Hugging Face
token](https://huggingface.co/settings/tokens) or be logged in using the
Hugging Face CLI):
import os
from gradio_client import Client, file
HF_TOKEN = os.environ.get("HF_TOKEN")
client = Client.duplicate("abidlabs/whisper", hf_token=HF_TOKEN)
client.predict(file("audio_sample.wav"))
>> "This is a test of the whisper speech recognition model."
If you have previously duplicated a Space, re-running `duplicate()` will _not_
create a new Space. Instead, the Client will attach to the previously-created
Space. So it is safe to re-run the `Client.duplicate()` method multiple times.
**Note:** if the original Space uses GPUs, your private Space will as well,
and your Hugging Face account will get billed based on the price of the GPU.
To minimize charges, your Space will automatically go to sleep after 1 hour of
inactivity. You can also set the hardware using the `hardware` parameter of
`duplicate()`.
|
Duplicating a Space for private
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
app
If your app is running somewhere else, just provide the full URL instead,
including the “http://” or “https://“. Here’s an example of making predictions
to a Gradio app that is running on a share URL:
from gradio_client import Client
client = Client("https://bec81a83-5b5c-471e.gradio.live")
|
Connecting a general Gradio
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Once you have connected to a Gradio app, you can view the APIs that are
available to you by calling the `Client.view_api()` method. For the Whisper
Space, we see the following:
Client.predict() Usage Info
---------------------------
Named API endpoints: 1
- predict(audio, api_name="/predict") -> output
Parameters:
- [Audio] audio: filepath (required)
Returns:
- [Textbox] output: str
We see that we have 1 API endpoint in this space, and shows us how to use the
API endpoint to make a prediction: we should call the `.predict()` method
(which we will explore below), providing a parameter `input_audio` of type
`str`, which is a `filepath or URL`.
We should also provide the `api_name='/predict'` argument to the `predict()`
method. Although this isn’t necessary if a Gradio app has only 1 named
endpoint, it does allow us to call different endpoints in a single app if they
are available.
|
Inspecting the API endpoints
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
As an alternative to running the `.view_api()` method, you can click on the
“Use via API” link in the footer of the Gradio app, which shows us the same
information, along with example usage.

The View API page also includes an “API Recorder” that lets you interact with
the Gradio UI normally and converts your interactions into the corresponding
code to run with the Python Client.
|
The “View API” Page
|
https://gradio.app/docs/python-client/introduction
|
Python Client - Introduction Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.