text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 183
values | source_page_title
stringclasses 183
values |
|---|---|---|---|
Parameters ▼
value: image_tuple | Callable | None
default `= None`
A tuple of PIL Image, numpy array, path or URL for the default value that
ImageSlider component is going to take, this pair of images should be of equal
size. If a function is provided, the function will be called each time the app
loads to set the initial value of this component.
format: str
default `= "webp"`
File format (e.g. "png" or "gif"). Used to save image if it does not already
have a valid format (e.g. if the image is being returned to the frontend as a
numpy array or PIL Image). The format should be supported by the PIL library.
Applies both when this component is used as an input or output. This parameter
has no effect on SVG files.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed tuple
of image file or numpy array, but will affect the displayed image.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed tuple
of image file or numpy array, but will affect the displayed image.
image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None
default `= "RGB"`
The pixel format and color depth that the image should be loaded and
preprocessed as. "RGB" will load the image as a color image, or "L" as black-
and-white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html
for other supported image modes and their meaning. This parameter has no
effect on SVG or GIF files. If set to None, the image_mode will be inferred
from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The for
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
image_mode will be inferred
from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The format the images are converted to before being passed into the prediction
function. "numpy" converts the images to numpy arrays with shape (height,
width, 3) and values from 0 to 255, "pil" converts the images to PIL image
objects, "filepath" passes str paths to temporary files containing the images.
To support animated GIFs in input, the `type` should be set to "filepath" or
"pil". To support SVGs, the `type` should be set to "filepath".
label: str | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
buttons: list[Literal['download', 'fullscreen']] | None
default `= None`
A list of buttons to show in the top right corner of the component. Valid
options are "download" and "fullscreen". The "download" button allows the user
to download the image. The "fullscreen" button allows the user to view the
image in fullscreen mode. By default, all buttons are shown.
container: bool
default `= True`
If T
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
the user
to download the image. The "fullscreen" button allows the user to view the
image in fullscreen mode. By default, all buttons are shown.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, will allow users to upload and edit an image; if False, can only be
used to display images. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str,
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
nt 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.
slider_position: float
default `= 50`
The position of the slider as a percentage of the width of the image, between
0 and 100.
max_height: int
default `= 500`
The maximum height of the image.
|
Initialization
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.ImageSlider`| "imageslider"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
imageslider
|
Demos
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider 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 ImageSlider component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`ImageSlider.clear(fn, ···)`| This listener is triggered when the user clears
the ImageSlider using the clear button for the component.
`ImageSlider.change(fn, ···)`| Triggered when the value of the ImageSlider
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.
`ImageSlider.stream(fn, ···)`| This listener is triggered when the user
streams the ImageSlider.
`ImageSlider.select(fn, ···)`| Event listener for when the user selects or
deselects the ImageSlider. Uses event data gradio.SelectData to carry `value`
referring to the label of the ImageSlider, and `selected` to refer to state of
the ImageSlider. See EventData documentation on how to use this event data
`ImageSlider.upload(fn, ···)`| This listener is triggered when the user
uploads a file into the ImageSlider.
`ImageSlider.input(fn, ···)`| This listener is triggered when the user changes
the value of the ImageSlider.
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 com
|
Event Listeners
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
n. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animati
|
Event Listeners
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
isplay, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['onc
|
Event Listeners
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
od. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
defau
|
Event Listeners
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
e by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/imageslider
|
Gradio - Imageslider Docs
|
Displays an interactive table of parameters and their descriptions and
default values with syntax highlighting. For each parameter, the user should
provide a type (e.g. a `str`), a human-readable description, and a default
value. As this component does not accept user input, it is rarely used as an
input component. Internally, this component is used to display the parameters
of components in the Custom Component Gallery (<https://www.gradio.app/custom-
components/gallery).>
|
Description
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
**As input component** : (Rarely used) passes value as a `dict[str, dict]`.
The key in the outer dictionary is the parameter name, while the inner
dictionary has keys "type", "description", and "default" for each parameter.
Your function should accept one of these types:
def predict(
value: dict[str, Parameter]
)
...
**As output component** : Expects value as a `dict[str, dict]`. The key in
the outer dictionary is the parameter name, while the inner dictionary has
keys "type", "description", and "default" for each parameter.
Your function should return one of these types:
def predict(···) -> dict[str, Parameter]
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Parameters ▼
value: dict[str, Parameter] | None
default `= None`
A dictionary of dictionaries. The key in the outer dictionary is the parameter
name, while the inner dictionary has keys "type", "description", and "default"
for each parameter. Markdown links are supported in "description".
language: Literal['python', 'typescript']
default `= "python"`
The language to display the code in. One of "python" or "typescript".
linkify: list[str] | None
default `= None`
A list of strings to linkify. If any of these strings is found in the
description, it will be rendered as a link.
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.
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
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
er()
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.
header: str | None
default `= "Parameters"`
The header to display above the table of parameters, also includes a toggle
button that closes/opens all details at once. If None, no header will be
displayed.
anchor_links: bool | str
default `= False`
If True, creates anchor links for each parameter that can be used to link
directly to that parameter. If a string, creates anchor links with the given
string as the prefix to prevent conflicts with other ParamViewer components.
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 content exceeds the height,
the parameter table will scroll vertically while the header remains fixed in
place. If content is shorter than the height, the component will shrink to fit
the content.
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.ParamViewer`| "paramviewer"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer 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 ParamViewer component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`ParamViewer.change(fn, ···)`| Triggered when the value of the ParamViewer
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.
`ParamViewer.upload(fn, ···)`| This listener is triggered when the user
uploads a file into the ParamViewer.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string,
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of l
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
ning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
end js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
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/paramviewer
|
Gradio - Paramviewer Docs
|
Set the static paths to be served by the gradio app.
Static files are are served directly from the file system instead of being
copied. They are served to users with The Content-Disposition HTTP header set
to "inline" when sending these files to users. This indicates that the file
should be displayed directly in the browser window if possible. This function
is useful when you want to serve files that you know will not be modified
during the lifetime of the gradio app (like files used in gr.Examples). By
setting static paths, your app will launch faster and it will consume less
disk space. Calling this function will set the static paths for all gradio
applications defined in the same interpreter session until it is called again
or the session ends.
|
Description
|
https://gradio.app/docs/gradio/set_static_paths
|
Gradio - Set_Static_Paths Docs
|
import gradio as gr
Paths can be a list of strings or pathlib.Path objects
corresponding to filenames or directories.
gr.set_static_paths(paths=["test/test_files/"])
The example files and the default value of the input
will not be copied to the gradio cache and will be served directly.
demo = gr.Interface(
lambda s: s.rotate(45),
gr.Image(value="test/test_files/cheetah1.jpg", type="pil"),
gr.Image(),
examples=["test/test_files/bus.png"],
)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/set_static_paths
|
Gradio - Set_Static_Paths Docs
|
Parameters ▼
paths: str | Path | list[str | Path]
filepath or list of filepaths or directory names to be served by the gradio
app. If it is a directory name, ALL files located within that directory will
be considered static and not moved to the gradio cache. This also means that
ALL files in that directory will be accessible over the network.
|
Initialization
|
https://gradio.app/docs/gradio/set_static_paths
|
Gradio - Set_Static_Paths Docs
|
Creates a navigation bar component for multipage Gradio apps. The navbar
component allows customizing the appearance of the navbar for that page. Only
one Navbar component can exist per page in a Blocks app, and it can be placed
anywhere within the page.
The Navbar component is designed to control the appearance of the navigation
bar in multipage applications. When present in a Blocks app, its properties
override the default navbar behavior.
|
Description
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
**As input component** : The preprocessed input data sent to the user's
function in the backend.
Your function should accept one of these types:
def predict(
value: list[tuple[str, str]] | None
)
...
**As output component** : The output data received by the component from
the user's function in the backend.
Your function should return one of these types:
def predict(···) -> list[tuple[str, str]] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
Parameters ▼
value: list[tuple[str, str]] | None
default `= None`
If a list of tuples of (page_name, page_path) are provided, these additional
pages will be added to the navbar alongside the existing pages defined in the
Blocks app. The page_path can be either a relative path for internal Gradio
app pages (e.g., "analytics") or an absolute URL for external links (e.g.,
"https://twitter.com/username"). Otherwise, only the pages defined using the
`Blocks.route` method will be displayed. Example: [("Dashboard", "dashboard"),
("About", "https://twitter.com/abidlabs")]
visible: bool
default `= True`
If True, the navbar will be visible. If False, the navbar will be hidden.
main_page_name: str | Literal[False]
default `= "Home"`
The title to display in the navbar for the main page of the Gradio. If False,
the main page will not be displayed in the navbar.
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.
|
Initialization
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Navbar`| "navbar"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar 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 Navbar component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Navbar.change(fn, ···)`| Triggered when the value of the Navbar 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.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as
|
Event Listeners
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
oint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
|
Event Listeners
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
`max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
|
Event Listeners
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
hould return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/navbar
|
Gradio - Navbar Docs
|
Creates a code editor for viewing code (as an output component), or for
entering and editing code (as an input component).
|
Description
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
**As input component** : Passes the code entered as a `str`.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a `str` of code.
Your function should return one of these types:
def predict(···) -> tuple[str] | str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
Parameters ▼
value: str | Callable | None
default `= None`
Default value to show in the code editor. If a function is provided, the
function will be called each time the app loads to set the initial value of
this component.
language: Literal['python', 'c', 'cpp', 'markdown', 'latex', 'json', 'html', 'css', 'javascript', 'jinja2', 'typescript', 'yaml', 'dockerfile', 'shell', 'r', 'sql', 'sql-msSQL', 'sql-mySQL', 'sql-mariaDB', 'sql-sqlite', 'sql-cassandra', 'sql-plSQL', 'sql-hive', 'sql-pgSQL', 'sql-gql', 'sql-gpSQL', 'sql-sparkSQL', 'sql-esper'] | None
default `= None`
The language to display the code as. Supported languages listed in
`gr.Code.languages`.
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.
lines: int
default `= 5`
Minimum number of visible lines to show in the code editor.
max_lines: int | None
default `= None`
Maximum number of visible lines to show in the code editor. Defaults to None
and will fill the height of the container.
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.
interactive: bool | None
default `= None`
Whether user should be able to enter code or only view it.
show_label: bool | None
default `= No
|
Initialization
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
component is assigned to.
interactive: bool | None
default `= None`
Whether user should be able to enter code or only view it.
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
|
Initialization
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
ey: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
wrap_lines: bool
default `= False`
If True, will wrap lines to the width of the container when overflow occurs.
Defaults to False.
show_line_numbers: bool
default `= True`
If True, displays line numbers, and if False, hides line numbers.
autocomplete: bool
default `= False`
If True, will show autocomplete suggestions for supported languages. Defaults
to False.
|
Initialization
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Code`| "code"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/code
|
Gradio - Code 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 Code component supports the following event listeners. Each event listener
takes the same parameters, which are listed in the Event Parameters table
below.
Listener| Description
---|---
`Code.languages(fn, ···)`| ['python', 'c', 'cpp', 'markdown', 'latex', 'json',
'html', 'css', 'javascript', 'jinja2', 'typescript', 'yaml', 'dockerfile',
'shell', 'r', 'sql', 'sql-msSQL', 'sql-mySQL', 'sql-mariaDB', 'sql-sqlite',
'sql-cassandra', 'sql-plSQL', 'sql-hive', 'sql-pgSQL', 'sql-gql', 'sql-gpSQL',
'sql-sparkSQL', 'sql-esper', None]
`Code.change(fn, ···)`| Triggered when the value of the Code 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.
`Code.input(fn, ···)`| This listener is triggered when the user changes the
value of the Code.
`Code.focus(fn, ···)`| This listener is triggered when the Code is focused.
`Code.blur(fn, ···)`| This listener is triggered when the Code is
unfocused/blurred.
Event Parameters
Parameters ▼
|
Event Listeners
|
https://gradio.app/docs/gradio/code
|
Gradio - Code Docs
|
The gr.KeyUpData class is a subclass of gr.EventData that specifically
carries information about the `.key_up()` event. When gr.KeyUpData is added as
a type hint to an argument of an event listener method, a gr.KeyUpData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
|
Description
|
https://gradio.app/docs/gradio/keyupdata
|
Gradio - Keyupdata Docs
|
import gradio as gr
def test(value, key_up_data: gr.KeyUpData):
return {
"component value": value,
"input value": key_up_data.input_value,
"key": key_up_data.key
}
with gr.Blocks() as demo:
d = gr.Dropdown(["abc", "def"], allow_custom_value=True)
t = gr.JSON()
d.key_up(test, d, t)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/keyupdata
|
Gradio - Keyupdata Docs
|
Parameters ▼
key: str
The key that was pressed.
input_value: str
The displayed value in the input textbox after the key was pressed. This may
be different than the `value` attribute of the component itself, as the
`value` attribute of some components (e.g. Dropdown) are not updated until the
user presses Enter.
|
Attributes
|
https://gradio.app/docs/gradio/keyupdata
|
Gradio - Keyupdata Docs
|
dropdown_key_up
|
Demos
|
https://gradio.app/docs/gradio/keyupdata
|
Gradio - Keyupdata Docs
|
Group is a layout element within Blocks which groups together children so
that they do not have any padding or margin between them.
|
Description
|
https://gradio.app/docs/gradio/group
|
Gradio - Group Docs
|
with gr.Group():
gr.Textbox(label="First")
gr.Textbox(label="Last")
|
Example Usage
|
https://gradio.app/docs/gradio/group
|
Gradio - Group Docs
|
Parameters ▼
visible: bool | Literal['hidden']
default `= True`
If False, group 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/group
|
Gradio - Group 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
|
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 as
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
hould be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should proc
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
is event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
defaul
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first wit
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
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
|
Component to select a date and (optionally) a time.
|
Description
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
**As input component** : Passes text value as a `str` into the function.
Your function should accept one of these types:
def predict(
value: float | datetime | str | None
)
...
**As output component** : Expects a tuple pair of datetimes.
Your function should return one of these types:
def predict(···) -> float | datetime | str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
Parameters ▼
value: float | str | datetime | None
default `= None`
default value for datetime.
include_time: bool
default `= True`
If True, the component will include time selection. If False, only date
selection will be available.
type: Literal['timestamp', 'datetime', 'string']
default `= "timestamp"`
The type of the value. Can be "timestamp", "datetime", or "string". If
"timestamp", the value will be a number representing the start and end date in
seconds since epoch. If "datetime", the value will be a datetime object. If
"string", the value will be the date entered by the user.
timezone: str | None
default `= None`
The timezone to use for timestamps, such as "US/Pacific" or "Europe/Paris". If
None, the timezone will be the local timezone.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
show_label: bool | None
default `= None`
if True, will display label.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: float | None
default `= None`
If `value` is a callable, run the function 'every' number of seconds while the
client connection is open. Has no effect otherwise. The event can be accessed
(e.g. to cancel it) via this component's .load_event attribute.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in B
|
Initialization
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
nents. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
interactive: bool | None
default `= None`
elem_id: str | None
default `= None`
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
y have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.DateTime`| "datetime"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The DateTime component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`DateTime.change(fn, ···)`| Triggered when the value of the DateTime changes
either because of user input (e.g. a user types in a textbox) OR because of a
function update (e.g. an image receives a value from the output of an event
trigger). See `.input()` for a listener that is only triggered by user input.
`DateTime.submit(fn, ···)`| This listener is triggered when the user presses
the Enter key while the DateTime is focused.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a str
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
ion returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_l
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
rontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
y if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/datetime
|
Gradio - Datetime Docs
|
The Progress class provides a custom progress tracker that is used in a
function signature. To attach a Progress tracker to a function, simply add a
parameter right after the input parameters that has a default value set to a
`gradio.Progress()` instance. The Progress tracker can then be updated in the
function by calling the Progress object or using the `tqdm` method on an
Iterable.
|
Description
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
import gradio as gr
import time
def my_function(x, progress=gr.Progress()):
progress(0, desc="Starting...")
time.sleep(1)
for i in progress.tqdm(range(100)):
time.sleep(0.1)
return x
gr.Interface(my_function, gr.Textbox(), gr.Textbox()).queue().launch()
|
Example Usage
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Parameters ▼
track_tqdm: bool
default `= False`
If True, the Progress object will track any tqdm.tqdm iterations with the tqdm
library in the function.
|
Initialization
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Methods
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Progress.__call__(progress, ···)
Description
%20Copyright%202022%20Fontic
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Updates progress tracker with progress and message text.
Parameters ▼
progress: float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If Tuple, first
number represents steps completed, and second value represents total steps or
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Progress.tqdm(iterable, ···)
Description
%20Copyright%202022%20Fonticons,
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
2'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Attaches progress tracker to iterable, like tqdm.
Parameters ▼
iterable: Iterable | None
iterable to attach progress tracker to.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Progress.__call__(progress, ···)
Description
%20Copyright%202022%20Fontic
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Updates progress tracker with progress and message text.
Parameters ▼
progress: float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If Tuple, first
number represents steps completed, and second value represents total steps or
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Progress.tqdm(iterable, ···)
Description
%20Copyright%202022%20Fonticons,
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
2'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Attaches progress tracker to iterable, like tqdm.
Parameters ▼
iterable: Iterable | None
iterable to attach progress tracker to.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
total number of steps.
unit: str
default `= "steps"`
unit of iterations.
|
tqdm
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Gradio features a built-in theming engine that lets you customize the look
and feel of your app. You can choose from a variety of themes, or create your
own. To do so, pass the `theme=` kwarg to the `Blocks` or `Interface`
constructor. For example:
with gr.Blocks(theme=gr.themes.Soft()) as demo:
...
Gradio comes with a set of prebuilt themes which you can load from
`gr.themes.*`. These are:
* — `gr.themes.Base()`
* — `gr.themes.Default()`
* — `gr.themes.Glass()`
* — `gr.themes.Monochrome()`
* — `gr.themes.Soft()`
Each of these themes set values for hundreds of CSS variables. You can use
prebuilt themes as a starting point for your own custom themes, or you can
create your own themes from scratch. Let’s take a look at each approach.
|
Introduction
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
The easiest way to build a theme is using the Theme Builder. To launch the
Theme Builder locally, run the following code:
import gradio as gr
gr.themes.builder()
You can use the Theme Builder running on Spaces above, though it runs much
faster when you launch it locally via `gr.themes.builder()`.
As you edit the values in the Theme Builder, the app will preview updates
in real time. You can download the code to generate the theme you’ve created
so you can use it in any Gradio app.
In the rest of the guide, we will cover building themes programmatically.
|
Using the Theme Builder
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
Constructor
Although each theme has hundreds of CSS variables, the values for most
these variables are drawn from 8 core variables which can be set through the
constructor of each prebuilt theme. Modifying these 8 arguments allows you to
quickly change the look and feel of your app.
|
Extending Themes via the
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
The first 3 constructor arguments set the colors of the theme and are
`gradio.themes.Color` objects. Internally, these Color objects hold brightness
values for the palette of a single hue, ranging from 50, 100, 200…, 800, 900,
950. Other CSS variables are derived from these 3 colors.
The 3 color constructor arguments are:
* — `primary_hue`: This is the color draws attention in your theme. In the default theme, this is set to `gradio.themes.colors.orange`.
* — `secondary_hue`: This is the color that is used for secondary elements in your theme. In the default theme, this is set to `gradio.themes.colors.blue`.
* — `neutral_hue`: This is the color that is used for text and other neutral elements in your theme. In the default theme, this is set to `gradio.themes.colors.gray`.
You could modify these values using their string shortcuts, such as
with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")) as demo:
...
or you could use the `Color` objects directly, like this:
with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) as demo:
...
Predefined colors are:
* — `slate`
* — `gray`
* — `zinc`
* — `neutral`
* — `stone`
* — `red`
* — `orange`
* — `amber`
* — `yellow`
* — `lime`
* — `green`
* — `emerald`
* — `teal`
* — `cyan`
* — `sky`
* — `blue`
* — `indigo`
* — `violet`
* — `purple`
* — `fuchsia`
* — `pink`
* — `rose`
You could also create your own custom `Color` objects and pass them in.
|
Core Colors
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
The next 3 constructor arguments set the sizing of the theme and are
`gradio.themes.Size` objects. Internally, these Size objects hold pixel size
values that range from `xxs` to `xxl`. Other CSS variables are derived from
these 3 sizes.
* — `spacing_size`: This sets the padding within and spacing between elements. In the default theme, this is set to `gradio.themes.sizes.spacing_md`.
* — `radius_size`: This sets the roundedness of corners of elements. In the default theme, this is set to `gradio.themes.sizes.radius_md`.
* — `text_size`: This sets the font size of text. In the default theme, this is set to `gradio.themes.sizes.text_md`.
You could modify these values using their string shortcuts, such as
with gr.Blocks(theme=gr.themes.Default(spacing_size="sm", radius_size="none")) as demo:
...
or you could use the `Size` objects directly, like this:
with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm, radius_size=gr.themes.sizes.radius_none)) as demo:
...
The predefined size objects are:
* — `radius_none`
* — `radius_sm`
* — `radius_md`
* — `radius_lg`
* — `spacing_sm`
* — `spacing_md`
* — `spacing_lg`
* — `text_sm`
* — `text_md`
* — `text_lg`
You could also create your own custom `Size` objects and pass them in.
|
Core Sizing
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
The final 2 constructor arguments set the fonts of the theme. You can pass
a list of fonts to each of these arguments to specify fallbacks. If you
provide a string, it will be loaded as a system font. If you provide a
`gradio.themes.GoogleFont`, the font will be loaded from Google Fonts.
* — `font`: This sets the primary font of the theme. In the default theme, this is set to `gradio.themes.GoogleFont("Source Sans Pro")`.
* — `font_mono`: This sets the monospace font of the theme. In the default theme, this is set to `gradio.themes.GoogleFont("IBM Plex Mono")`.
You could modify these values such as the following:
with gr.Blocks(theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
...
|
Core Fonts
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
You can also modify the values of CSS variables after the theme has been
loaded. To do so, use the `.set()` method of the theme object to get access to
the CSS variables. For example:
theme = gr.themes.Default(primary_hue="blue").set(
loader_color="FF0000",
slider_color="FF0000",
)
with gr.Blocks(theme=theme) as demo:
...
In the example above, we’ve set the `loader_color` and `slider_color`
variables to `FF0000`, despite the overall `primary_color` using the blue
color palette. You can set any CSS variable that is defined in the theme in
this manner.
Your IDE type hinting should help you navigate these variables. Since there
are so many CSS variables, let’s take a look at how these variables are named
and organized.
|
Extending Themes via `.set()`
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
Conventions
CSS variable names can get quite long, like
`button_primary_background_fill_hover_dark`! However they follow a common
naming convention that makes it easy to understand what they do and to find
the variable you’re looking for. Separated by underscores, the variable name
is made up of:
* — 1. The target element, such as `button`, `slider`, or `block`.
* — 2. The target element type or sub-element, such as `button_primary`, or `block_label`.
* — 3. The property, such as `button_primary_background_fill`, or `block_label_border_width`.
* — 4. Any relevant state, such as `button_primary_background_fill_hover`.
* — 5. If the value is different in dark mode, the suffix `_dark`. For example, `input_border_color_focus_dark`.
Of course, many CSS variable names are shorter than this, such as
`table_border_color`, or `input_shadow`.
|
CSS Variable Naming
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
Though there are hundreds of CSS variables, they do not all have to have
individual values. They draw their values by referencing a set of core
variables and referencing each other. This allows us to only have to modify a
few variables to change the look and feel of the entire theme, while also
getting finer control of individual elements that we may want to modify.
Referencing Core Variables
To reference one of the core constructor variables, precede the variable
name with an asterisk. To reference a core color, use the `*primary_`,
`*secondary_`, or `*neutral_` prefix, followed by the brightness value. For
example:
theme = gr.themes.Default(primary_hue="blue").set(
button_primary_background_fill="*primary_200",
button_primary_background_fill_hover="*primary_300",
)
In the example above, we’ve set the `button_primary_background_fill` and
`button_primary_background_fill_hover` variables to `*primary_200` and
`*primary_300`. These variables will be set to the 200 and 300 brightness
values of the blue primary color palette, respectively.
Similarly, to reference a core size, use the `*spacing_`, `*radius_`, or
`*text_` prefix, followed by the size value. For example:
theme = gr.themes.Default(radius_size="md").set(
button_primary_border_radius="*radius_xl",
)
In the example above, we’ve set the `button_primary_border_radius` variable
to `*radius_xl`. This variable will be set to the `xl` setting of the medium
radius size range.
|
CSS Variable Organization
|
https://gradio.app/docs/gradio/themes
|
Gradio - Themes Docs
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.