text stringlengths 0 2k | heading1 stringlengths 4 79 | source_page_url stringclasses 183 values | source_page_title stringclasses 183 values |
|---|---|---|---|
Shortcuts
gradio.CheckboxGroup
Interface String Shortcut `"checkboxgroup"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
sentence_builder
| Demos | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The CheckboxGroup component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
CheckboxGroup.change(fn, ···)
Triggered when the value of the CheckboxGroup changes either because of user
input (e.g. a user types in a textbox) OR because of a function update (e.g.
an image receives a value from the output of an event trigger). See `.input()`
for a listener that is only triggered by user input.
CheckboxGroup.input(fn, ···)
This listener is triggered when the user changes the value of the
CheckboxGroup.
CheckboxGroup.select(fn, ···)
Event listener for when the user selects or deselects the CheckboxGroup. Uses
event data gradio.SelectData to carry `value` referring to the label of the
CheckboxGroup, and `selected` to refer to state of the CheckboxGroup. See
<https://www.gradio.app/main/docs/gradio/eventdata> for more details.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | | Event Listeners | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use | Event Listeners | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
ol
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) | Event Listeners | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
)`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default ` | Event Listeners | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
r this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
| Event Listeners | https://gradio.app/docs/gradio/checkboxgroup | Gradio - Checkboxgroup Docs |
Used to create an upload button, when clicked allows a user to upload files
that satisfy the specified file type or generic files (if file_type not set).
| Description | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
**Using UploadButton as an input component.**
How UploadButton will pass its value to your function:
Type: `bytes | str | list[bytes] | list[str] | None`
Passes the file as a `str` or `bytes` object, or a list of `str` or list of
`bytes` objects, depending on `type` and `file_count`.
Example Code
import gradio as gr
def predict(
value: bytes | str | list[bytes] | list[str] | None
):
process value from the UploadButton component
return "prediction"
interface = gr.Interface(predict, gr.UploadButton(), gr.Textbox())
interface.launch()
**Using UploadButton as an output component**
How UploadButton expects you to return a value:
Type: `str | list[str] | None`
Expects a `str` filepath or URL, or a `list[str]` of filepaths/URLs.
Example Code
import gradio as gr
def predict(text) -> str | list[str] | None
process value to return to the UploadButton component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.UploadButton())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
Parameters ▼
label: str
default `= "Upload a File"`
Text to display on the button. Defaults to "Upload a File".
value: str | I18nData | list[str] | Callable | None
default `= None`
File or list of files to upload by default.
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.
variant: Literal['primary', 'secondary', 'stop']
default `= "secondary"`
'primary' for main call-to-action, 'secondary' for a more subdued style,
'stop' for a stop button.
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
size: Literal['sm', 'md', 'lg']
default `= "lg"`
size of the button. Can be "sm", "md", or "lg".
icon: str | None
default `= None`
URL or path to the icon file to display within the button. If None, no icon
will be displayed.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_widt | Initialization | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
idth: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool
default `= True`
If False, the UploadButton will be in a disabled state.
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
type: Literal['filepath', 'binary']
default `= "filepath"`
Type of value to be returned by component. "file" returns a temporary file
object with the same base name as the uploaded file, whose full path can be
retrieved by file_obj.name, "binary" returns an bytes object.
file_count: Literal['single', 'multiple', 'directory']
| Initialization | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
h the same base name as the uploaded file, whose full path can be
retrieved by file_obj.name, "binary" returns an bytes object.
file_count: Literal['single', 'multiple', 'directory']
default `= "single"`
if single, allows user to upload one file. If "multiple", user uploads
multiple files. If "directory", user uploads all files in selected directory.
Return type will be list for each file in case of "multiple" or "directory".
file_types: list[str] | None
default `= None`
List of type of files to be uploaded. "file" allows any file to be uploaded,
"image" allows only image files to be uploaded, "audio" allows only audio
files to be uploaded, "video" allows only video files to be uploaded, "text"
allows only text files to be uploaded.
| Initialization | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
Shortcuts
gradio.UploadButton
Interface String Shortcut `"uploadbutton"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
upload_and_downloadupload_button
| Demos | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton 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 UploadButton component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
UploadButton.click(fn, ···)
Triggered when the UploadButton is clicked.
UploadButton.upload(fn, ···)
This listener is triggered when the user uploads a file into the UploadButton.
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 t | Event Listeners | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the que | Event Listeners | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
onent), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultane | Event Listeners | https://gradio.app/docs/gradio/uploadbutton | Gradio - Uploadbutton Docs |
t `= "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/uploadbutton | Gradio - Uploadbutton 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.
[Chatbot Specific Events](../../guides/chatbot-specific-events/)
| Attributes | https://gradio.app/docs/gradio/retrydata | Gradio - Retrydata 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.
[Sharing Your App](../../guides/sharing-your-app)
| Initialization | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
This function allows you to pass custom info messages to the user. You can
do so simply by writing `gr.Info('message here')` in your function, and when
that line is executed the custom message will appear in a modal on the demo.
The modal is gray by default and has the heading: "Info." Queue must be
enabled for this behavior; otherwise, the message will be printed to the
console.
| Description | https://gradio.app/docs/gradio/info | Gradio - Info Docs |
import gradio as gr
def hello_world():
gr.Info('This is some info.')
return "hello world"
with gr.Blocks() as demo:
md = gr.Markdown()
demo.load(hello_world, inputs=None, outputs=[md])
demo.queue().launch()
| Example Usage | https://gradio.app/docs/gradio/info | Gradio - Info Docs |
Parameters ▼
message: str
default `= "Info issued."`
The info 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 that the info message should be displayed for. If None
or 0, the message will be displayed indefinitely until the user closes it.
visible: bool
default `= True`
Whether the error message should be displayed in the UI.
title: str
default `= "Info"`
The title to be displayed to the user at the top of the modal.
| Initialization | https://gradio.app/docs/gradio/info | Gradio - Info Docs |
blocks_chained_events
[Alerts](../../guides/alerts)
| Demos | https://gradio.app/docs/gradio/info | Gradio - Info Docs |
Used to render arbitrary Markdown output. Can also render latex enclosed by
dollar signs as well as code blocks with syntax highlighting. Supported
languages are bash, c, cpp, go, java, javascript, json, php, python, rust,
sql, and yaml. As this component does not accept user input, it is rarely used
as an input component.
| Description | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
**Using Markdown as an input component.**
How Markdown will pass its value to your function:
Type: `str | None`
Passes the `str` of Markdown corresponding to the displayed value.
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from the Markdown component
return "prediction"
interface = gr.Interface(predict, gr.Markdown(), gr.Textbox())
interface.launch()
**Using Markdown as an output component**
How Markdown expects you to return a value:
Type: `str | I18nData | None`
Expects a valid `str` that can be rendered as Markdown.
Example Code
import gradio as gr
def predict(text) -> str | I18nData | None
process value to return to the Markdown component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.Markdown())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
Parameters ▼
value: str | I18nData | Callable | None
default `= None`
Value to show in Markdown component. If a function is provided, the function
will be called each time the app loads to set the initial value of this
component.
label: str | I18nData | None
default `= None`
This parameter has no effect
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
This parameter has no effect.
rtl: bool
default `= False`
If True, sets the direction of the rendered text to right-to-left. Default is
False, which renders text left-to-right.
latex_delimiters: list[dict[str, str | bool]] | None
default `= None`
A list of dicts of the form {"left": open delimiter (str), "right": close
delimiter (str), "display": whether to display in newline (bool)} that will be
used to render LaTeX expressions. If not provided, `latex_delimiters` is set
to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions
enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass
in an empty list to disable LaTeX rendering. For more information, see the
[KaTeX documentation](https://katex.org/docs/autorender.html).
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None | Initialization | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
sanitize_html: bool
default `= True`
If False, will disable HTML sanitization when converted from markdown. This is
not recommended, as it can lead to security vulnerabilities.
line_breaks: bool
default `= False`
If True, will enable Github-flavored Markdown line breaks in chatbot messages.
If False (default), single new lines will be ignored.
header_links: bool
default `= False`
If True, will automatically create anchors for headings, displaying a link
icon on hover.
height: int | str | None
defaul | Initialization | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
nored.
header_links: bool
default `= False`
If True, will automatically create anchors for headings, displaying a link
icon on hover.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. If markdown content exceeds the height, the
component will scroll.
max_height: int | str | None
default `= None`
The maximum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If markdown content exceeds the
height, the component will scroll. If markdown content is shorter than the
height, the component will shrink to fit the content. Will not have any effect
if `height` is set and is smaller than `max_height`.
min_height: int | str | None
default `= None`
The minimum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If markdown content exceeds the
height, the component will expand to fit the content. Will not have any effect
if `height` is set and is larger than `min_height`.
buttons: list[Literal['copy']] | None
default `= None`
A list of buttons to show for the component. Currently, the only valid option
is "copy". The "copy" button allows the user to copy the text in the Markdown
component. By default, no buttons are shown.
container: bool
default `= False`
If True, the Markdown component will be displayed in a container. Default is
False.
padding: bool
default `= False`
If True, the Markdown component will have a certain padding (set by the
`--block-padding` CSS variable) in all directions. Default is False.
| Initialization | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
Shortcuts
gradio.Markdown
Interface String Shortcut `"markdown"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
blocks_helloblocks_kinematics
| Demos | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Markdown component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Markdown.change(fn, ···)
Triggered when the value of the Markdown changes either because of user input
(e.g. a user types in a textbox) OR because of a function update (e.g. an
image receives a value from the output of an event trigger). See `.input()`
for a listener that is only triggered by user input.
Markdown.copy(fn, ···)
This listener is triggered when the user copies content from the Markdown.
Uses event data gradio.CopyData to carry information about the copied content.
See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | No | Event Listeners | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
et[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists shou | Event Listeners | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
pp.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values o | Event Listeners | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
fter the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives | Event Listeners | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
ion to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
| Event Listeners | https://gradio.app/docs/gradio/markdown | Gradio - Markdown Docs |
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 |
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 passed. If content exceeds the height, the row
will expand to fit the content. Will not have any effect if `height` is set
and is larger than `min_height`.
equal_height: bool
default `= False`
If True, makes every child element have equal height
show_progress: bool
default `= False`
If True, shows progress animation when being updated.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= None`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
| Initialization | https://gradio.app/docs/gradio/row | Gradio - Row Docs |
The widths of elements in a `Row` can be controlled via a combination of
`scale` and `min_width` arguments that are present in every component.
* `scale` is an integer that defines how an element will take up space in a `Row`. If `scale` is set to 0, the element will not expand to take up space. If `scale` is set to 1 or greater, the element will expand. Multiple elements in a row will expand proportional to their scale. Below, `btn2` will expand twice as much as `btn1`, while `btn0` will not expand at all:
with gr.Blocks() as demo:
with gr.Row():
btn0 = gr.Button("Button 0", scale=0)
btn1 = gr.Button("Button 1", scale=1)
btn2 = gr.Button("Button 2", scale=2)
* `min_width` will set the minimum width the element will take. The Row will wrap if there isn’t sufficient space to satisfy all `min_width` values.
[Controlling Layout](../../guides/controlling-layout/)
| Controlling Width | https://gradio.app/docs/gradio/row | Gradio - Row Docs |
Creates a file explorer component that allows users to browse files on the
machine hosting the Gradio app. As an input component, it also allows users to
select files to be used as input to a function, while as an output component,
it displays selected files.
| Description | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
**Using FileExplorer as an input component.**
How FileExplorer will pass its value to your function:
Type: `list[str] | str | None`
Passes the selected file or directory as a `str` path (relative to `root`) or
`list[str}` depending on `file_count`
Example Code
import gradio as gr
def predict(
value: list[str] | str | None
):
process value from the FileExplorer component
return "prediction"
interface = gr.Interface(predict, gr.FileExplorer(), gr.Textbox())
interface.launch()
**Using FileExplorer as an output component**
How FileExplorer expects you to return a value:
Type: `str | list[str] | None`
Expects function to return a `str` path to a file, or `list[str]` consisting
of paths to files.
Example Code
import gradio as gr
def predict(text) -> str | list[str] | None
process value to return to the FileExplorer component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.FileExplorer())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
Parameters ▼
glob: str
default `= "**/*"`
The glob-style pattern used to select which files to display, e.g. "*" to
match all files, "*.png" to match all .png files, "**/*.txt" to match any .txt
file in any subdirectory, etc. The default value matches all files and folders
recursively. See the Python glob documentation at
https://docs.python.org/3/library/glob.html for more information.
value: str | list[str] | Callable | None
default `= None`
The file (or list of files, depending on the `file_count` parameter) to show
as "selected" when the component is first loaded. If a callable is provided,
it will be called when the app loads to set the initial value of the
component. If not provided, no files are shown as selected.
file_count: Literal['single', 'multiple']
default `= "multiple"`
Whether to allow single or multiple files to be selected. If "single", the
component will return a single absolute file path as a string. If "multiple",
the component will return a list of absolute file paths as a list of strings.
root_dir: str | Path
default `= "."`
Path to root directory to select files from. If not provided, defaults to
current working directory. Raises ValueError if the directory does not exist.
ignore_glob: str | None
default `= None`
The glob-style, case-sensitive pattern that will be used to exclude files from
the list. For example, "*.py" will exclude all .py files from the list. See
the Python glob documentation at https://docs.python.org/3/library/glob.html
for more information.
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 | Initialization | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
onent. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
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.
height: int | str | None
default `= None`
The maximum height of the file component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If more files are uploaded than
can fit in the height, a scrollbar will appear.
max_height: int | str | None
default `= 500`
min_height: int | str | None
default `= None`
interactive: bool | None
default `= None`
if True, will allow users to select file(s); if False, will only display
file | Initialization | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
min_height: int | str | None
default `= None`
interactive: bool | None
default `= None`
if True, will allow users to select file(s); if False, will only 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.
buttons: list[Button] | None
default `= None`
A list of gr.Button() instances to show in the top right corner of the
component. Custom buttons will appear in the toolbar with their configured | Initialization | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
buttons: list[Button] | None
default `= None`
A list of gr.Button() instances to show in the top right corner of the
component. Custom buttons will appear in the toolbar with their configured
icon and/or label, and clicking them will trigger any .click() events
registered on the button.
| Initialization | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
Shortcuts
gradio.FileExplorer
Interface String Shortcut `"fileexplorer"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer 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 FileExplorer component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
FileExplorer.change(fn, ···)
Triggered when the value of the FileExplorer 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.
FileExplorer.input(fn, ···)
This listener is triggered when the user changes the value of the
FileExplorer.
FileExplorer.select(fn, ···)
Event listener for when the user selects or deselects the FileExplorer. Uses
event data gradio.SelectData to carry `value` referring to the label of the
FileExplorer, and `selected` to refer to state of the FileExplorer. See
<https://www.gradio.app/main/docs/gradio/eventdata> for more details.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Comp | Event Listeners | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
text] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queu | Event Listeners | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
lt `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would al | Event Listeners | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
| Event Listeners | https://gradio.app/docs/gradio/fileexplorer | Gradio - Fileexplorer Docs |
ent 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/fileexplorer | Gradio - Fileexplorer Docs |
Button that triggers a Spaces Duplication, when the demo is on Hugging Face
Spaces. Does nothing locally.
| Description | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
**Using DuplicateButton as an input component.**
How DuplicateButton will pass its value to your function:
Type: `str | None`
(Rarely used) the `str` corresponding to the button label when the button is
clicked
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from the DuplicateButton component
return "prediction"
interface = gr.Interface(predict, gr.DuplicateButton(), gr.Textbox())
interface.launch()
**Using DuplicateButton as an output component**
How DuplicateButton expects you to return a value:
Type: `str | None`
string corresponding to the button label
Example Code
import gradio as gr
def predict(text) -> str | None
process value to return to the DuplicateButton component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.DuplicateButton())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
Parameters ▼
value: str
default `= "Duplicate Space"`
default text for the button to display. If a function is provided, the
function will be called each time the app loads to set the initial value of
this component.
every: Timer | float | None
default `= None`
continuously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
variant: Literal['primary', 'secondary', 'stop', 'huggingface']
default `= "huggingface"`
sets the background and text color of the button. Use 'primary' for main call-
to-action buttons, 'secondary' for a more subdued style, 'stop' for a stop
button, 'huggingface' for a black background with white text, consistent with
Hugging Face's button styles.
size: Literal['sm', 'md', 'lg']
default `= "sm"`
size of the button. Can be "sm", "md", or "lg".
icon: str | Path | None
default `= None`
URL or path to the icon file to display within the button. If None, no icon
will be displayed.
link: str | None
default `= None`
URL to open when the button is clicked. If None, no link will be used.
link_target: Literal['_self', '_blank', '_parent', '_top']
default `= "_self"`
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
interactive: bool
default `= True`
if False, the Button will be in a disabled state.
elem_id: str | None
default `= None`
an op | Initialization | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
he layout but still exist in the DOM
interactive: bool
default `= True`
if False, the Button will be in a disabled state.
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
an optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
if False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
scale: int | None
default `= 0`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int | None
default `= None`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respect | Initialization | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
m pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
| Initialization | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
Shortcuts
gradio.DuplicateButton
Interface String Shortcut `"duplicatebutton"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The DuplicateButton component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listeners
DuplicateButton.click(fn, ···)
Triggered when the Button is clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the | Event Listeners | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of | Event Listeners | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Bloc | Event Listeners | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
| Event Listeners | https://gradio.app/docs/gradio/duplicatebutton | Gradio - Duplicatebutton Docs |
Creates a "Sign In" button that redirects the user to sign in with Hugging
Face OAuth. Once the user is signed in, the button will act as a logout
button, and you can retrieve a signed-in user's profile by adding a parameter
of type `gr.OAuthProfile` to any Gradio function. This will only work if this
Gradio app is running in a Hugging Face Space. Permissions for the OAuth app
can be configured in the Spaces README file, as described here:
<https://huggingface.co/docs/hub/en/spaces-oauth.> For local development,
instead of OAuth, the local Hugging Face account that is logged in (via `hf
auth login`) will be available through the `gr.OAuthProfile` object.
| Description | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
**Using LoginButton as an input component.**
How LoginButton will pass its value to your function:
Type: `str | None`
(Rarely used) the `str` corresponding to the button label when the button is
clicked
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from the LoginButton component
return "prediction"
interface = gr.Interface(predict, gr.LoginButton(), gr.Textbox())
interface.launch()
**Using LoginButton as an output component**
How LoginButton expects you to return a value:
Type: `str | None`
string corresponding to the button label
Example Code
import gradio as gr
def predict(text) -> str | None
process value to return to the LoginButton component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.LoginButton())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
Parameters ▼
value: str
default `= "Sign in with Hugging Face"`
logout_value: str
default `= "Logout ({})"`
The text to display when the user is signed in. The string should contain a
placeholder for the username with a call-to-action to logout, e.g. "Logout
({})".
every: Timer | float | None
default `= None`
inputs: Component | list[Component] | set[Component] | None
default `= None`
variant: Literal['primary', 'secondary', 'stop', 'huggingface']
default `= "huggingface"`
size: Literal['sm', 'md', 'lg']
default `= "lg"`
icon: str | Path | None
default `= "/home/runner/work/gradio/gradio/gradio/icons/huggingface-
logo.svg"`
link: str | None
default `= None`
link_target: Literal['_self', '_blank', '_parent', '_top']
default `= "_self"`
visible: bool | Literal['hidden']
default `= True`
interactive: bool
default `= True`
elem_id: str | None
default `= None`
elem_classes: list[str] | str | None
default `= None`
render: bool
default `= True`
key: int | str | tuple[int | str, ...] | None
default `= None`
preserved_by_key: list[str] | str | None
default `= "value"`
scale: int | None
default `= None`
min_width: int | None
default `= None`
| Initialization | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
Shortcuts
gradio.LoginButton
Interface String Shortcut `"loginbutton"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
login_with_huggingface
| Demos | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton 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 LoginButton component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
LoginButton.click(fn, ···)
Triggered when the Button is clicked.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
de | Event Listeners | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
ion: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of compone | Event Listeners | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
um number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue | Event Listeners | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
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.
[Sharing Your App](../../guides/sharing-your-app/)
| Event Listeners | https://gradio.app/docs/gradio/loginbutton | Gradio - Loginbutton Docs |
Creates a slider that ranges from `minimum` to `maximum` with a step size
of `step`.
| Description | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
**Using Slider as an input component.**
How Slider will pass its value to your function:
Type: `float`
Passes slider value as a `float` into the function.
Example Code
import gradio as gr
def predict(
value: float
):
process value from the Slider component
return "prediction"
interface = gr.Interface(predict, gr.Slider(), gr.Textbox())
interface.launch()
**Using Slider as an output component**
How Slider expects you to return a value:
Type: `float | None`
Expects an `int` or `float` returned from function and sets slider value to it
as long as it is within range (otherwise, sets to minimum value).
Example Code
import gradio as gr
def predict(text) -> float | None
process value to return to the Slider component
return value
interface = gr.Interface(predict, gr.Textbox(), gr.Slider())
interface.launch()
| Behavior | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
Parameters ▼
minimum: float
default `= 0`
minimum value for slider. When used as an input, if a user provides a smaller
value, a gr.Error exception is raised by the backend.
maximum: float
default `= 100`
maximum value for slider. When used as an input, if a user provides a larger
value, a gr.Error exception is raised by the backend.
value: float | Callable | None
default `= None`
default value for slider. If a function is provided, the function will be
called each time the app loads to set the initial value of this component.
Ignored if randomized=True.
step: float | None
default `= None`
increment between slider values.
precision: int | None
default `= None`
Precision to round input/output to. If set to 0, will round to nearest integer
and convert type to int. If None, no rounding happens.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
info: str | I18nData | None
default `= None`
additional component description, appears below the label in smaller font.
Supports markdown / HTML syntax.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if | Initialization | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
sed as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, slider will be adjustable; if False, adjusting will be disabled. If
not provided, this is inferred based on whether the component is used as an
input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component l | Initialization | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
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.
randomize: bool
default `= False`
If True, the value of the slider when the app loads is taken uniformly at
random from the range given by the minimum and maximum.
buttons: list[Literal['reset']] | None
default `= None`
A list of buttons to show for the component. Currently, the only valid option
is "reset". The "reset" button allows the user to reset the slider to its
default value. By default, no buttons are shown.
| Initialization | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
Shortcuts
gradio.Slider
Interface String Shortcut `"slider"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
Logarithmic scale
Sliders are linear by default. For parameters that vary over several orders of
magnitude (e.g. learning rate), map the slider value inside your function:
import gradio as gr
def train(lr_exp):
lr = 10 ** lr_exp slider value -5 → lr 0.00001
return f"Training with lr={lr}"
demo = gr.Interface(
fn=train,
inputs=gr.Slider(-5, 0, value=-3, step=0.5, label="Learning rate (log₁₀)"),
outputs="text",
)
Reacting on release only
By default, the slider triggers a `change` event on every movement. For
expensive operations, listen to `release` instead so the function only runs
when the user lets go:
import gradio as gr
with gr.Blocks() as demo:
slider = gr.Slider(0, 100, label="Epochs")
output = gr.Textbox()
slider.release(fn=lambda v: f"Will train for {int(v)} epochs", inputs=slider, outputs=output)
| Common Patterns | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
sentence_builderslider_releaseinterface_random_sliderblocks_random_slider
| Demos | https://gradio.app/docs/gradio/slider | Gradio - Slider 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 Slider component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listeners
Slider.change(fn, ···)
Triggered when the value of the Slider 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.
Slider.input(fn, ···)
This listener is triggered when the user changes the value of the Slider.
Slider.release(fn, ···)
This listener is triggered when the user releases the mouse on this Slider.
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 | Event Listeners | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
| None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None
default `= None`
defines how the endpoint appears in the API docs. Can be a string or None. If
set to a string, the endpoint will be exposed in the API docs with the given
name. If None (default), the name of the function will be used as the API
endpoint.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be | Event Listeners | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
ol
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', ret | Event Listeners | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
plete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by clients), or "undocumented" (hidden from API docs but
callable by clients and via gr.load). If fn is None, api_visibility will
automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main f | Event Listeners | https://gradio.app/docs/gradio/slider | Gradio - Slider Docs |
nction. 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/slider | Gradio - Slider Docs |
This function allows you to pass custom warning messages to the user. You
can do so simply by writing `gr.Warning('message here')` in your function, and
when that line is executed the custom message will appear in a modal on the
demo. The modal is yellow by default and has the heading: "Warning." Queue
must be enabled for this behavior; otherwise, the warning will be printed to
the console using the `warnings` library.
| Description | https://gradio.app/docs/gradio/warning | Gradio - Warning Docs |
import gradio as gr
def hello_world():
gr.Warning('This is a warning message.')
return "hello world"
with gr.Blocks() as demo:
md = gr.Markdown()
demo.load(hello_world, inputs=None, outputs=[md])
demo.queue().launch()
| Example Usage | https://gradio.app/docs/gradio/warning | Gradio - Warning Docs |
Parameters ▼
message: str
default `= "Warning issued."`
The warning 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 that the warning message should be displayed for. If
None or 0, the message will be displayed indefinitely until the user closes
it.
visible: bool
default `= True`
Whether the error message should be displayed in the UI.
title: str
default `= "Warning"`
The title to be displayed to the user at the top of the modal.
| Initialization | https://gradio.app/docs/gradio/warning | Gradio - Warning Docs |
blocks_chained_events
[Alerts](../../guides/alerts)
| Demos | https://gradio.app/docs/gradio/warning | Gradio - Warning 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.
[Creating a Chatbot Fast](../../guides/creating-a-chatbot-fast)
| Initialization | https://gradio.app/docs/gradio/load_chat | Gradio - Load_Chat Docs |
Creates a plot component to display various kinds of plots (matplotlib,
plotly, altair, or bokeh plots are supported). As this component does not
accept user input, it is rarely used as an input component.
| Description | https://gradio.app/docs/gradio/plot | Gradio - Plot Docs |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.