text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 182
values | source_page_title
stringclasses 182
values |
|---|---|---|---|
upload_and_download
|
Demos
|
https://gradio.app/docs/gradio/downloadbutton
|
Gradio - Downloadbutton 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 DownloadButton component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener| Description
---|---
`DownloadButton.click(fn, ···)`| Triggered when the DownloadButton is clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in t
|
Event Listeners
|
https://gradio.app/docs/gradio/downloadbutton
|
Gradio - Downloadbutton Docs
|
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not
|
Event Listeners
|
https://gradio.app/docs/gradio/downloadbutton
|
Gradio - Downloadbutton Docs
|
ze: 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
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_limi
|
Event Listeners
|
https://gradio.app/docs/gradio/downloadbutton
|
Gradio - Downloadbutton Docs
|
an 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/downloadbutton
|
Gradio - Downloadbutton Docs
|
Creates a component to displays a base image and colored annotations on top
of that image. Annotations can take the from of rectangles (e.g. object
detection) or masks (e.g. image segmentation). As this component does not
accept user input, it is rarely used as an input component.
|
Description
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
**As input component** : Passes its value as a `tuple` consisting of a
`str` filepath to a base image and `list` of annotations. Each annotation
itself is `tuple` of a mask (as a `str` filepath to image) and a `str` label.
Your function should accept one of these types:
def predict(
value: tuple[str, list[tuple[str, str]]] | None
)
...
**As output component** : Expects a a tuple of a base image and list of
annotations: a `tuple[Image, list[Annotation]]`. The `Image` itself can be
`str` filepath, `numpy.ndarray`, or `PIL.Image`. Each `Annotation` is a
`tuple[Mask, str]`. The `Mask` can be either a `tuple` of 4 `int`'s
representing the bounding box coordinates (x1, y1, x2, y2), or 0-1 confidence
mask in the form of a `numpy.ndarray` of the same shape as the image, while
the second element of the `Annotation` tuple is a `str` label.
Your function should return one of these types:
def predict(···) -> tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Parameters ▼
value: tuple[np.ndarray | PIL.Image.Image | str, list[tuple[np.ndarray | tuple[int, int, int, int], str]]] | None
default `= None`
Tuple of base image and list of (annotation, label) pairs.
format: str
default `= "webp"`
Format used to save images before it is returned to the front end, such as
'jpeg' or 'png'. This parameter only takes effect when the base image is
returned from the prediction function as a numpy array or a PIL Image. The
format should be supported by the PIL library.
show_legend: bool
default `= True`
If True, will show a legend of the annotations.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
file or numpy array, but will affect the displayed image.
color_map: dict[str, str] | None
default `= None`
A dictionary mapping labels to colors. The colors must be specified as hex
codes.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] |
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
ct otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
Relative width compared to adjacent Components in a Row. For example, if
Component A has scale=2, and Component B has scale=1, A will be twice as wide
as B. Should be an integer.
min_width: int
default `= 160`
Minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
buttons: list[Literal['fullscreen']] | None
default `= None`
A list of buttons to show for the component. Currently, the only valid option
is "fullscreen". The "fullscreen" button allows the user to view the image in
fullscreen mode. By default, all buttons are shown.
|
Initialization
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.AnnotatedImage`| "annotatedimage"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
image_segmentation
|
Demos
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The AnnotatedImage component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener| Description
---|---
`AnnotatedImage.select(fn, ···)`| Event listener for when the user selects or
deselects the AnnotatedImage. Uses event data gradio.SelectData to carry
`value` referring to the label of the AnnotatedImage, and `selected` to refer
to state of the AnnotatedImage. See EventData documentation on how to use this
event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the fu
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
h (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this eve
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
uts', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
he main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/annotatedimage
|
Gradio - Annotatedimage Docs
|
Load a chat interface from an OpenAI API chat compatible endpoint.
|
Description
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat Docs
|
import gradio as gr
demo = gr.load_chat("http://localhost:11434/v1", model="deepseek-r1")
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat Docs
|
Parameters ▼
base_url: str
The base URL of the endpoint, e.g. "http://localhost:11434/v1/"
model: str
The name of the model you are loading, e.g. "llama3.2"
token: str | None
default `= None`
The API token or a placeholder string if you are using a local model, e.g.
"ollama"
file_types: Literal['text_encoded', 'image'] | list[Literal['text_encoded', 'image']] | None
default `= "text_encoded"`
The file types allowed to be uploaded by the user. "text_encoded" allows
uploading any text-encoded file (which is simply appended to the prompt), and
"image" adds image upload support. Set to None to disable file uploads.
system_message: str | None
default `= None`
The system message to use for the conversation, if any.
streaming: bool
default `= True`
Whether the response should be streamed.
kwargs: <class 'inspect._empty'>
Additional keyword arguments to pass into ChatInterface for customization.
|
Initialization
|
https://gradio.app/docs/gradio/load_chat
|
Gradio - Load_Chat Docs
|
Any code in a `if gr.NO_RELOAD` code-block will not be re-evaluated when
the source file is reloaded. This is helpful for importing modules that do not
like to be reloaded (tiktoken, numpy) as well as database connections and long
running set up code.
|
Description
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
import gradio as gr
if gr.NO_RELOAD:
from transformers import pipeline
pipe = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
gr.Interface.from_pipeline(pipe).launch()
|
Example Usage
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
The gr.RetryData class is a subclass of gr.Event data that specifically
carries information about the `.retry()` event. When gr.RetryData is added as
a type hint to an argument of an event listener method, a gr.RetryData 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/retrydata
|
Gradio - Retrydata Docs
|
import gradio as gr
def retry(retry_data: gr.RetryData, history: list[gr.MessageDict]):
history_up_to_retry = history[:retry_data.index]
new_response = ""
for token in api.chat_completion(history):
new_response += token
yield history + [new_response]
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.retry(retry, chatbot, chatbot)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/retrydata
|
Gradio - Retrydata Docs
|
Parameters ▼
index: int | tuple[int, int]
The index of the user message that should be retried.
value: Any
The value of the user message that should be retried.
|
Attributes
|
https://gradio.app/docs/gradio/retrydata
|
Gradio - Retrydata Docs
|
Creates a scatter plot component to display data from a pandas DataFrame.
|
Description
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
**As input component** : The data to display in a line plot.
Your function should accept one of these types:
def predict(
value: AltairPlotData | None
)
...
**As output component** : Expects a pandas DataFrame containing the data to
display in the line plot. The DataFrame should contain at least two columns,
one for the x-axis (corresponding to this component's `x` argument) and one
for the y-axis (corresponding to `y`).
Your function should return one of these types:
def predict(···) -> pd.DataFrame | dict | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
Parameters ▼
value: pd.DataFrame | Callable | None
default `= None`
The pandas dataframe containing the data to display in the plot.
x: str | None
default `= None`
Column corresponding to the x axis. Column can be numeric, datetime, or
string/category.
y: str | None
default `= None`
Column corresponding to the y axis. Column must be numeric.
color: str | None
default `= None`
Column corresponding to series, visualized by color. Column must be
string/category.
title: str | None
default `= None`
The title to display on top of the chart.
x_title: str | None
default `= None`
The title given to the x axis. By default, uses the value of the x parameter.
y_title: str | None
default `= None`
The title given to the y axis. By default, uses the value of the y parameter.
color_title: str | None
default `= None`
The title given to the color legend. By default, uses the value of color
parameter.
x_bin: str | float | None
default `= None`
Grouping used to cluster x values. If x column is numeric, should be number to
bin the x values. If x column is datetime, should be string such as "1h",
"15m", "10s", using "s", "m", "h", "d" suffixes.
y_aggregate: Literal['sum', 'mean', 'median', 'min', 'max', 'count'] | None
default `= None`
Aggregation function used to aggregate y values, used if x_bin is provided or
x is a string/category. Must be one of "sum", "mean", "median", "min", "max".
color_map: dict[str, str] | None
default `= None`
Mapping of series to color names or codes. For example, {"success": "green",
"fail": "FF8888"}.
colors_in_legend: list[str] | None
default `= None`
List containing column names of the series to show in the legend. By default,
all series are shown.
x_lim: list[float | None] | None
default `= None`
A tuple or list containing
|
Initialization
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
ne`
List containing column names of the series to show in the legend. By default,
all series are shown.
x_lim: list[float | None] | None
default `= None`
A tuple or list containing the limits for the x-axis, specified as [x_min,
x_max]. To fix only one of these values, set the other to None, e.g. [0, None]
to scale from 0 to the maximum value. If x column is datetime type, x_lim
should be timestamps.
y_lim: list[float | None]
default `= None`
A tuple of list containing the limits for the y-axis, specified as [y_min,
y_max]. To fix only one of these values, set the other to None, e.g. [0, None]
to scale from 0 to the maximum to value.
x_label_angle: float
default `= 0`
The angle of the x-axis labels in degrees offset clockwise.
y_label_angle: float
default `= 0`
The angle of the y-axis labels in degrees offset clockwise.
x_axis_labels_visible: bool | Literal['hidden']
default `= True`
Whether the x-axis labels should be visible. Can be hidden when many x-axis
labels are present.
caption: str | I18nData | None
default `= None`
The (optional) caption to display below the plot.
sort: Literal['x', 'y', '-x', '-y'] | list[str] | None
default `= None`
The sorting order of the x values, if x column is type string/category. Can be
"x", "y", "-x", "-y", or list of strings that represent the order of the
categories.
tooltip: Literal['axis', 'none', 'all'] | list[str]
default `= "axis"`
The tooltip to display when hovering on a point. "axis" shows the values for
the axis columns, "all" shows all column values, and "none" shows no tooltips.
Can also provide a list of strings representing columns to show in the
tooltip, which will be displayed along with axis values.
height: int | None
default `= None`
The height of the plot in pixels.
label: str | I18nData | None
default `= None`
The (optional) label
|
Initialization
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
ed along with axis values.
height: int | None
default `= None`
The height of the plot in pixels.
label: str | I18nData | None
default `= None`
The (optional) label to display on the top left corner of the plot.
show_label: bool | None
default `= None`
Whether the label should be displayed.
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.
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.
visible: bool | Literal['hidden']
default `= True`
Whether the plot should be visible.
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 a
|
Initialization
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
signed 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.
buttons: list[Literal['fullscreen', 'export']] | None
default `= None`
A list of buttons to show for the component. Valid options are "fullscreen"
and "export". The "fullscreen" button allows the user to view the plot in
fullscreen mode. The "export" button allows the user to export and download
the current view of the plot as a PNG image. By default, no buttons are shown.
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/scatterplot
|
Gradio - Scatterplot Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.ScatterPlot`| "scatterplot"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
scatter_plot_demo
|
Demos
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot 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 ScatterPlot component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`ScatterPlot.select(fn, ···)`| Event listener for when the user selects or
deselects the NativePlot. Uses event data gradio.SelectData to carry `value`
referring to the label of the NativePlot, and `selected` to refer to state of
the NativePlot. See EventData documentation on how to use this event data
`ScatterPlot.double_click(fn, ···)`| Triggered when the NativePlot is double
clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in t
|
Event Listeners
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
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 lists (even if there is only 1 outp
|
Event Listeners
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
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: int | None | Literal['default']
|
Event Listeners
|
https://gradio.app/docs/gradio/scatterplot
|
Gradio - Scatterplot Docs
|
g '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/scatterplot
|
Gradio - Scatterplot Docs
|
e 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/scatterplot
|
Gradio - Scatterplot Docs
|
This class allows you to pass custom error messages to the user. You can do
so by raising a gr.Error("custom message") anywhere in the code, and when that
line is executed the custom message will appear in a modal on the demo.
You can control for how long the error message is displayed with the
`duration` parameter. If it’s `None`, the message will be displayed forever
until the user closes it. If it’s a number, it will be shown for that many
seconds.
You can also hide the error modal from being shown in the UI by setting
`visible=False`.
Below is a demo of how different values of duration control the error,
info, and warning messages. You can see the code
[here](https://huggingface.co/spaces/freddyaboulton/gradio-error-
duration/blob/244331cf53f6b5fa2fd406ece3bf55c6ccb9f5f2/app.pyL17).

|
Description
|
https://gradio.app/docs/gradio/error
|
Gradio - Error Docs
|
import gradio as gr
def divide(numerator, denominator):
if denominator == 0:
raise gr.Error("Cannot divide by zero!")
gr.Interface(divide, ["number", "number"], "number").launch()
|
Example Usage
|
https://gradio.app/docs/gradio/error
|
Gradio - Error Docs
|
Parameters ▼
message: str
default `= "Error raised."`
The error message to be displayed to the user. Can be HTML, which will be
rendered in the modal.
duration: float | None
default `= 10`
The duration in seconds to display the error message. If None or 0, the error
message will be displayed until the user closes it.
visible: bool
default `= True`
Whether the error message should be displayed in the UI.
title: str
default `= "Error"`
The title to be displayed to the user at the top of the error modal.
print_exception: bool
default `= True`
Whether to print traceback of the error to the console when the error is
raised.
|
Initialization
|
https://gradio.app/docs/gradio/error
|
Gradio - Error Docs
|
calculatorblocks_chained_events
|
Demos
|
https://gradio.app/docs/gradio/error
|
Gradio - Error Docs
|
This class is a wrapper over the Dataset component and can be used to
create Examples for Blocks / Interfaces. Populates the Dataset component with
examples and assigns event listener so that clicking on an example populates
the input/output components. Optionally handles example caching for fast
inference.
|
Description
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Parameters ▼
examples: list[Any] | list[list[Any]] | str
example inputs that can be clicked to populate specific components. Should be
nested list, in which the outer list consists of samples and each inner list
consists of an input corresponding to each input component. A string path to a
directory of examples can also be provided but it should be within the
directory with the python file running the gradio app. If there are multiple
input components and a directory is provided, a log.csv file must be present
in the directory to link corresponding inputs.
inputs: Component | list[Component]
the component or list of components corresponding to the examples
outputs: Component | list[Component] | None
default `= None`
optionally, provide the component or list of components corresponding to the
output of the examples. Required if `cache_examples` is not False.
fn: Callable | None
default `= None`
optionally, provide the function to run to generate the outputs corresponding
to the examples. Required if `cache_examples` is not False. Also required if
`run_on_click` is True.
cache_examples: bool | None
default `= None`
If True, caches examples in the server for fast runtime in examples. If
"lazy", then examples are cached (for all users of the app) after their first
use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES
environment variable, which should be either "true" or "false". In HuggingFace
Spaces, this parameter is True (as long as `fn` and `outputs` are also
provided). The default option otherwise is False. Note that examples are
cached separately from Gradio's queue() so certain features, such as
gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
d in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment
variable if defined, or default to "eager".
examples_per_page: int
default `= 10`
how many examples to show per page.
label: str | I18nData | None
default `= "Examples"`
the label to use for the examples component (by default, "Examples")
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM.
run_on_click: bool
default `= False`
if cache_examples is False, clicking on an example does not run the function
when an example is clicked. Set this to True to run the function when an
example is clicked. Has no effect if cache_examples is True.
preprocess: bool
default `= True`
if True, preprocesses the example input before running the prediction function
and caching the output. Only applies if `cache_examples` is not False.
postprocess: bool
default `= True`
if True, postprocesses the example output after running the prediction
function and before caching. Only applies if `cache_examples` is not False.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "undocumented"`
Controls the visibility of the event associated with clicking on the examples.
Can be "public" (shown in API docs and callable), "private" (hidden from API
docs and not callable), or "undocumented" (hidden from API docs but callable).
api_name: str | None
default `= "load_example"`
Defines how the event associated with clicking on the examples appears in the
API docs. Can be a string or None. If set to a string, the endpoint will be
exposed in the API docs with the given name. If None, an auto-generated name
will be u
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
icking on the examples appears in the
API docs. Can be a string or None. If set to a string, the endpoint will be
exposed in the API docs with the given name. If None, an auto-generated name
will be used.
api_description: str | None | Literal[False]
default `= None`
Description of the event associated with clicking on the examples in the API
docs. Can be a string, None, or False. If set to a string, the endpoint will
be exposed in the API docs with the given description. If None, the function's
docstring will be used as the API endpoint description. If False, then no
description will be displayed in the API docs.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. Used only if
cache_examples is not False.
example_labels: list[str] | None
default `= None`
A list of labels for each example. If provided, the length of this list should
be the same as the number of examples, and these labels will be used in the UI
instead of rendering the example values.
visible: bool | Literal['hidden']
default `= True`
If False, the examples component will be hidden in the UI.
preload: int | Literal[False]
default `= 0`
If an integer is provided (and examples are being cached eagerly and none of
the input components have a developer-provided `value`), the example at that
index in the examples list will be preloaded when the Gradio app is first
loaded. If False, no example will be preloaded.
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Parameters ▼
dataset: gradio.Dataset
The `gr.Dataset` component corresponding to this Examples object.
load_input_event: gradio.events.Dependency
The Gradio event that populates the input values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event.
cache_event: gradio.events.Dependency | None
The Gradio event that populates the cached output values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event. This event is `None` if
`cache_examples` if False, and is the same as `load_input_event` if
`cache_examples` is `'lazy'`.
|
Attributes
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
**Updating Examples**
In this demo, we show how to update the examples by updating the samples of
the underlying dataset. Note that this only works if `cache_examples=False` as
updating the underlying dataset does not update the cache.
import gradio as gr
def update_examples(country):
if country == "USA":
return gr.Dataset(samples=[["Chicago"], ["Little Rock"], ["San Francisco"]])
else:
return gr.Dataset(samples=[["Islamabad"], ["Karachi"], ["Lahore"]])
with gr.Blocks() as demo:
dropdown = gr.Dropdown(label="Country", choices=["USA", "Pakistan"], value="USA")
textbox = gr.Textbox()
examples = gr.Examples([["Chicago"], ["Little Rock"], ["San Francisco"]], textbox)
dropdown.change(update_examples, dropdown, examples.dataset)
demo.launch()
|
Examples
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
calculator_blocks
|
Demos
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Creates a component allows users to upload or view 3D Model files (.obj,
.glb, .stl, .gltf, .splat, or .ply).
|
Description
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
**As input component** : Passes the uploaded file as a `str` filepath to
the function.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects function to return a `str` or
`pathlib.Path` filepath of type (.obj, .glb, .stl, or .gltf)
Your function should return one of these types:
def predict(···) -> str | Path | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
Parameters ▼
value: str | Callable | None
default `= None`
path to (.obj, .glb, .stl, .gltf, .splat, or .ply) file to show in model3D
viewer. If a function is provided, the function will be called each time the
app loads to set the initial value of this component.
display_mode: Literal['solid', 'point_cloud', 'wireframe'] | None
default `= None`
the display mode of the 3D model in the scene. Can be "solid" (which renders
the model as a solid object), "point_cloud", or "wireframe". For .splat, or
.ply files, this parameter is ignored, as those files can only be rendered as
solid objects.
clear_color: tuple[float, float, float, float] | None
default `= None`
background color of scene, should be a tuple of 4 floats between 0 and 1
representing RGBA values.
camera_position: tuple[int | float | None, int | float | None, int | float | None]
default `= (None, None, None)`
initial camera position of scene, provided as a tuple of `(alpha, beta,
radius)`. Each value is optional. If provided, `alpha` and `beta` should be in
degrees reflecting the angular position along the longitudinal and latitudinal
axes, respectively. Radius corresponds to the distance from the center of the
object to the camera.
zoom_speed: float
default `= 1`
the speed of zooming in and out of the scene when the cursor wheel is rotated
or when screen is pinched on a mobile device. Should be a positive float,
increase this value to make zooming faster, decrease to make it slower.
Affects the wheelPrecision property of the camera.
pan_speed: float
default `= 1`
the speed of panning the scene when the cursor is dragged or when the screen
is dragged on a mobile device. Should be a positive float, increase this value
to make panning faster, decrease to make it slower. Affects the panSensibility
property of the camera.
height: int | str | None
default `= None`
The height of the model3D c
|
Initialization
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
his value
to make panning faster, decrease to make it slower. Affects the panSensibility
property of the camera.
height: int | str | None
default `= None`
The height of the model3D component, specified in pixels if a number is
passed, or in CSS units if a string is passed.
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.
show_label: bool | None
default `= None`
if True, will display label.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
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 |
|
Initialization
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
reen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, will allow users to upload a file; if False, can only be used to
display files. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
he user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Model3D`| "model3d"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D 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 Model3D component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Model3D.change(fn, ···)`| Triggered when the value of the Model3D 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.
`Model3D.upload(fn, ···)`| This listener is triggered when the user uploads a
file into the Model3D.
`Model3D.edit(fn, ···)`| This listener is triggered when the user edits the
Model3D (e.g. image) using the built-in editor.
`Model3D.clear(fn, ···)`| This listener is triggered when the user clears the
Model3D using the clear button for the component.
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
|
Event Listeners
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
ts,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function s
|
Event Listeners
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | No
|
Event Listeners
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
owed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed
|
Event Listeners
|
https://gradio.app/docs/gradio/model3d
|
Gradio - Model3D Docs
|
nders 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/model3d
|
Gradio - Model3D 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.DeletedFileData class is a subclass of gr.EventData that
specifically carries information about the `.delete()` event. When
gr.DeletedFileData is added as a type hint to an argument of an event listener
method, a gr.DeletedFileData 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/deletedfiledata
|
Gradio - Deletedfiledata Docs
|
import gradio as gr
def test(delete_data: gr.DeletedFileData):
return delete_data.file.path
with gr.Blocks() as demo:
files = gr.File(file_count="multiple")
deleted_file = gr.File()
files.delete(test, None, deleted_file)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/deletedfiledata
|
Gradio - Deletedfiledata Docs
|
Parameters ▼
file: FileData
The file that was deleted, as a FileData object. The str path to the file can
be retrieved with the .path attribute.
|
Attributes
|
https://gradio.app/docs/gradio/deletedfiledata
|
Gradio - Deletedfiledata Docs
|
file_component_events
|
Demos
|
https://gradio.app/docs/gradio/deletedfiledata
|
Gradio - Deletedfiledata Docs
|
Creates a gallery or table to display data samples. This component is
primarily designed for internal use to display examples. However, it can also
be used directly to display a dataset and let users select examples.
|
Description
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
**As input component** : Passes the selected sample either as a `list` of
data corresponding to each input component (if `type` is "value") or as an
`int` index (if `type` is "index"), or as a `tuple` of the index and the data
(if `type` is "tuple").
Your function should accept one of these types:
def predict(
value: int | list | None
)
...
**As output component** : Expects an `int` index or `list` of sample data.
Returns the index of the sample in the dataset or `None` if the sample is not
found.
Your function should return one of these types:
def predict(···) -> list[list]
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
Parameters ▼
label: str | I18nData | None
default `= None`
the label for this component, appears above the component.
show_label: bool
default `= True`
If True, the label will be shown above the component.
components: list[Component] | list[str] | None
default `= None`
Which component types to show in this dataset widget, can be passed in as a
list of string names or Components instances. The following components are
supported in a Dataset: Audio, Checkbox, CheckboxGroup, ColorPicker,
Dataframe, Dropdown, File, HTML, Image, Markdown, Model3D, Number, Radio,
Slider, Textbox, TimeSeries, Video
component_props: list[dict[str, Any]] | None
default `= None`
samples: list[list[Any]] | None
default `= None`
a nested list of samples. Each sublist within the outer list represents a data
sample, and each element within the sublist represents an value for each
component
headers: list[str] | None
default `= None`
Column headers in the Dataset widget, should be the same len as components. If
not provided, inferred from component labels
type: Literal['values', 'index', 'tuple']
default `= "values"`
"values" if clicking on a sample should pass the value of the sample, "index"
if it should pass the index of the sample, or "tuple" if it should pass both
the index and the value of the sample.
layout: Literal['gallery', 'table'] | None
default `= None`
"gallery" if the dataset should be displayed as a gallery with each sample in
a clickable card, or "table" if it should be displayed as a table with each
sample in a row. By default, "gallery" is used if there is a single component,
and "table" is used if there are more than one component. If there are more
than one component, the layout can only be "table".
samples_per_page: int
default `= 10`
how many examples to show per page.
visible: bool | Literal['hidden']
|
Initialization
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
re more
than one component, the layout can only be "table".
samples_per_page: int
default `= 10`
how many examples to show per page.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wi
|
Initialization
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
proxy_url: str | None
default `= None`
The URL of the external Space used to load this component. Set automatically
when using `gr.load()`. This should not be set manually.
sample_labels: list[str] | None
default `= None`
A list of labels for each sample. If provided, the length of this list should
be the same as the number of samples, and these labels will be used in the UI
instead of rendering the sample values.
|
Initialization
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
Class| Interface String Shortcut| Initialization
---|---|---
`gradio.Dataset`| "dataset"| Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
**Updating a Dataset**
In this example, we display a text dataset using `gr.Dataset` and then update
it when the user clicks a button:
import gradio as gr
philosophy_quotes = [
["I think therefore I am."],
["The unexamined life is not worth living."]
]
startup_quotes = [
["Ideas are easy. Implementation is hard"],
["Make mistakes faster."]
]
def show_startup_quotes():
return gr.Dataset(samples=startup_quotes)
with gr.Blocks() as demo:
textbox = gr.Textbox()
dataset = gr.Dataset(components=[textbox], samples=philosophy_quotes)
button = gr.Button()
button.click(show_startup_quotes, None, dataset)
demo.launch()
|
Examples
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Dataset component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener| Description
---|---
`Dataset.click(fn, ···)`| Triggered when the Dataset is clicked.
`Dataset.select(fn, ···)`| Event listener for when the user selects or
deselects the Dataset. Uses event data gradio.SelectData to carry `value`
referring to the label of the Dataset, and `selected` to refer to state of the
Dataset. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If No
|
Event Listeners
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
me: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the t
|
Event Listeners
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
e lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this i
|
Event Listeners
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
or
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/dataset
|
Gradio - Dataset Docs
|
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
|
Mount a gradio.Blocks to an existing FastAPI application.
|
Description
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
from fastapi import FastAPI
import gradio as gr
app = FastAPI()
@app.get("/")
def read_main():
return {"message": "This is your main app"}
io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
app = gr.mount_gradio_app(app, io, path="/gradio")
Then run `uvicorn run:app` from the terminal and navigate to
http://localhost:8000/gradio.
|
Example Usage
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
Parameters ▼
app: fastapi.FastAPI
The parent FastAPI application.
blocks: gradio.Blocks
The blocks object we want to mount to the parent app.
path: str
The path at which the gradio application will be mounted, e.g. "/gradio".
server_name: str
default `= "0.0.0.0"`
The server name on which the Gradio app will be run.
server_port: int
default `= 7860`
The port on which the Gradio app will be run.
footer_links: list[Literal['api', 'gradio', 'settings'] | dict[str, str]] | None
default `= None`
The links to display in the footer of the app. Accepts a list, where each
element of the list must be one of "api", "gradio", or "settings"
corresponding to the API docs, "built with Gradio", and settings pages
respectively. If None, all three links will be shown in the footer. An empty
list means that no footer is shown.
app_kwargs: dict[str, Any] | None
default `= None`
Additional keyword arguments to pass to the underlying FastAPI app as a
dictionary of parameter keys and argument values. For example, `{"docs_url":
"/docs"}`
auth: Callable | tuple[str, str] | list[tuple[str, str]] | None
default `= None`
If provided, username and password (or list of username-password tuples)
required to access the gradio app. Can also provide function that takes
username and password and returns True if valid login.
auth_message: str | None
default `= None`
If provided, HTML message provided on login page for this gradio app.
auth_dependency: Callable[[fastapi.Request], str | None] | None
default `= None`
A function that takes a FastAPI request and returns a string user ID or None.
If the function returns None for a specific request, that user is not
authorized to access the gradio app (they will see a 401 Unauthorized
response). To be used with external authentication systems like OAuth. Cannot
be used with `auth`.
|
Initialization
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
ic request, that user is not
authorized to access the gradio app (they will see a 401 Unauthorized
response). To be used with external authentication systems like OAuth. Cannot
be used with `auth`.
root_path: str | None
default `= None`
The subpath corresponding to the public deployment of this FastAPI
application. For example, if the application is served at
"https://example.com/myapp", the `root_path` should be set to "/myapp". A full
URL beginning with http:// or https:// can be provided, which will be used in
its entirety. Normally, this does not need to provided (even if you are using
a custom `path`). However, if you are serving the FastAPI app behind a proxy,
the proxy may not provide the full path to the Gradio app in the request
headers. In which case, you can provide the root path here.
allowed_paths: list[str] | None
default `= None`
List of complete filepaths or parent directories that this gradio app is
allowed to serve. Must be absolute paths. Warning: if you provide directories,
any files in these directories or their subdirectories are accessible to all
users of your app.
blocked_paths: list[str] | None
default `= None`
List of complete filepaths or parent directories that this gradio app is not
allowed to serve (i.e. users of your app are not allowed to access). Must be
absolute paths. Warning: takes precedence over `allowed_paths` and all other
directories exposed by Gradio by default.
favicon_path: str | None
default `= None`
If a path to a file (.png, .gif, or .ico) is provided, it will be used as the
favicon for this gradio app's page.
show_error: bool
default `= True`
If True, any errors in the gradio app will be displayed in an alert modal and
printed in the browser console log. Otherwise, errors will only be visible in
the terminal session running the Gradio app.
max_file_size: str | int | None
default `= None`
The maximum file size in
|
Initialization
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
browser console log. Otherwise, errors will only be visible in
the terminal session running the Gradio app.
max_file_size: str | int | None
default `= None`
The maximum file size in bytes that can be uploaded. Can be a string of the
form "<value><unit>", where value is any positive integer and unit is one of
"b", "kb", "mb", "gb", "tb". If None, no limit is set.
ssr_mode: bool | None
default `= None`
If True, the Gradio app will be rendered using server-side rendering mode,
which is typically more performant and provides better SEO, but this requires
Node 20+ to be installed on the system. If False, the app will be rendered
using client-side rendering mode. If None, will use GRADIO_SSR_MODE
environment variable or default to False.
node_server_name: str | None
default `= None`
The name of the Node server to use for SSR. If None, will use
GRADIO_NODE_SERVER_NAME environment variable or search for a node binary in
the system.
node_port: int | None
default `= None`
The port on which the Node server should run. If None, will use
GRADIO_NODE_SERVER_PORT environment variable or find a free port.
enable_monitoring: bool | None
default `= None`
pwa: bool | None
default `= None`
i18n: I18n | None
default `= None`
If provided, the i18n instance to use for this gradio app.
mcp_server: bool | None
default `= None`
If True, the MCP server will be launched on the gradio app. If None, will use
GRADIO_MCP_SERVER environment variable or default to False.
theme: Theme | str | None
default `= None`
A Theme object or a string representing a theme. If a string, will look for a
built-in theme with that name (e.g. "soft" or "default"), or will attempt to
load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None,
will use the Default theme.
css: str | None
default `= None`
Custom css as a code stri
|
Initialization
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
or will attempt to
load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None,
will use the Default theme.
css: str | None
default `= None`
Custom css as a code string. This css will be included in the demo webpage.
css_paths: str | Path | list[str | Path] | None
default `= None`
Custom css as a pathlib.Path to a css file or a list of such paths. This css
files will be read, concatenated, and included in the demo webpage. If the
`css` parameter is also set, the css from `css` will be included first.
js: str | Literal[True] | None
default `= None`
Custom js as a code string. The custom js should be in the form of a single js
function. This function will automatically be executed when the page loads.
For more flexibility, use the head parameter to insert js inside <script>
tags.
head: str | None
default `= None`
Custom html code to insert into the head of the demo webpage. This can be used
to add custom meta tags, multiple scripts, stylesheets, etc. to the page.
head_paths: str | Path | list[str | Path] | None
default `= None`
Custom html code as a pathlib.Path to a html file or a list of such paths.
This html files will be read, concatenated, and included in the head of the
demo webpage. If the `head` parameter is also set, the html from `head` will
be included first.
|
Initialization
|
https://gradio.app/docs/gradio/mount_gradio_app
|
Gradio - Mount_Gradio_App Docs
|
Sets up an API or MCP endpoint for a generic function without needing
define events listeners or components. Derives its typing from type hints in
the provided function's signature rather than the components.
|
Description
|
https://gradio.app/docs/gradio/api
|
Gradio - Api Docs
|
import gradio as gr
with gr.Blocks() as demo:
with gr.Row():
input = gr.Textbox()
button = gr.Button("Submit")
output = gr.Textbox()
def fn(a: int, b: int, c: list[str]) -> tuple[int, str]:
return a + b, c[a:b]
gr.api(fn, api_name="add_and_slice")
_, url, _ = demo.launch()
from gradio_client import Client
client = Client(url)
result = client.predict(
a=3,
b=5,
c=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
api_name="/add_and_slice"
)
print(result)
|
Example Usage
|
https://gradio.app/docs/gradio/api
|
Gradio - Api Docs
|
Parameters ▼
fn: Callable | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. The function should be fully typed, and the type
hints will be used to derive the typing information for the API/MCP endpoint.
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
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.
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)
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simult
|
Initialization
|
https://gradio.app/docs/gradio/api
|
Gradio - Api Docs
|
eue
(only relevant if batch=True)
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`
The time limit for the function to run. Parameter only used for the
`.stream()` event.
stream_every: float
default `= 0.5`
The latency (in seconds) at which stream chunks are sent to the backend.
Defaults to 0.5 seconds. Parameter only used for the `.stream()` event.
|
Initialization
|
https://gradio.app/docs/gradio/api
|
Gradio - Api Docs
|
Row is a layout element within Blocks that renders all children
horizontally.
|
Description
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
with gr.Blocks() as demo:
with gr.Row():
gr.Image("lion.jpg", scale=2)
gr.Image("tiger.jpg", scale=1)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
Parameters ▼
variant: Literal['default', 'panel', 'compact']
default `= "default"`
row type, 'default' (no background), 'panel' (gray background color and
rounded corners), or 'compact' (rounded corners and no internal gap).
visible: bool | Literal['hidden']
default `= True`
If False, row 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.
scale: int | None
default `= None`
relative height compared to adjacent elements. 1 or greater indicates the Row
will expand in height, and any child columns will also expand to fill the
height.
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.
height: int | str | None
default `= None`
The height of the row, specified in pixels if a number is passed, or in CSS
units if a string is passed. If content exceeds the height, the row will
scroll vertically. If not set, the row will expand to fit the content.
max_height: int | str | None
default `= None`
The maximum height of the row, specified in pixels if a number is passed, or
in CSS units if a string is passed. If content exceeds the height, the row
will scroll vertically. If content is shorter than the height, the row will
shrink to fit the content. Will not have any effect if `height` is set and is
smaller than `max_height`.
min_height: int | str | None
default `= None`
The minimum height of the row, specified in pixels if a number is passed, or
in CSS units if a string is
|
Initialization
|
https://gradio.app/docs/gradio/row
|
Gradio - Row Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.