text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 179
values | source_page_title
stringclasses 179
values |
---|---|---|---|
Variables can also reference each other. For example, look at the example
below:
theme = gr.themes.Default().set(
button_primary_background_fill="FF0000",
button_primary_background_fill_hover="FF0000",
button_primary_border="FF0000",
)
Having to set these values to a common color is a bit tedious. Instead, we
can reference the `button_primary_background_fill` variable in the
`button_primary_background_fill_hover` and `button_primary_border` variables,
using a `*` prefix.
theme = gr.themes.Default().set(
button_primary_background_fill="FF0000",
button_primary_background_fill_hover="*button_primary_background_fill",
button_primary_border="*button_primary_background_fill",
)
Now, if we change the `button_primary_background_fill` variable, the
`button_primary_background_fill_hover` and `button_primary_border` variables
will automatically update as well.
This is particularly useful if you intend to share your theme - it makes it
easy to modify the theme without having to change every variable.
Note that dark mode variables automatically reference each other. For
example:
theme = gr.themes.Default().set(
button_primary_background_fill="FF0000",
button_primary_background_fill_dark="AAAAAA",
button_primary_border="*button_primary_background_fill",
button_primary_border_dark="*button_primary_background_fill_dark",
)
`button_primary_border_dark` will draw its value from
`button_primary_background_fill_dark`, because dark mode always draw from the
dark version of the variable.
|
Referencing Other Variables
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
Let’s say you want to create a theme from scratch! We’ll go through it step
by step - you can also see the source of prebuilt themes in the gradio source
repo for reference - [here’s the source](https://github.com/gradio-
app/gradio/blob/main/gradio/themes/monochrome.py) for the Monochrome theme.
Our new theme class will inherit from `gradio.themes.Base`, a theme that
sets a lot of convenient defaults. Let’s make a simple demo that creates a
dummy theme called Seafoam, and make a simple app that uses it.
$code_theme_new_step_1
The Base theme is very barebones, and uses `gr.themes.Blue` as it primary
color - you’ll note the primary button and the loading animation are both blue
as a result. Let’s change the defaults core arguments of our app. We’ll
overwrite the constructor and pass new defaults for the core constructor
arguments.
We’ll use `gr.themes.Emerald` as our primary color, and set secondary and
neutral hues to `gr.themes.Blue`. We’ll make our text larger using `text_lg`.
We’ll use `Quicksand` as our default font, loaded from Google Fonts.
$code_theme_new_step_2
See how the primary button and the loading animation are now green? These CSS
variables are tied to the `primary_hue` variable.
Let’s modify the theme a bit more directly. We’ll call the `set()` method to
overwrite CSS variable values explicitly. We can use any CSS logic, and
reference our core constructor arguments using the `*` prefix.
$code_theme_new_step_3
Look how fun our theme looks now! With just a few variable changes, our theme
looks completely different.
You may find it helpful to explore the [source code of the other prebuilt
themes](https://github.com/gradio-app/gradio/blob/main/gradio/themes) to see
how they modified the base theme. You can also find your browser’s Inspector
useful to select elements from the UI and see what CSS variables are being
used in the styles panel.
Sharing Themes
Once you have created a theme, you can upload it to the HuggingFace Hub to
|
Creating a Full Theme
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
ctor
useful to select elements from the UI and see what CSS variables are being
used in the styles panel.
Sharing Themes
Once you have created a theme, you can upload it to the HuggingFace Hub to let
others view it, use it, and build off of it!
|
Creating a Full Theme
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
There are two ways to upload a theme, via the theme class instance or the
command line. We will cover both of them with the previously created `seafoam`
theme.
* Via the class instance
Each theme instance has a method called `push_to_hub` we can use to upload a
theme to the HuggingFace hub.
seafoam.push_to_hub(repo_name="seafoam",
version="0.0.1",
hf_token="<token>")
* Via the command line
First save the theme to disk
seafoam.dump(filename="seafoam.json")
Then use the `upload_theme` command:
upload_theme\
"seafoam.json"\
"seafoam"\
--version "0.0.1"\
--hf_token "<token>"
In order to upload a theme, you must have a HuggingFace account and pass your
[Access Token](https://huggingface.co/docs/huggingface_hub/quick-startlogin)
as the `hf_token` argument. However, if you log in via the [HuggingFace
command line](https://huggingface.co/docs/huggingface_hub/quick-startlogin)
(which comes installed with `gradio`), you can omit the `hf_token` argument.
The `version` argument lets you specify a valid [semantic
version](https://www.geeksforgeeks.org/introduction-semantic-versioning/)
string for your theme. That way your users are able to specify which version
of your theme they want to use in their apps. This also lets you publish
updates to your theme without worrying about changing how previously created
apps look. The `version` argument is optional. If omitted, the next patch
version is automatically applied.
|
Uploading a Theme
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
By calling `push_to_hub` or `upload_theme`, the theme assets will be stored in
a [HuggingFace space](https://huggingface.co/docs/hub/spaces-overview).
The theme preview for our seafoam theme is here: [seafoam
preview](https://huggingface.co/spaces/gradio/seafoam).
|
Theme Previews
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
The [Theme Gallery](https://huggingface.co/spaces/gradio/theme-gallery) shows
all the public gradio themes. After publishing your theme, it will
automatically show up in the theme gallery after a couple of minutes.
You can sort the themes by the number of likes on the space and from most to
least recently created as well as toggling themes between light and dark mode.
|
Discovering Themes
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
To use a theme from the hub, use the `from_hub` method on the `ThemeClass` and
pass it to your app:
my_theme = gr.Theme.from_hub("gradio/seafoam")
with gr.Blocks(theme=my_theme) as demo:
....
You can also pass the theme string directly to `Blocks` or `Interface`
(`gr.Blocks(theme="gradio/seafoam")`)
You can pin your app to an upstream theme version by using semantic versioning
expressions.
For example, the following would ensure the theme we load from the `seafoam`
repo was between versions `0.0.1` and `0.1.0`:
with gr.Blocks(theme="gradio/seafoam@>=0.0.1,<0.1.0") as demo:
....
Enjoy creating your own themes! If you make one you’re proud of, please share
it with the world by uploading it to the hub! If you tag us on
[Twitter](https://twitter.com/gradio) we can give your theme a shout out!
|
Downloading
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
Creates a checkbox that can be set to `True` or `False`. Can be used as an
input to pass a boolean value to a function or as an output to display a
boolean value.
|
Description
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
**As input component** : Passes the status of the checkbox as a `bool`.
Your function should accept one of these types:
def predict(
value: bool | None
)
...
**As output component** : Expects a `bool` value that is set as the status
of the checkbox
Your function should return one of these types:
def predict(···) -> bool | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
Parameters ▼
value: bool | Callable
default `= False`
if True, checked by default. If a function is provided, the function will be
called each time the app loads to set the initial value of this component.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in
|
Initialization
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
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, this checkbox can be checked; if False, checking will be disabled. If
not provided, this is inferred based on whether the component is used as an
input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided
|
Initialization
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
dered 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/checkbox
|
Gradio - Checkbox Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.Checkbox` | "checkbox" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
sentence_builderhello_world_3
Open in 🎢 ↗ import gradio as gr def sentence_builder(quantity, animal,
countries, place, activity_list, morning): return f"""The {quantity} {animal}s
from {" and ".join(countries)} went to the {place} where they {" and
".join(activity_list)} until the {"morning" if morning else "night"}""" demo =
gr.Interface( sentence_builder, [ gr.Slider(2, 20, value=4, label="Count",
info="Choose between 2 and 20"), gr.Dropdown( ["cat", "dog", "bird"],
label="Animal", info="Will add more animals later!" ),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries", info="Where
are they from?"), gr.Radio(["park", "zoo", "road"], label="Location",
info="Where did they go?"), gr.Dropdown( ["ran", "swam", "ate", "slept"],
value=["swam", "slept"], multiselect=True, label="Activity", info="Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ultricies
aliquam, nunc nisl aliquet nunc, eget aliquam nisl nunc vel nisl." ),
gr.Checkbox(label="Morning", info="Did they do it in the morning?"), ],
"text", examples=[ [2, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"],
True], [4, "dog", ["Japan"], "zoo", ["ate", "swam"], False], [10, "bird",
["USA", "Pakistan"], "road", ["ran"], False], [8, "cat", ["Pakistan"], "zoo",
["ate"], True], ] ) if __name__ == "__main__": demo.launch()
import gradio as gr
def sentence_builder(quantity, animal, countries, place, activity_list, morning):
return f"""The {quantity} {animal}s from {" and ".join(countries)} went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
demo = gr.Interface(
sentence_builder,
[
gr.Slider(2, 20, value=4, label="Count", info="Choose between 2 and 20"),
gr.Dropdown(
["cat", "dog", "bird"], label="Animal", info="Will add more animals later!"
),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label=
|
Demos
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
),
gr.Dropdown(
["cat", "dog", "bird"], label="Animal", info="Will add more animals later!"
),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries", info="Where are they from?"),
gr.Radio(["park", "zoo", "road"], label="Location", info="Where did they go?"),
gr.Dropdown(
["ran", "swam", "ate", "slept"], value=["swam", "slept"], multiselect=True, label="Activity", info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, eget aliquam nisl nunc vel nisl."
),
gr.Checkbox(label="Morning", info="Did they do it in the morning?"),
],
"text",
examples=[
[2, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"], True],
[4, "dog", ["Japan"], "zoo", ["ate", "swam"], False],
[10, "bird", ["USA", "Pakistan"], "road", ["ran"], False],
[8, "cat", ["Pakistan"], "zoo", ["ate"], True],
]
)
if __name__ == "__main__":
demo.launch()
Open in 🎢 ↗ import gradio as gr def greet(name, is_morning, temperature):
salutation = "Good morning" if is_morning else "Good evening" greeting =
f"{salutation} {name}. It is {temperature} degrees today" celsius =
(temperature - 32) * 5 / 9 return greeting, round(celsius, 2) demo =
gr.Interface( fn=greet, inputs=["text", "checkbox", gr.Slider(0, 100)],
outputs=["text", "number"], ) if __name__ == "__main__": demo.launch()
import gradio as gr
def greet(name, is_morning, temperature):
salutation = "Good morning" if is_morning else "Good evening"
greeting = f"{salutation} {name}. It is {temperature} degrees today"
celsius = (temperature - 32) * 5 / 9
return greeting, round(celsius, 2)
demo = gr.Interface(
fn=greet,
inputs=["text", "checkbox", gr.Slider(0, 100)],
outp
|
Demos
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
celsius = (temperature - 32) * 5 / 9
return greeting, round(celsius, 2)
demo = gr.Interface(
fn=greet,
inputs=["text", "checkbox", gr.Slider(0, 100)],
outputs=["text", "number"],
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox 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 Checkbox component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`Checkbox.change(fn, ···)` | Triggered when the value of the Checkbox 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.
`Checkbox.input(fn, ···)` | This listener is triggered when the user changes the value of the Checkbox.
`Checkbox.select(fn, ···)` | Event listener for when the user selects or deselects the Checkbox. Uses event data gradio.SelectData to carry `value` referring to the label of the Checkbox, and `selected` to refer to state of the Checkbox. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] |
|
Event Listeners
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
ts 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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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 h
|
Event Listeners
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
ess animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple
|
Event Listeners
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
iteral['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
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 a
|
Event Listeners
|
https://gradio.app/docs/gradio/checkbox
|
Gradio - Checkbox Docs
|
ult `= False`
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/checkbox
|
Gradio - Checkbox Docs
|
Displays text that contains spans that are highlighted by category or
numerical value.
|
Description
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
**As input component** : Passes the value as a list of tuples as a `list[tuple]` into the function. Each `tuple` consists of a `str` substring of the text (so the entire text is included) and `str | float | None` label, which is the category or confidence of that substring.
Your function should accept one of these types:
def predict(
value: list[tuple[str, str | float | None]] | None
)
...
**As output component** : Expects a list of (word, category) tuples, or a
dictionary of two keys: "text", and "entities", which itself is a list of
dictionaries, each of which have the keys: "entity" (or "entity_group"),
"start", and "end"
Your function should return one of these types:
def predict(···) -> list[tuple[str, str | float | None]] | dict | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Parameters ▼
value: list[tuple[str, str | float | None]] | dict | Callable | None
default `= None`
Default value to show. If a function is provided, the function will be called
each time the app loads to set the initial value of this component.
color_map: dict[str, str] | None
default `= None`
A dictionary mapping labels to colors. The colors may be specified as hex
codes or by their names. For example: {"person": "red", "location": "FFEE22"}
show_legend: bool
default `= False`
whether to show span categories in a separate legend or inline.
show_inline_category: bool
default `= True`
If False, will not display span category label. Only applies if
show_legend=False and interactive=False.
combine_adjacent: bool
default `= False`
If True, will merge the labels of adjacent tokens belonging to the same
category.
adjacent_separator: str
default `= ""`
Specifies the separator to be used between tokens if combine_adjacent is True.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
con
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
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.
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
`= 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.
interactive: bool | None
default `= None`
If True, the component will be editable, and allow user to select spans of
text and label them.
rtl: bool
default `= False`
If True, will display the text in right-to-left direction, and the labels in
the legend will also be aligned to the right.
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.HighlightedText` | "highlightedtext" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
diff_texts
Open in 🎢 ↗ from difflib import Differ import gradio as gr def
diff_texts(text1, text2): d = Differ() return [ (token[2:], token[0] if
token[0] != " " else None) for token in d.compare(text1, text2) ] demo =
gr.Interface( diff_texts, [ gr.Textbox( label="Text 1", info="Initial text",
lines=3, value="The quick brown fox jumped over the lazy dogs.", ),
gr.Textbox( label="Text 2", info="Text to compare", lines=3, value="The fast
brown fox jumps over lazy dogs.", ), ], gr.HighlightedText( label="Diff",
combine_adjacent=True, show_legend=True, color_map={"+": "red", "-":
"green"}), theme=gr.themes.Base() ) if __name__ == "__main__": demo.launch()
from difflib import Differ
import gradio as gr
def diff_texts(text1, text2):
d = Differ()
return [
(token[2:], token[0] if token[0] != " " else None)
for token in d.compare(text1, text2)
]
demo = gr.Interface(
diff_texts,
[
gr.Textbox(
label="Text 1",
info="Initial text",
lines=3,
value="The quick brown fox jumped over the lazy dogs.",
),
gr.Textbox(
label="Text 2",
info="Text to compare",
lines=3,
value="The fast brown fox jumps over lazy dogs.",
),
],
gr.HighlightedText(
label="Diff",
combine_adjacent=True,
show_legend=True,
color_map={"+": "red", "-": "green"}),
theme=gr.themes.Base()
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext 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 HighlightedText component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener | Description
---|---
`HighlightedText.change(fn, ···)` | Triggered when the value of the HighlightedText 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.
`HighlightedText.select(fn, ···)` | Event listener for when the user selects or deselects the HighlightedText. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedText, and `selected` to refer to state of the HighlightedText. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
s 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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
on on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
`= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
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.
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
| 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/highlightedtext
|
Gradio - Highlightedtext Docs
|
Load a chat interface from an OpenAI API chat compatible endpoint.
|
Description
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat Docs
|
import gradio as gr
demo = gr.load_chat("http://localhost:11434/v1", model="deepseek-r1")
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat Docs
|
Parameters ▼
base_url: str
The base URL of the endpoint, e.g. "http://localhost:11434/v1/"
model: str
The name of the model you are loading, e.g. "llama3.2"
token: str | None
default `= None`
The API token or a placeholder string if you are using a local model, e.g.
"ollama"
file_types: Literal['text_encoded', 'image'] | list[Literal['text_encoded', 'image']] | None
default `= "text_encoded"`
The file types allowed to be uploaded by the user. "text_encoded" allows
uploading any text-encoded file (which is simply appended to the prompt), and
"image" adds image upload support. Set to None to disable file uploads.
system_message: str | None
default `= None`
The system message to use for the conversation, if any.
streaming: bool
default `= True`
Whether the response should be streamed.
kwargs: <class 'inspect._empty'>
Additional keyword arguments to pass into ChatInterface for customization.
|
Initialization
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat 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
|
Used to render arbitrary Markdown output. Can also render latex enclosed by
dollar signs as well as code blocks with syntax highlighting. Supported
languages are bash, c, cpp, go, java, javascript, json, php, python, rust,
sql, and yaml. As this component does not accept user input, it is rarely used
as an input component.
|
Description
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
**As input component** : Passes the `str` of Markdown corresponding to the
displayed value.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a valid `str` that can be rendered as
Markdown.
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
Parameters ▼
value: str | I18nData | Callable | None
default `= None`
Value to show in Markdown component. 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`
This parameter has no effect
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`
This parameter has no effect.
rtl: bool
default `= False`
If True, sets the direction of the rendered text to right-to-left. Default is
False, which renders text left-to-right.
latex_delimiters: list[dict[str, str | bool]] | None
default `= None`
A list of dicts of the form {"left": open delimiter (str), "right": close
delimiter (str), "display": whether to display in newline (bool)} that will be
used to render LaTeX expressions. If not provided, `latex_delimiters` is set
to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions
enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass
in an empty list to disable LaTeX rendering. For more information, see the
[KaTeX documentation](https://katex.org/docs/autorender.html).
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
|
Initialization
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
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.
sanitize_html: bool
default `= True`
If False, will disable HTML sanitization when converted from markdown. This is
not recommended, as it can lead to security vulnerabilities.
line_breaks: bool
default `= False`
If True, will enable Github-flavored Markdown line breaks in chatbot messages.
If False (default), single new lines will be ignored.
header_links: bool
default `= False`
If True, will automatically create anchors for headings, displaying a link
icon on hover.
height: int | str | None
defaul
|
Initialization
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
nored.
header_links: bool
default `= False`
If True, will automatically create anchors for headings, displaying a link
icon on hover.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. If markdown content exceeds the height, the
component will scroll.
max_height: int | str | None
default `= None`
The maximum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If markdown content exceeds the
height, the component will scroll. If markdown content is shorter than the
height, the component will shrink to fit the content. Will not have any effect
if `height` is set and is smaller than `max_height`.
min_height: int | str | None
default `= None`
The minimum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If markdown content exceeds the
height, the component will expand to fit the content. Will not have any effect
if `height` is set and is larger than `min_height`.
show_copy_button: bool
default `= False`
If True, includes a copy button to copy the text in the Markdown component.
Default is False.
container: bool
default `= False`
If True, the Markdown component will be displayed in a container. Default is
False.
padding: bool
default `= False`
If True, the Markdown component will have a certain padding (set by the
`--block-padding` CSS variable) in all directions. Default is False.
|
Initialization
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.Markdown` | "markdown" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
blocks_helloblocks_kinematics
Open in 🎢 ↗ import gradio as gr def welcome(name): return f"Welcome to Gradio,
{name}!" with gr.Blocks() as demo: gr.Markdown( """ Hello World! Start
typing below to see the output. """) inp = gr.Textbox(placeholder="What is
your name?") out = gr.Textbox() inp.change(welcome, inp, out) if __name__ ==
"__main__": demo.launch()
import gradio as gr
def welcome(name):
return f"Welcome to Gradio, {name}!"
with gr.Blocks() as demo:
gr.Markdown(
"""
Hello World!
Start typing below to see the output.
""")
inp = gr.Textbox(placeholder="What is your name?")
out = gr.Textbox()
inp.change(welcome, inp, out)
if __name__ == "__main__":
demo.launch()
Open in 🎢 ↗ import pandas as pd import numpy as np import gradio as gr def
plot(v, a): g = 9.81 theta = a / 180 * 3.14 tmax = ((2 * v) * np.sin(theta)) /
g timemat = tmax * np.linspace(0, 1, 40) x = (v * timemat) * np.cos(theta) y =
((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2)) df =
pd.DataFrame({"x": x, "y": y}) return df demo = gr.Blocks() with demo:
gr.Markdown( r"Let's do some kinematics! Choose the speed and angle to see the
trajectory. Remember that the range $R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$"
) with gr.Row(): speed = gr.Slider(1, 30, 25, label="Speed") angle =
gr.Slider(0, 90, 45, label="Angle") output = gr.LinePlot( x="x", y="y",
overlay_point=True, tooltip=["x", "y"], x_lim=[0, 100], y_lim=[0, 60],
width=350, height=300, ) btn = gr.Button(value="Run") btn.click(plot, [speed,
angle], output) if __name__ == "__main__": demo.launch()
import pandas as pd
import numpy as np
import gradio as gr
def plot(v, a):
g = 9.81
theta = a / 180 * 3.14
tmax = ((2 * v) * np.sin(theta)) / g
timemat = tmax * np.linspace(0, 1, 40)
x = (v * timemat) * np.cos(theta)
y =
|
Demos
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
g = 9.81
theta = a / 180 * 3.14
tmax = ((2 * v) * np.sin(theta)) / g
timemat = tmax * np.linspace(0, 1, 40)
x = (v * timemat) * np.cos(theta)
y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
df = pd.DataFrame({"x": x, "y": y})
return df
demo = gr.Blocks()
with demo:
gr.Markdown(
r"Let's do some kinematics! Choose the speed and angle to see the trajectory. Remember that the range $R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$"
)
with gr.Row():
speed = gr.Slider(1, 30, 25, label="Speed")
angle = gr.Slider(0, 90, 45, label="Angle")
output = gr.LinePlot(
x="x",
y="y",
overlay_point=True,
tooltip=["x", "y"],
x_lim=[0, 100],
y_lim=[0, 60],
width=350,
height=300,
)
btn = gr.Button(value="Run")
btn.click(plot, [speed, angle], output)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown 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 Markdown component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`Markdown.change(fn, ···)` | Triggered when the value of the Markdown 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.
`Markdown.copy(fn, ···)` | This listener is triggered when the user copies content from the Markdown. Uses event data gradio.CopyData to carry information about the copied content. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when 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: s
|
Event Listeners
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
xt] | 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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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/markdown
|
Gradio - Markdown Docs
|
request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pe
|
Event Listeners
|
https://gradio.app/docs/gradio/markdown
|
Gradio - Markdown Docs
|
event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
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/markdown
|
Gradio - Markdown 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/markdown
|
Gradio - Markdown Docs
|
Creates a component to displays a base image and colored annotations on top
of that image. Annotations can take the from of rectangles (e.g. object
detection) or masks (e.g. image segmentation). As this component does not
accept user input, it is rarely used as an input component.
|
Description
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
**As input component** : Passes its value as a `tuple` consisting of a
`str` filepath to a base image and `list` of annotations. Each annotation
itself is `tuple` of a mask (as a `str` filepath to image) and a `str` label.
Your function should accept one of these types:
def predict(
value: tuple[str, list[tuple[str, str]]] | None
)
...
**As output component** : Expects a a tuple of a base image and list of
annotations: a `tuple[Image, list[Annotation]]`. The `Image` itself can be
`str` filepath, `numpy.ndarray`, or `PIL.Image`. Each `Annotation` is a
`tuple[Mask, str]`. The `Mask` can be either a `tuple` of 4 `int`'s
representing the bounding box coordinates (x1, y1, x2, y2), or 0-1 confidence
mask in the form of a `numpy.ndarray` of the same shape as the image, while
the second element of the `Annotation` tuple is a `str` label.
Your function should return one of these types:
def predict(···) -> tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Parameters ▼
value: tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
default `= None`
Tuple of base image and list of (annotation, label) pairs.
format: str
default `= "webp"`
Format used to save images before it is returned to the front end, such as
'jpeg' or 'png'. This parameter only takes effect when the base image is
returned from the prediction function as a numpy array or a PIL Image. The
format should be supported by the PIL library.
show_legend: bool
default `= True`
If True, will show a legend of the annotations.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
color_map: dict[str, str] | None
default `= None`
A dictionary mapping labels to colors. The colors must be specified as hex
codes.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] |
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ct otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
Relative width compared to adjacent Components in a Row. For example, if
Component A has scale=2, and Component B has scale=1, A will be twice as wide
as B. Should be an integer.
min_width: int
default `= 160`
Minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
show_fullscreen_button: bool
default `= True`
If True, will show a button to allow the image to be viewed in fullscreen
mode.
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.AnnotatedImage` | "annotatedimage" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
image_segmentation
Open in 🎢 ↗ import gradio as gr import numpy as np import random with
gr.Blocks() as demo: section_labels = [ "apple", "banana", "carrot", "donut",
"eggplant", "fish", "grapes", "hamburger", "ice cream", "juice", ] with
gr.Row(): num_boxes = gr.Slider(0, 5, 2, step=1, label="Number of boxes")
num_segments = gr.Slider(0, 5, 1, step=1, label="Number of segments") with
gr.Row(): img_input = gr.Image() img_output = gr.AnnotatedImage(
color_map={"banana": "a89a00", "carrot": "ffae00"} ) section_btn =
gr.Button("Identify Sections") selected_section = gr.Textbox(label="Selected
Section") def section(img, num_boxes, num_segments): sections = [] for a in
range(num_boxes): x = random.randint(0, img.shape[1]) y = random.randint(0,
img.shape[0]) w = random.randint(0, img.shape[1] - x) h = random.randint(0,
img.shape[0] - y) sections.append(((x, y, x + w, y + h), section_labels[a]))
for b in range(num_segments): x = random.randint(0, img.shape[1]) y =
random.randint(0, img.shape[0]) r = random.randint(0, min(x, y, img.shape[1] -
x, img.shape[0] - y)) mask = np.zeros(img.shape[:2]) for i in
range(img.shape[0]): for j in range(img.shape[1]): dist_square = (i - y) ** 2
+ (j - x) ** 2 if dist_square < r**2: mask[i, j] = round((r**2 - dist_square)
/ r**2 * 4) / 4 sections.append((mask, section_labels[b + num_boxes])) return
(img, sections) section_btn.click(section, [img_input, num_boxes,
num_segments], img_output) def select_section(evt: gr.SelectData): return
section_labels[evt.index] img_output.select(select_section, None,
selected_section) if __name__ == "__main__": demo.launch()
import gradio as gr
import numpy as np
import random
with gr.Blocks() as demo:
section_labels = [
"apple",
"banana",
"carrot",
"donut",
"eggplant",
"fish",
"grapes",
"hamburger",
"ice cream",
"juice",
]
w
|
Demos
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
"carrot",
"donut",
"eggplant",
"fish",
"grapes",
"hamburger",
"ice cream",
"juice",
]
with gr.Row():
num_boxes = gr.Slider(0, 5, 2, step=1, label="Number of boxes")
num_segments = gr.Slider(0, 5, 1, step=1, label="Number of segments")
with gr.Row():
img_input = gr.Image()
img_output = gr.AnnotatedImage(
color_map={"banana": "a89a00", "carrot": "ffae00"}
)
section_btn = gr.Button("Identify Sections")
selected_section = gr.Textbox(label="Selected Section")
def section(img, num_boxes, num_segments):
sections = []
for a in range(num_boxes):
x = random.randint(0, img.shape[1])
y = random.randint(0, img.shape[0])
w = random.randint(0, img.shape[1] - x)
h = random.randint(0, img.shape[0] - y)
sections.append(((x, y, x + w, y + h), section_labels[a]))
for b in range(num_segments):
x = random.randint(0, img.shape[1])
y = random.randint(0, img.shape[0])
r = random.randint(0, min(x, y, img.shape[1] - x, img.shape[0] - y))
mask = np.zeros(img.shape[:2])
for i in range(img.shape[0]):
for j in range(img.shape[1]):
dist_square = (i - y) ** 2 + (j - x) ** 2
if dist_square < r**2:
mask[i, j] = round((r**2 - dist_square) / r**2 * 4) / 4
sections.append((mask, section_labels[b + num_boxes]))
return (img, sections)
section_btn.click(section, [img_input, num_boxes, num_segments], img_output)
def select_section(evt: gr.SelectData):
return section_labels[evt.index]
img_output.select(select_s
|
Demos
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ick(section, [img_input, num_boxes, num_segments], img_output)
def select_section(evt: gr.SelectData):
return section_labels[evt.index]
img_output.select(select_section, None, selected_section)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The AnnotatedImage component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener | Description
---|---
`AnnotatedImage.select(fn, ···)` | Event listener for when the user selects or deselects the AnnotatedImage. Uses event data gradio.SelectData to carry `value` referring to the label of the AnnotatedImage, and `selected` to refer to state of the AnnotatedImage. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (d
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ault `= 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 arguments for js
method are values of 'inputs' and 'outputs', return sho
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
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.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
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 sho
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
The gr.CopyData class is a subclass of gr.EventData that specifically
carries information about the `.copy()` event. When gr.CopyData is added as a
type hint to an argument of an event listener method, a gr.CopyData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
|
Description
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
import gradio as gr
def on_copy(copy_data: gr.CopyData):
return f"Copied text: {copy_data.value}"
with gr.Blocks() as demo:
textbox = gr.Textbox("Hello World!")
copied = gr.Textbox()
textbox.copy(on_copy, None, copied)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
Parameters ▼
value: Any
The value that was copied.
|
Attributes
|
https://gradio.app/docs/gradio/copydata
|
Gradio - Copydata Docs
|
Creates a set of checkboxes. Can be used as an input to pass a set of
values to a function or as an output to display values, a subset of which are
selected.
|
Description
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
**As input component** : Passes the list of checked checkboxes as a `list[str | int | float]` or their indices as a `list[int]` into the function, depending on `type`.
Your function should accept one of these types:
def predict(
value: list[str | int | float] | list[int | None]
)
...
**As output component** : Expects a `list[str | int | float]` of values or a single `str | int | float` value, the checkboxes with these values are checked.
Your function should return one of these types:
def predict(···) -> list[str | int | float] | str | int | float | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
Parameters ▼
choices: list[str | int | float | tuple[str, str | int | float]] | None
default `= None`
A list of string or numeric options to select from. An option can also be a
tuple of the form (name, value), where name is the displayed name of the
checkbox button and value is the value to be passed to the function, or
returned by the function.
value: list[str | float | int] | str | float | int | Callable | None
default `= None`
Default selected list of options. If a single choice is selected, it can be
passed in as a string or numeric type. If a function is provided, the function
will be called each time the app loads to set the initial value of this
component.
type: Literal['value', 'index']
default `= "value"`
Type of value to be returned by component. "value" returns the list of strings
of the choices selected, "index" returns the list of indices of the choices
selected.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
|
Initialization
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
nt] | 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_select_all: bool
default `= False`
If True, will display a select/deselect all checkbox next to the label. Only
available when show_label is True.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
Relative width compared to adjacent Components in a Row. For example, if
Component A has scale=2, and Component B has scale=1, A will be twice as wide
as B. Should be an integer.
min_width: int
default `= 160`
Minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
If True, choices in this checkbox group will be checkable; if False, checking
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,
|
Initialization
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.CheckboxGroup` | "checkboxgroup" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
sentence_builder
Open in 🎢 ↗ import gradio as gr def sentence_builder(quantity, animal,
countries, place, activity_list, morning): return f"""The {quantity} {animal}s
from {" and ".join(countries)} went to the {place} where they {" and
".join(activity_list)} until the {"morning" if morning else "night"}""" demo =
gr.Interface( sentence_builder, [ gr.Slider(2, 20, value=4, label="Count",
info="Choose between 2 and 20"), gr.Dropdown( ["cat", "dog", "bird"],
label="Animal", info="Will add more animals later!" ),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries", info="Where
are they from?"), gr.Radio(["park", "zoo", "road"], label="Location",
info="Where did they go?"), gr.Dropdown( ["ran", "swam", "ate", "slept"],
value=["swam", "slept"], multiselect=True, label="Activity", info="Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ultricies
aliquam, nunc nisl aliquet nunc, eget aliquam nisl nunc vel nisl." ),
gr.Checkbox(label="Morning", info="Did they do it in the morning?"), ],
"text", examples=[ [2, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"],
True], [4, "dog", ["Japan"], "zoo", ["ate", "swam"], False], [10, "bird",
["USA", "Pakistan"], "road", ["ran"], False], [8, "cat", ["Pakistan"], "zoo",
["ate"], True], ] ) if __name__ == "__main__": demo.launch()
import gradio as gr
def sentence_builder(quantity, animal, countries, place, activity_list, morning):
return f"""The {quantity} {animal}s from {" and ".join(countries)} went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
demo = gr.Interface(
sentence_builder,
[
gr.Slider(2, 20, value=4, label="Count", info="Choose between 2 and 20"),
gr.Dropdown(
["cat", "dog", "bird"], label="Animal", info="Will add more animals later!"
),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries",
|
Demos
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
gr.Dropdown(
["cat", "dog", "bird"], label="Animal", info="Will add more animals later!"
),
gr.CheckboxGroup(["USA", "Japan", "Pakistan"], label="Countries", info="Where are they from?"),
gr.Radio(["park", "zoo", "road"], label="Location", info="Where did they go?"),
gr.Dropdown(
["ran", "swam", "ate", "slept"], value=["swam", "slept"], multiselect=True, label="Activity", info="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor, nisl eget ultricies aliquam, nunc nisl aliquet nunc, eget aliquam nisl nunc vel nisl."
),
gr.Checkbox(label="Morning", info="Did they do it in the morning?"),
],
"text",
examples=[
[2, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"], True],
[4, "dog", ["Japan"], "zoo", ["ate", "swam"], False],
[10, "bird", ["USA", "Pakistan"], "road", ["ran"], False],
[8, "cat", ["Pakistan"], "zoo", ["ate"], True],
]
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup 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 CheckboxGroup component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`CheckboxGroup.change(fn, ···)` | Triggered when the value of the CheckboxGroup 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.
`CheckboxGroup.input(fn, ···)` | This listener is triggered when the user changes the value of the CheckboxGroup.
`CheckboxGroup.select(fn, ···)` | Event listener for when the user selects or deselects the CheckboxGroup. Uses event data gradio.SelectData to carry `value` referring to the label of the CheckboxGroup, and `selected` to refer to state of the CheckboxGroup. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | Bl
|
Event Listeners
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
ne
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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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 p
|
Event Listeners
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
onent or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions w
|
Event Listeners
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
ed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.rende
|
Event Listeners
|
https://gradio.app/docs/gradio/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
like_user_message: bool
default `= False`
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/checkboxgroup
|
Gradio - Checkboxgroup Docs
|
Walkthrough is a layout element within Blocks that can contain multiple
"Step" Components, which can be used to create a step-by-step workflow.
|
Description
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
with gr.Walkthrough(selected=1) as walkthrough:
with gr.Step("Step 1", id=1):
btn = gr.Button("go to Step 2")
btn.click(lambda: gr.Walkthrough(selected=2), outputs=walkthrough)
with gr.Step("Step 2", id=2):
txt = gr.Textbox("Welcome to Step 2")
|
Example Usage
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
Parameters ▼
selected: int | None
default `= None`
The currently selected step. Must be a number corresponding to the step
number. Defaults to the first step.
visible: bool
default `= True`
If False, Walkthrough will be hidden.
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional string or list of strings that are assigned as the class of this
component in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, this layout will not be rendered in the Blocks context. Should be
used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= None`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
walkthrough
Open in 🎢 ↗ import gradio as gr with gr.Blocks() as demo: with
gr.Walkthrough(selected=0) as walkthrough: with gr.Step("Image", id=0): image
= gr.Image() btn = gr.Button("go to prompt") btn.click(lambda:
gr.Walkthrough(selected=1), outputs=walkthrough) with gr.Step("Prompt", id=1):
prompt = gr.Textbox() btn = gr.Button("generate") btn.click(lambda:
gr.Walkthrough(selected=2), outputs=walkthrough) with gr.Step("Result", id=2):
gr.Image(label="result", interactive=False) if __name__ == "__main__":
demo.launch()
import gradio as gr
with gr.Blocks() as demo:
with gr.Walkthrough(selected=0) as walkthrough:
with gr.Step("Image", id=0):
image = gr.Image()
btn = gr.Button("go to prompt")
btn.click(lambda: gr.Walkthrough(selected=1), outputs=walkthrough)
with gr.Step("Prompt", id=1):
prompt = gr.Textbox()
btn = gr.Button("generate")
btn.click(lambda: gr.Walkthrough(selected=2), outputs=walkthrough)
with gr.Step("Result", id=2):
gr.Image(label="result", interactive=False)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
Methods
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough 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.Walkthrough.change(···)
Description
%20Copyright%202022%20Fonticons,%20In
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Triggered when the value of the Walkthrough 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.
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 parame
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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 ev
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
t `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run 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 thi
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
essing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio cl
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
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.
|
change
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough 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.Walkthrough.select(···)
Description
%20Copyright%202022%20Fonticons,%20In
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Event listener for when the user selects or deselects the Walkthrough. Uses
event data gradio.SelectData to carry `value` referring to the label of the
Walkthrough, and `selected` to refer to state of the Walkthrough. See
EventData documentation on how to use this event data
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 t
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
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 | Literal[False]
default `= None`
defines how the endpoint appears 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 name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
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 r
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
se`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run 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 listen
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
f component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. U
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
st set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
select
|
https://gradio.app/docs/gradio/walkthrough
|
Gradio - Walkthrough Docs
|
Time plots need a datetime column on the x-axis. Here's a simple example with some flight data:
$code_plot_guide_temporal
$demo_plot_guide_temporal
|
Creating a Plot with a pd.Dataframe
|
https://gradio.app/guides/time-plots
|
Data Science And Plots - Time Plots Guide
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.