text stringlengths 0 2k | heading1 stringlengths 4 79 | source_page_url stringclasses 183 values | source_page_title stringclasses 183 values |
|---|---|---|---|
ved_by_key: list[str] | str | None
default `= None`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
[Controlling Layout](../../guides/controlling-layout/)
| Initialization | https://gradio.app/docs/gradio/column | Gradio - Column Docs |
Creates an image component that can be used to upload images (as an input)
or display images (as an output).
| Description | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
**Using SimpleImage as an input component.**
How SimpleImage will pass its value to your function:
Type: `str | None`
A `str` containing the path to the image.
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from the SimpleImage component
return "prediction"
interface = gr.Interface(predict, gr.SimpleImage(), gr.Textbox())
interface.launch()
**Using SimpleImage as an output component**
How SimpleImage expects you to return a value:
Type: `str | Path | None`
Expects a `str` or `pathlib.Path` object containing the path to the image.
Example Code
import gradio as gr
def predict(text) -> str | Path | None
process value to return to the SimpleImage component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.SimpleImage())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
Parameters ▼
value: str | None
default `= None`
A path or URL for the default value that SimpleImage component is going to
take. If a function is provided, the function will be called each time the app
loads to set the initial value of this component.
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.
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.
show_download_button: bool
default `= True`
If True, will display button to download image.
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 | Initialization | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
ll_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, will allow users to upload and edit an image; if False, can only be
used to display images. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | 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 | Initialization | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
| Initialization | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
Shortcuts
gradio.SimpleImage
Interface String Shortcut `"simpleimage"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage 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 SimpleImage component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
SimpleImage.clear(fn, ···)
This listener is triggered when the user clears the SimpleImage using the
clear button for the component.
SimpleImage.change(fn, ···)
Triggered when the value of the SimpleImage 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.
SimpleImage.upload(fn, ···)
This listener is triggered when the user uploads a file into the SimpleImage.
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.
| Event Listeners | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for e | Event Listeners | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input argumen | Event Listeners | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
d allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be ca | Event Listeners | https://gradio.app/docs/gradio/simpleimage | Gradio - Simpleimage Docs |
e`
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/simpleimage | Gradio - Simpleimage Docs |
Creates a button that can be assigned arbitrary .click() events. The value
(label) of the button can be used as an input to the function (rarely used) or
set via the output of a function.
| Description | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
**Using Button as an input component.**
How Button will pass its value to your function:
Type: `str | None`
(Rarely used) the `str` corresponding to the button label when the button is
clicked
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from the Button component
return "prediction"
interface = gr.Interface(predict, gr.Button(), gr.Textbox())
interface.launch()
**Using Button as an output component**
How Button expects you to return a value:
Type: `str | None`
string corresponding to the button label
Example Code
import gradio as gr
def predict(text) -> str | None
process value to return to the Button component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.Button())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
Parameters ▼
value: str | I18nData | Callable
default `= "Run"`
default text for the button to display. If a function is provided, the
function will be called each time the app loads to set the initial value of
this component.
every: Timer | float | None
default `= None`
continuously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
variant: Literal['primary', 'secondary', 'stop', 'huggingface']
default `= "secondary"`
sets the background and text color of the button. Use 'primary' for main call-
to-action buttons, 'secondary' for a more subdued style, 'stop' for a stop
button, 'huggingface' for a black background with white text, consistent with
Hugging Face's button styles.
size: Literal['sm', 'md', 'lg']
default `= "lg"`
size of the button. Can be "sm", "md", or "lg".
icon: str | Path | None
default `= None`
URL or path to the icon file to display within the button. If None, no icon
will be displayed.
link: str | None
default `= None`
URL to open when the button is clicked. If None, no link will be used.
link_target: Literal['_self', '_blank', '_parent', '_top']
default `= "_self"`
determines where to open the linked URL. "_self" (default, same tab), "_blank"
(new tab), "_parent" (parent frame), "_top" (top frame).
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
in | Initialization | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
iteral['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
interactive: bool
default `= True`
if False, the Button will be in a disabled state.
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
an optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
if False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen sp | Initialization | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
| Initialization | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
Shortcuts
gradio.Button
Interface String Shortcut `"button"`
Initialization Uses default values
gradio.ClearButton
Interface String Shortcut `"clearbutton"`
Initialization Uses default values
gradio.DeepLinkButton
Interface String Shortcut `"deeplinkbutton"`
Initialization Uses default values
gradio.DuplicateButton
Interface String Shortcut `"duplicatebutton"`
Initialization Uses default values
gradio.LoginButton
Interface String Shortcut `"loginbutton"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Button component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Button.click(fn, ···)
Triggered when the Button is clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. | Event Listeners | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data be | Event Listeners | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which | Event Listeners | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
y_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
| Event Listeners | https://gradio.app/docs/gradio/button | Gradio - Button Docs |
The Progress class provides a custom progress tracker that is used in a
function signature. To attach a Progress tracker to a function, simply add a
parameter right after the input parameters that has a default value set to a
`gradio.Progress()` instance. The Progress tracker can then be updated in the
function by calling the Progress object or using the `tqdm` method on an
Iterable.
| Description | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
import gradio as gr
import time
def my_function(x, progress=gr.Progress()):
progress(0, desc="Starting...")
time.sleep(1)
for i in progress.tqdm(range(100)):
time.sleep(0.1)
return x
gr.Interface(my_function, gr.Textbox(), gr.Textbox()).queue().launch()
| Example Usage | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
Parameters ▼
track_tqdm: bool
default `= False`
If True, the Progress object will track any tqdm.tqdm iterations with the tqdm
library in the function.
| Initialization | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
Methods | https://gradio.app/docs/gradio/progress | Gradio - Progress 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.Progress.__call__(progress, ···)
Description
%20Copyright%202022%20Fontic | __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
20512'%3e%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)
Updates progress tracker with progress and message text.
Parameters ▼
progress: float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If Tuple, first
number represents steps completed, and second value represents total steps or
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total | __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
| __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress 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.Progress.tqdm(iterable, ···)
Description
%20Copyright%202022%20Fonticons, | tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
2'%3e%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)
Attaches progress tracker to iterable, like tqdm.
Parameters ▼
iterable: Iterable | None
iterable to attach progress tracker to.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
[Progress Bars](../../guides/progress-bars/)
| tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
total number of steps.
unit: str
default `= "steps"`
unit of iterations.
[Progress Bars](../../guides/progress-bars/)
| tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress 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.Progress.__call__(progress, ···)
Description
%20Copyright%202022%20Fontic | __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
20512'%3e%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)
Updates progress tracker with progress and message text.
Parameters ▼
progress: float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If Tuple, first
number represents steps completed, and second value represents total steps or
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total | __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
| __call__ | https://gradio.app/docs/gradio/progress | Gradio - Progress 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.Progress.tqdm(iterable, ···)
Description
%20Copyright%202022%20Fonticons, | tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
2'%3e%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)
Attaches progress tracker to iterable, like tqdm.
Parameters ▼
iterable: Iterable | None
iterable to attach progress tracker to.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
| tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
total number of steps.
unit: str
default `= "steps"`
unit of iterations.
| tqdm | https://gradio.app/docs/gradio/progress | Gradio - Progress Docs |
This class is a wrapper over the Dataset component and can be used to
create Examples for Blocks / Interfaces. Populates the Dataset component with
examples and assigns event listener so that clicking on an example populates
the input/output components. Optionally handles example caching for fast
inference.
| Description | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
Parameters ▼
examples: list[Any] | list[list[Any]] | str
example inputs that can be clicked to populate specific components. Should be
nested list, in which the outer list consists of samples and each inner list
consists of an input corresponding to each input component. A string path to a
directory of examples can also be provided but it should be within the
directory with the python file running the gradio app. If there are multiple
input components and a directory is provided, a log.csv file must be present
in the directory to link corresponding inputs.
inputs: Component | list[Component]
the component or list of components corresponding to the examples
outputs: Component | list[Component] | None
default `= None`
optionally, provide the component or list of components corresponding to the
output of the examples. Required if `cache_examples` is not False.
fn: Callable | None
default `= None`
optionally, provide the function to run to generate the outputs corresponding
to the examples. Required if `cache_examples` is not False. Also required if
`run_on_click` is True.
cache_examples: bool | None
default `= None`
If True, caches examples in the server for fast runtime in examples. If
"lazy", then examples are cached (for all users of the app) after their first
use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES
environment variable, which should be either "true" or "false". In HuggingFace
Spaces, this parameter is True (as long as `fn` and `outputs` are also
provided). The default option otherwise is False. Note that examples are
cached separately from Gradio's queue() so certain features, such as
gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are | Initialization | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
d in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment
variable if defined, or default to "eager".
examples_per_page: int
default `= 10`
how many examples to show per page.
label: str | I18nData | None
default `= "Examples"`
the label to use for the examples component (by default, "Examples")
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM.
run_on_click: bool
default `= False`
if cache_examples is False, clicking on an example does not run the function
when an example is clicked. Set this to True to run the function when an
example is clicked. Has no effect if cache_examples is True.
preprocess: bool
default `= True`
if True, preprocesses the example input before running the prediction function
and caching the output. Only applies if `cache_examples` is not False.
postprocess: bool
default `= True`
if True, postprocesses the example output after running the prediction
function and before caching. Only applies if `cache_examples` is not False.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "undocumented"`
Controls the visibility of the event associated with clicking on the examples.
Can be "public" (shown in API docs and callable), "private" (hidden from API
docs and not callable), or "undocumented" (hidden from API docs but callable).
api_name: str | None
default `= "load_example"`
Defines how the event associated with clicking on the examples 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, an auto-generated name
will be u | Initialization | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
icking on the examples 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, an auto-generated name
will be used.
api_description: str | None | Literal[False]
default `= None`
Description of the event associated with clicking on the examples in the API
docs. 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.
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. Used only if
cache_examples is not False.
example_labels: list[str] | None
default `= None`
A list of labels for each example. If provided, the length of this list should
be the same as the number of examples, and these labels will be used in the UI
instead of rendering the example values.
visible: bool | Literal['hidden']
default `= True`
If False, the examples component will be hidden in the UI.
preload: int | Literal[False]
default `= 0`
If an integer is provided (and examples are being cached eagerly and none of
the input components have a developer-provided `value`), the example at that
index in the examples list will be preloaded when the Gradio app is first
loaded. If False, no example will be preloaded.
| Initialization | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
Parameters ▼
dataset: gradio.Dataset
The `gr.Dataset` component corresponding to this Examples object.
load_input_event: gradio.events.Dependency
The Gradio event that populates the input values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event.
cache_event: gradio.events.Dependency | None
The Gradio event that populates the cached output values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event. This event is `None` if
`cache_examples` if False, and is the same as `load_input_event` if
`cache_examples` is `'lazy'`.
| Attributes | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
**Updating Examples**
In this demo, we show how to update the examples by updating the samples of
the underlying dataset. Note that this only works if `cache_examples=False` as
updating the underlying dataset does not update the cache.
import gradio as gr
def update_examples(country):
if country == "USA":
return gr.Dataset(samples=[["Chicago"], ["Little Rock"], ["San Francisco"]])
else:
return gr.Dataset(samples=[["Islamabad"], ["Karachi"], ["Lahore"]])
with gr.Blocks() as demo:
dropdown = gr.Dropdown(label="Country", choices=["USA", "Pakistan"], value="USA")
textbox = gr.Textbox()
examples = gr.Examples([["Chicago"], ["Little Rock"], ["San Francisco"]], textbox)
dropdown.change(update_examples, dropdown, examples.dataset)
demo.launch()
| Examples | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
calculator_blocks
| Demos | https://gradio.app/docs/gradio/examples | Gradio - Examples Docs |
The gr.KeyUpData class is a subclass of gr.EventData that specifically
carries information about the `.key_up()` event. When gr.KeyUpData is added as
a type hint to an argument of an event listener method, a gr.KeyUpData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
| Description | https://gradio.app/docs/gradio/keyupdata | Gradio - Keyupdata Docs |
import gradio as gr
def test(value, key_up_data: gr.KeyUpData):
return {
"component value": value,
"input value": key_up_data.input_value,
"key": key_up_data.key
}
with gr.Blocks() as demo:
d = gr.Dropdown(["abc", "def"], allow_custom_value=True)
t = gr.JSON()
d.key_up(test, d, t)
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/keyupdata | Gradio - Keyupdata Docs |
Parameters ▼
key: str
The key that was pressed.
input_value: str
The displayed value in the input textbox after the key was pressed. This may
be different than the `value` attribute of the component itself, as the
`value` attribute of some components (e.g. Dropdown) are not updated until the
user presses Enter.
| Attributes | https://gradio.app/docs/gradio/keyupdata | Gradio - Keyupdata Docs |
dropdown_key_up
| Demos | https://gradio.app/docs/gradio/keyupdata | Gradio - Keyupdata Docs |
The FileData class is a subclass of the GradioModel class that represents a
file object within a Gradio interface. It is used to store file data and
metadata when a file is uploaded.
| Description | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
from gradio_client import Client, FileData, handle_file
def get_url_on_server(data: FileData):
print(data['url'])
client = Client("gradio/gif_maker_main", download_files=False)
job = client.submit([handle_file("./cheetah.jpg")], api_name="/predict")
data = job.result()
video: FileData = data['video']
get_url_on_server(video)
| Example Usage | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
Parameters ▼
path: str
The server file path where the file is stored.
url: Optional[str]
The normalized server URL pointing to the file.
size: Optional[int]
The size of the file in bytes.
orig_name: Optional[str]
The original filename before upload.
mime_type: Optional[str]
The MIME type of the file.
is_stream: bool
Indicates whether the file is a stream.
meta: dict
Additional metadata used internally (should not be changed).
| Attributes | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
Creates a gallery or table to display data samples. This component is
primarily designed for internal use to display examples. However, it can also
be used directly to display a dataset and let users select examples.
| Description | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
**Using Dataset as an input component.**
How Dataset will pass its value to your function:
Type: `int | list | tuple[int, list] | None`
Passes the selected sample either as a `list` of data corresponding to each
input component (if `type` is "value") or as an `int` index (if `type` is
"index"), or as a `tuple` of the index and the data (if `type` is "tuple").
Example Code
import gradio as gr
def predict(
value: int | list | tuple[int, list] | None
):
process value from the Dataset component
return "prediction"
interface = gr.Interface(predict, gr.Dataset(), gr.Textbox())
interface.launch()
**Using Dataset as an output component**
How Dataset expects you to return a value:
Type: `int | list | None`
Expects an `int` index or `list` of sample data. Returns the index of the
sample in the dataset or `None` if the sample is not found.
Example Code
import gradio as gr
def predict(text) -> int | list | None
process value to return to the Dataset component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.Dataset())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
Parameters ▼
label: str | I18nData | None
default `= None`
the label for this component, appears above the component.
show_label: bool
default `= True`
If True, the label will be shown above the component.
components: list[Component] | list[str] | None
default `= None`
Which component types to show in this dataset widget, can be passed in as a
list of string names or Components instances. The following components are
supported in a Dataset: Audio, Checkbox, CheckboxGroup, ColorPicker,
Dataframe, Dropdown, File, HTML, Image, Markdown, Model3D, Number, Radio,
Slider, Textbox, TimeSeries, Video
component_props: list[dict[str, Any]] | None
default `= None`
samples: list[list[Any]] | None
default `= None`
a nested list of samples. Each sublist within the outer list represents a data
sample, and each element within the sublist represents an value for each
component
headers: list[str] | None
default `= None`
Column headers in the Dataset widget, should be the same len as components. If
not provided, inferred from component labels
type: Literal['values', 'index', 'tuple']
default `= "values"`
"values" if clicking on a sample should pass the value of the sample, "index"
if it should pass the index of the sample, or "tuple" if it should pass both
the index and the value of the sample.
layout: Literal['gallery', 'table'] | None
default `= None`
"gallery" if the dataset should be displayed as a gallery with each sample in
a clickable card, or "table" if it should be displayed as a table with each
sample in a row. By default, "gallery" is used if there is a single component,
and "table" is used if there are more than one component. If there are more
than one component, the layout can only be "table".
samples_per_page: int
default `= 10`
how many examples to show per page.
visible: bool | Literal['hidden'] | Initialization | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
re more
than one component, the layout can only be "table".
samples_per_page: int
default `= 10`
how many examples to show per page.
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.
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 wi | Initialization | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
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.
proxy_url: str | None
default `= None`
The URL of the external Space used to load this component. Set automatically
when using `gr.load()`. This should not be set manually.
sample_labels: list[str] | None
default `= None`
A list of labels for each sample. If provided, the length of this list should
be the same as the number of samples, and these labels will be used in the UI
instead of rendering the sample values.
| Initialization | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
Shortcuts
gradio.Dataset
Interface String Shortcut `"dataset"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
**Updating a Dataset**
In this example, we display a text dataset using `gr.Dataset` and then update
it when the user clicks a button:
import gradio as gr
philosophy_quotes = [
["I think therefore I am."],
["The unexamined life is not worth living."]
]
startup_quotes = [
["Ideas are easy. Implementation is hard"],
["Make mistakes faster."]
]
def show_startup_quotes():
return gr.Dataset(samples=startup_quotes)
with gr.Blocks() as demo:
textbox = gr.Textbox()
dataset = gr.Dataset(components=[textbox], samples=philosophy_quotes)
button = gr.Button()
button.click(show_startup_quotes, None, dataset)
demo.launch()
| Examples | https://gradio.app/docs/gradio/dataset | Gradio - Dataset 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 Dataset component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Dataset.click(fn, ···)
Triggered when the Dataset is clicked.
Dataset.select(fn, ···)
Event listener for when the user selects or deselects the Dataset. Uses event
data gradio.SelectData to carry `value` referring to the label of the Dataset,
and `selected` to refer to state of the Dataset. See
<https://www.gradio.app/main/docs/gradio/eventdata> for more details.
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 | Event Listeners | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each l | Event Listeners | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
arameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If | Event Listeners | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
r js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
| Event Listeners | https://gradio.app/docs/gradio/dataset | Gradio - Dataset Docs |
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/dataset | Gradio - Dataset Docs |
Constructs a Gradio app automatically from a Hugging Face model/Space repo
name or a 3rd-party API provider. Note that if a Space repo is loaded, certain
high-level attributes of the Blocks (e.g. custom `css`, `js`, and `head`
attributes) will not be loaded.
| Description | https://gradio.app/docs/gradio/load | Gradio - Load Docs |
import gradio as gr
demo = gr.load("gradio/question-answering", src="spaces")
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/load | Gradio - Load Docs |
Parameters ▼
name: str
the name of the model (e.g. "google/vit-base-patch16-224") or Space (e.g.
"flax-community/spanish-gpt2"). This is the first parameter passed into the
`src` function. Can also be formatted as {src}/{repo name} (e.g.
"models/google/vit-base-patch16-224") if `src` is not provided.
src: Callable[[str, str | None], Blocks] | Literal['models', 'spaces', 'huggingface'] | None
default `= None`
function that accepts a string model `name` and a string or None `token` and
returns a Gradio app. Alternatively, this parameter takes one of two strings
for convenience: "models" (for loading a Hugging Face model through the
Inference API) or "spaces" (for loading a Hugging Face Space). If None, uses
the prefix of the `name` parameter to determine `src`.
token: str | None
default `= None`
optional token that is passed as the second parameter to the `src` function.
If not explicitly provided, will use the HF_TOKEN environment variable or
fallback to the locally-saved HF token when loading models but not Spaces
(when loading Spaces, only provide a token if you are loading a trusted
private Space as the token can be read by the Space you are loading). Find
your HF tokens here: https://huggingface.co/settings/tokens.
accept_token: bool | LoginButton
default `= False`
if True, a Textbox component is first rendered to allow the user to provide a
token, which will be used instead of the `token` parameter when calling the
loaded model or Space. Can also provide an instance of a gr.LoginButton in the
same Blocks scope, which allows the user to login with a Hugging Face account
whose token will be used instead of the `token` parameter when calling the
loaded model or Space.
provider: PROVIDER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova", "fal-ai", etc). Should be one of the
providers suppo | Initialization | https://gradio.app/docs/gradio/load | Gradio - Load Docs |
DER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova", "fal-ai", etc). Should be one of the
providers supported by `huggingface_hub.InferenceClient`. This parameter is
only used when `src` is "models"
kwargs: <class 'inspect._empty'>
additional keyword parameters to pass into the `src` function. If `src` is
"models" or "Spaces", these parameters are passed into the `gr.Interface` or
`gr.ChatInterface` constructor.
[Using HuggingFace Integrations](../../guides/using-hugging-face-integrations)
| Initialization | https://gradio.app/docs/gradio/load | Gradio - Load Docs |
The gr.LikeData class is a subclass of gr.EventData that specifically
carries information about the `.like()` event. When gr.LikeData is added as a
type hint to an argument of an event listener method, a gr.LikeData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
| Description | https://gradio.app/docs/gradio/likedata | Gradio - Likedata Docs |
import gradio as gr
def test(value, like_data: gr.LikeData):
return {
"chatbot_value": value,
"liked_message": like_data.value,
"liked_index": like_data.index,
"liked_or_disliked_as_bool": like_data.liked
}
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def")])
t = gr.JSON()
c.like(test, c, t)
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/likedata | Gradio - Likedata Docs |
Parameters ▼
index: int | tuple[int, int]
The index of the liked/disliked item. Is a tuple if the component is two
dimensional.
value: Any
The value of the liked/disliked item.
liked: bool
True if the item was liked, False if disliked, or string value if any other
feedback.
| Attributes | https://gradio.app/docs/gradio/likedata | Gradio - Likedata Docs |
chatbot_core_components_simple
[Chatbot Specific Events](../../guides/chatbot-specific-events/)
| Demos | https://gradio.app/docs/gradio/likedata | Gradio - Likedata Docs |
The gr.EditData class is a subclass of gr.Event data that specifically
carries information about the `.edit()` event. When gr.EditData is added as a
type hint to an argument of an event listener method, a gr.EditData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
| Description | https://gradio.app/docs/gradio/editdata | Gradio - Editdata Docs |
import gradio as gr
def edit(edit_data: gr.EditData, history: list[gr.MessageDict]):
history_up_to_edit = history[:edit_data.index]
history_up_to_edit[-1] = edit_data.value
return history_up_to_edit
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.undo(edit, chatbot, chatbot)
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/editdata | Gradio - Editdata Docs |
Parameters ▼
index: int | tuple[int, int]
The index of the message that was edited.
previous_value: Any
The previous content of the message that was edited.
value: Any
The new content of the message that was edited.
[Chatbot Specific Events](../../guides/chatbot-specific-events/)
| Attributes | https://gradio.app/docs/gradio/editdata | Gradio - Editdata Docs |
A TabbedInterface is created by providing a list of Interfaces or Blocks,
each of which gets rendered in a separate tab. Only the components from the
Interface/Blocks will be rendered in the tab.
| Description | https://gradio.app/docs/gradio/tabbedinterface | Gradio - Tabbedinterface Docs |
Parameters ▼
interface_list: list[Blocks]
A list of Interfaces (or Blocks) to be rendered in the tabs.
tab_names: list[str] | None
default `= None`
A list of tab names. If None, the tab names will be "Tab 1", "Tab 2", etc.
title: str | None
default `= None`
The tab title to display when this demo is opened in a browser window.
analytics_enabled: bool | None
default `= None`
Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED
environment variable or default to True.
| Initialization | https://gradio.app/docs/gradio/tabbedinterface | Gradio - Tabbedinterface Docs |
tabbed_interface_lite
| Demos | https://gradio.app/docs/gradio/tabbedinterface | Gradio - Tabbedinterface 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 |
**Using Number as an input component.**
How Number will pass its value to your function:
Type: `float | int | None`
Passes field value as a `float` or `int` into the function, depending on
`precision`.
Example Code
import gradio as gr
def predict(
value: float | int | None
):
process value from the Number component
return "prediction"
interface = gr.Interface(predict, gr.Number(), gr.Textbox())
interface.launch()
**Using Number as an output component**
How Number expects you to return a value:
Type: `float | int | None`
Expects an `int` or `float` returned from the function and sets field value to
it.
Example Code
import gradio as gr
def predict(text) -> float | int | None
process value to return to the Number component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.Number())
interface.launch()
| 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.
buttons: list[Button] | None
default `= None`
A list of gr.Button() instances to show in the top right corner of the
component. Custom buttons will appear in the toolbar with their configured
icon and/or label, and clicking them will trigger any .click() events
registered on the button.
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 |
Shortcuts
gradio.Number
Interface String Shortcut `"number"`
Initialization 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.
Listeners
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 | Bloc | Event Listeners | https://gradio.app/docs/gradio/number | Gradio - Number Docs |
io.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
| Event Listeners | https://gradio.app/docs/gradio/number | Gradio - Number Docs |
on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending ev | Event Listeners | https://gradio.app/docs/gradio/number | Gradio - Number Docs |
pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before t | Event Listeners | https://gradio.app/docs/gradio/number | Gradio - Number Docs |
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/number | Gradio - Number Docs |
Interface is Gradio's main high-level class, and allows you to create a
web-based GUI / demo around a machine learning model (or any Python function)
in a few lines of code. You must specify three parameters: (1) the function to
create a GUI for (2) the desired input components and (3) the desired output
components. Additional parameters can be used to control the appearance and
behavior of the demo.
| Description | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
import gradio as gr
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
Parameters ▼
fn: Callable
the function to wrap an interface around. 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: str | Component | list[str | Component] | None
a single Gradio component, or list of Gradio components. Components can either
be passed as instantiated objects, or referred to by their string shortcuts.
The number of input components should match the number of parameters in fn. If
set to None, then only the output components will be displayed.
outputs: str | Component | list[str | Component] | None
a single Gradio component, or list of Gradio components. Components can either
be passed as instantiated objects, or referred to by their string shortcuts.
The number of output components should match the number of values returned by
fn. If set to None, then only the input components will be displayed.
examples: list[Any] | list[list[Any]] | str | None
default `= None`
sample inputs for the function; if provided, appear below the UI components
and can be clicked to populate the interface. Should be nested list, in which
the outer list consists of samples and each inner list consists of an input
corresponding to each input component. A string path to a directory of
examples can also be provided, but it should be within the directory with the
python file running the gradio app. If there are multiple input components and
a directory is provided, a log.csv file must be present in the directory to
link corresponding inputs.
cache_examples: bool | None
default `= None`
If True, caches examples in the server for fast runtime in examples. If
"lazy", then examples are cached (for all users of the app) after their first
use (by any user of the app). If None, will use | Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
If True, caches examples in the server for fast runtime in examples. If
"lazy", then examples are cached (for all users of the app) after their first
use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES
environment variable, which should be either "true" or "false". In HuggingFace
Spaces, this parameter defaults to True (as long as `fn` and `outputs` are
also provided). Note that examples are cached separately from Gradio's queue()
so certain features, such as gr.Progress(), gr.Info(), gr.Warning(), etc. will
not be displayed in Gradio's UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment
variable if defined, or default to "eager". In HuggingFace Spaces, this
parameter defaults to "eager" except for ZeroGPU Spaces, in which case it
defaults to "lazy".
examples_per_page: int
default `= 10`
if examples are provided, how many to display per page.
example_labels: list[str] | None
default `= None`
a list of labels for each example. If provided, the length of this list should
be the same as the number of examples, and these labels will be used in the UI
instead of rendering the example values.
preload_example: int | Literal[False]
default `= 0`
If an integer is provided (and examples are being cached eagerly and none of
the input components have a developer-provided `value`), the example at that
index in the examples list will be preloaded when the Gradio app is first
loaded. If False, no example will be preloaded.
live: bool
default `= False`
whether the interface should automatically rerun if any of the inputs change.
title: str | I18nData | None
default `= None`
a title for the interface; if provided, appears above the input and output
components in larg | Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
tically rerun if any of the inputs change.
title: str | I18nData | None
default `= None`
a title for the interface; if provided, appears above the input and output
components in large font. Also used as the tab title when opened in a browser
window.
description: str | None
default `= None`
a description for the interface; if provided, appears above the input and
output components and beneath the title in regular font. Accepts Markdown and
HTML content.
article: str | None
default `= None`
an expanded article explaining the interface; if provided, appears below the
input and output components in regular font. Accepts Markdown and HTML
content. If it is an HTTP(S) link to a downloadable remote file, the content
of this file is displayed.
flagging_mode: Literal['never'] | Literal['auto'] | Literal['manual'] | None
default `= None`
one of "never", "auto", or "manual". If "never" or "auto", users will not see
a button to flag an input and output. If "manual", users will see a button to
flag. If "auto", every input the user submits will be automatically flagged,
along with the generated output. If "manual", both the input and outputs are
flagged when the user clicks flag button. This parameter can be set with
environmental variable GRADIO_FLAGGING_MODE; otherwise defaults to "manual".
flagging_options: list[str] | list[tuple[str, str]] | None
default `= None`
if provided, allows user to select from the list of options when flagging.
Only applies if flagging_mode is "manual". Can either be a list of tuples of
the form (label, value), where label is the string that will be displayed on
the button and value is the string that will be stored in the flagging CSV; or
it can be a list of strings ["X", "Y"], in which case the values will be the
list of strings and the labels will ["Flag as X", "Flag as Y"], etc.
flagging_dir: str
default `= ".gradio/flagged"`
path to the di | Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
s ["X", "Y"], in which case the values will be the
list of strings and the labels will ["Flag as X", "Flag as Y"], etc.
flagging_dir: str
default `= ".gradio/flagged"`
path to the directory where flagged data is stored. If the directory does not
exist, it will be created.
flagging_callback: FlaggingCallback | None
default `= None`
either None or an instance of a subclass of FlaggingCallback which will be
called when a sample is flagged. If set to None, an instance of
gradio.flagging.CSVLogger will be created and logs will be saved to a local
CSV file in flagging_dir. Default to None.
analytics_enabled: bool | None
default `= None`
whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED
environment variable if defined, or default to True.
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`
the maximum number of inputs to batch together if this is called from the
queue (only relevant if batch=True)
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
Controls the visibility of the prediction endpoint. Can be "public" (shown in
API docs and callable), "private" (hidden from API docs and not callable), or
"undocumented" (hidden from API docs but callable).
api_name: str | None
default `= None`
defines how the prediction 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, the name of the function will be used.
| Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
ion 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, the name of the function will be used.
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.
allow_duplication: bool
default `= False`
if True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces.
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
`.queue()`, which itself is 1 by default).
additional_inputs: str | Component | list[str | Component] | None
default `= None`
a single Gradio component, or list of Gradio components. Components can either
be passed as instantiated objects, or referred to by their string shortcuts.
These components will be rendered in an accordion below the main input
components. By default, no additional input components will be displayed.
additional_inputs_accordion: str | Accordion | None
default `= None`
if a string is provided, this is the label of the `gr.Accordion` to use to
contain additional inputs. A `gr.Accordion` object can be provided as well to
configure other properties of the container holding the additional inputs.
Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This
parameter is only used if `additional_inputs` is provide | Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
gure other properties of the container holding the additional inputs.
Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This
parameter is only used if `additional_inputs` is provided.
submit_btn: str | Button
default `= "Submit"`
the button to use for submitting inputs. Defaults to a `gr.Button("Submit",
variant="primary")`. This parameter does not apply if the Interface is output-
only, in which case the submit button always displays "Generate". Can be set
to a string (which becomes the button label) or a `gr.Button` object (which
allows for more customization).
stop_btn: str | Button
default `= "Stop"`
the button to use for stopping the interface. Defaults to a `gr.Button("Stop",
variant="stop", visible=False)`. Can be set to a string (which becomes the
button label) or a `gr.Button` object (which allows for more customization).
clear_btn: str | Button | None
default `= "Clear"`
the button to use for clearing the inputs. Defaults to a `gr.Button("Clear",
variant="secondary")`. Can be set to a string (which becomes the button label)
or a `gr.Button` object (which allows for more customization). Can be set to
None, which hides the button.
delete_cache: tuple[int, int] | None
default `= None`
a tuple corresponding [frequency, age] both expressed in number of seconds.
Every `frequency` seconds, the temporary files created by this Blocks instance
will be deleted if more than `age` seconds have passed since the file was
created. For example, setting this to (86400, 86400) will delete temporary
files every day. The cache will be deleted entirely when the server restarts.
If None, no cache deletion will occur.
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" o | Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
`= "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
fill_width: bool
default `= False`
whether to horizontally expand to fill container fully. If False, centers and
constrains app to a maximum width.
time_limit: int | None
default `= 30`
The time limit for the stream to run. Default is 30 seconds. Parameter only
used for streaming images or audio if the interface is live and the input
components are set to "streaming=True".
stream_every: float
default `= 0.5`
The latency (in seconds) at which stream chunks are sent to the backend.
Defaults to 0.5 seconds. Parameter only used for streaming images or audio if
the interface is live and the input components are set to "streaming=True".
deep_link: str | DeepLinkButton | bool | None
default `= None`
a string or `gr.DeepLinkButton` object that creates a unique URL you can use
to share your app and all components **as they currently are** with others.
Automatically enabled on Hugging Face Spaces unless explicitly set to False.
validator: Callable | None
default `= None`
a function that takes in the inputs and can optionally return a gr.validate()
object for each input.
| Initialization | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
hello_worldhello_world_2hello_world_3
| Demos | https://gradio.app/docs/gradio/interface#interface-queue | Gradio - Interface#Interface Queue Docs |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.