text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 178
values | source_page_title
stringclasses 178
values |
---|---|---|---|
es if flagging_mode is "manual". Can either be a list of tuples of
the form (label, value), where label is the string that will be displayed on
the button and value is the string that will be stored in the flagging CSV; or
it can be a list of strings ["X", "Y"], in which case the values will be the
list of strings and the labels will ["Flag as X", "Flag as Y"], etc.
flagging_dir: str
default `= ".gradio/flagged"`
path to the the directory where flagged data is stored. If the directory does
not exist, it will be created.
flagging_callback: FlaggingCallback | None
default `= None`
either None or an instance of a subclass of FlaggingCallback which will be
called when a sample is flagged. If set to None, an instance of
gradio.flagging.CSVLogger will be created and logs will be saved to a local
CSV file in flagging_dir. Default to None.
analytics_enabled: bool | None
default `= None`
whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED
environment variable if defined, or default to True.
batch: bool
default `= False`
if True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
the maximum number of inputs to batch together if this is called from the
queue (only relevant if batch=True)
show_api: bool
default `= True`
whether to show the prediction endpoint in the "view API" page of the Gradio
app, or in the ".view_api()" method of the Gradio clients. Unlike setting
api_name to False, setting show_api to False will still allow downstream apps
as well as the Clients to use this event.
|
Initialization
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
in the ".view_api()" method of the Gradio clients. Unlike setting
api_name to False, setting show_api to False will still allow downstream apps
as well as the Clients to use this event.
api_name: str | Literal[False] | None
default `= "predict"`
defines how the prediction endpoint appears in the API docs. Can be a string,
None, or False. If set to a string, the endpoint will be exposed in the API
docs with the given name. If None, the name of the prediction function will be
used as the API endpoint. If False, the endpoint will not be exposed in the
API docs and downstream apps (including those that `gr.load` this app) will
not be able to use this prediction 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.
allow_duplication: bool
default `= False`
if True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces.
concurrency_limit: int | None | Literal['default']
default `= "default"`
if set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`.queue()`, which itself is 1 by default).
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 web
|
Initialization
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ths: 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.
additional_inputs: str | Component | list[str | Component] | None
default `= None`
a single Gradio component, or list of Gradio components. Components can either
be passed as instantiated objects, or referred to by their string shortcuts.
These components will be rendered in an accordion below the main input
components. By default, no additional input components will be displayed.
additional_inputs_accordion: str | Accordion | None
default `= None`
if a string is provided, this is the label of the `gr.Accordion` to use to
contain additional inputs. A `gr.Accordion` object can be provided as well to
configure other properties of the container holding the additional inputs.
Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This
parameter is only used if `additional_inputs` is provided.
submit_btn:
|
Initialization
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ntainer holding the additional inputs.
Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This
parameter is only used if `additional_inputs` is provided.
submit_btn: str | Button
default `= "Submit"`
the button to use for submitting inputs. Defaults to a `gr.Button("Submit",
variant="primary")`. This parameter does not apply if the Interface is output-
only, in which case the submit button always displays "Generate". Can be set
to a string (which becomes the button label) or a `gr.Button` object (which
allows for more customization).
stop_btn: str | Button
default `= "Stop"`
the button to use for stopping the interface. Defaults to a `gr.Button("Stop",
variant="stop", visible=False)`. Can be set to a string (which becomes the
button label) or a `gr.Button` object (which allows for more customization).
clear_btn: str | Button | None
default `= "Clear"`
the button to use for clearing the inputs. Defaults to a `gr.Button("Clear",
variant="secondary")`. Can be set to a string (which becomes the button label)
or a `gr.Button` object (which allows for more customization). Can be set to
None, which hides the button.
delete_cache: tuple[int, int] | None
default `= None`
a tuple corresponding [frequency, age] both expressed in number of seconds.
Every `frequency` seconds, the temporary files created by this Blocks instance
will be deleted if more than `age` seconds have passed since the file was
created. For example, setting this to (86400, 86400) will delete temporary
files every day. The cache will be deleted entirely when the server restarts.
If None, no cache deletion will occur.
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display,
|
Initialization
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
gress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
fill_width: bool
default `= False`
whether to horizontally expand to fill container fully. If False, centers and
constrains app to a maximum width.
allow_flagging: Literal['never'] | Literal['auto'] | Literal['manual'] | None
default `= None`
time_limit: int | None
default `= 30`
The time limit for the stream to run. Default is 30 seconds. Parameter only
used for streaming images or audio if the interface is live and the input
components are set to "streaming=True".
stream_every: float
default `= 0.5`
The latency (in seconds) at which stream chunks are sent to the backend.
Defaults to 0.5 seconds. Parameter only used for streaming images or audio if
the interface is live and the input components are set to "streaming=True".
deep_link: str | DeepLinkButton | bool | None
default `= None`
a string or `gr.DeepLinkButton` object that creates a unique URL you can use
to share your app and all components **as they currently are** with others.
Automatically enabled on Hugging Face Spaces unless explicitly set to False.
|
Initialization
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
hello_worldhello_world_2hello_world_3
Open in 🎢 ↗ import gradio as gr def greet(name): return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") if __name__
== "__main__": demo.launch()
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
if __name__ == "__main__":
demo.launch()
Open in 🎢 ↗ import gradio as gr def greet(name, intensity): return "Hello, " +
name + "!" * intensity demo = gr.Interface( fn=greet, inputs=["text",
gr.Slider(value=2, minimum=1, maximum=10, step=1)],
outputs=[gr.Textbox(label="greeting", lines=3)], ) if __name__ == "__main__":
demo.launch()
import gradio as gr
def greet(name, intensity):
return "Hello, " + name + "!" * intensity
demo = gr.Interface(
fn=greet,
inputs=["text", gr.Slider(value=2, minimum=1, maximum=10, step=1)],
outputs=[gr.Textbox(label="greeting", lines=3)],
)
if __name__ == "__main__":
demo.launch()
Open in 🎢 ↗ import gradio as gr def greet(name, is_morning, temperature):
salutation = "Good morning" if is_morning else "Good evening" greeting =
f"{salutation} {name}. It is {temperature} degrees today" celsius =
(temperature - 32) * 5 / 9 return greeting, round(celsius, 2) demo =
gr.Interface( fn=greet, inputs=["text", "checkbox", gr.Slider(0, 100)],
outputs=["text", "number"], ) if __name__ == "__main__": demo.launch()
import gradio as gr
def greet(name, is_morning, temperature):
salutation = "Good morning" if is_morning else "Good evening"
greeting = f"{salutation} {name}. It is {temperature} degrees today"
celsius = (temperature - 32) * 5 / 9
return greeting, round(celsius, 2)
demo = gr.Interface(
fn=greet,
inputs=["text", "checkbox", gr.Slider(0, 10
|
Demos
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
grees today"
celsius = (temperature - 32) * 5 / 9
return greeting, round(celsius, 2)
demo = gr.Interface(
fn=greet,
inputs=["text", "checkbox", gr.Slider(0, 100)],
outputs=["text", "number"],
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
Methods
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Interface.launch(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Launches a simple web server that serves the demo. Can also be used to create
a public link used by anyone to access the demo from their browser by setting
share=True.
Example Usage
%20Copyright%202022%20Fonticons,
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
2'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
import gradio as gr
def reverse(text):
return text[::-1]
demo = gr.Interface(reverse, "text", "text")
demo.launch(share=True, auth=("username", "password"))
Parameters ▼
inline: bool | None
default `= None`
whether to display in the gradio app inline in an iframe. Defaults to True in
python notebooks; False otherwise.
inbrowser: bool
default `= False`
whether to automatically launch the gradio app in a new tab on the de
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
pp inline in an iframe. Defaults to True in
python notebooks; False otherwise.
inbrowser: bool
default `= False`
whether to automatically launch the gradio app in a new tab on the default
browser.
share: bool | None
default `= None`
whether to create a publicly shareable link for the gradio app. Creates an SSH
tunnel to make your UI accessible from anywhere. If not provided, it is set to
False by default every time, except when running in Google Colab. When
localhost is not accessible (e.g. Google Colab), setting share=False is not
supported. Can be set by environment variable GRADIO_SHARE=True.
debug: bool
default `= False`
if True, blocks the main thread from running. If running in Google Colab, this
is needed to print the errors in the cell output.
max_threads: int
default `= 40`
the maximum number of total threads that the Gradio app can generate in
parallel. The default is inherited from the starlette library (currently 40).
auth: Callable[[str, str], bool] | tuple[str, str] | list[tuple[str, str]] | None
default `= None`
If provided, username and password (or list of username-password tuples)
required to access 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.
prevent_thread_lock: bool
default `= False`
By default, the gradio app blocks the main thread while the server is running.
If set to True, the gradio app will not block and the gradio server will
terminate as soon as the script finishes.
show_error: bool
default `= False`
If True, any errors in the gradio app will be displayed in an alert modal and
printed in the browser console log. They will also be displayed in the alert
modal of downstream apps that gr.load() this app.
server_name: str | None
default `= No
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
an alert modal and
printed in the browser console log. They will also be displayed in the alert
modal of downstream apps that gr.load() this app.
server_name: str | None
default `= None`
to make app accessible on local network, set this to "0.0.0.0". Can be set by
environment variable GRADIO_SERVER_NAME. If None, will use "127.0.0.1".
server_port: int | None
default `= None`
will start gradio app on this port (if available). Can be set by environment
variable GRADIO_SERVER_PORT. If None, will search for an available port
starting at 7860.
height: int
default `= 500`
The height in pixels of the iframe element containing the gradio app (used if
inline=True)
width: int | str
default `= "100%"`
The width in pixels of the iframe element containing the gradio app (used if
inline=True)
favicon_path: str | Path | None
default `= None`
If a path to a file (.png, .gif, or .ico) is provided, it will be used as the
favicon for the web page.
ssl_keyfile: str | None
default `= None`
If a path to a file is provided, will use this as the private key file to
create a local server running on https.
ssl_certfile: str | None
default `= None`
If a path to a file is provided, will use this as the signed certificate for
https. Needs to be provided if ssl_keyfile is provided.
ssl_keyfile_password: str | None
default `= None`
If a password is provided, will use this with the ssl certificate for https.
ssl_verify: bool
default `= True`
If False, skips certificate validation which allows self-signed certificates
to be used.
quiet: bool
default `= False`
If True, suppresses most print statements.
show_api: bool
default `= True`
If True, shows the api docs in the footer of the app. Default True.
allowed_paths: list[str] | None
default `= None`
List of complete filepaths or parent di
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
: bool
default `= True`
If True, shows the api docs in the footer of the app. Default True.
allowed_paths: list[str] | None
default `= None`
List of complete filepaths or parent directories that gradio 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. Can be set by comma separated environment variable
GRADIO_ALLOWED_PATHS. These files are generally assumed to be secure and will
be displayed in the browser when possible.
blocked_paths: list[str] | None
default `= None`
List of complete filepaths or parent directories that gradio 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. Can be set by comma separated
environment variable GRADIO_BLOCKED_PATHS.
root_path: str | None
default `= None`
The root path (or "mount point") of the application, if it's not served from
the root ("/") of the domain. Often used when the application is behind a
reverse proxy that forwards requests to the 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 as the root path in its entirety. Can be set by
environment variable GRADIO_ROOT_PATH. Defaults to "".
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"}`
state_session_capacity: int
default `= 10000`
The maximum number of sessions whose information to store in memory. If the
number of sessions exceeds this number, the oldest sessions will be removed.
Reduce capac
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
_capacity: int
default `= 10000`
The maximum number of sessions whose information to store in memory. If the
number of sessions exceeds this number, the oldest sessions will be removed.
Reduce capacity to reduce memory usage when using gradio.State or returning
updated components from functions. Defaults to 10000.
share_server_address: str | None
default `= None`
Use this to specify a custom FRP server and port for sharing Gradio apps (only
applies if share=True). If not provided, will use the default FRP server at
https://gradio.live. See https://github.com/huggingface/frp for more
information.
share_server_protocol: Literal['http', 'https'] | None
default `= None`
Use this to specify the protocol to use for the share links. Defaults to
"https", unless a custom share_server_address is provided, in which case it
defaults to "http". If you are using a custom share_server_address and want to
use https, you must set this to "https".
share_server_tls_certificate: str | None
default `= None`
The path to a TLS certificate file to use when connecting to a custom share
server. This parameter is not used with the default FRP server at
https://gradio.live. Otherwise, you must provide a valid TLS certificate file
(e.g. a "cert.pem") relative to the current working directory, or the
connection will not use TLS encryption, which is insecure.
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 app (they will see a 401 Unauthorized response). To
be used with external authentication systems like OAuth. Cannot be used with
`auth`.
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
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ed with
`auth`.
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.
enable_monitoring: bool | None
default `= None`
Enables traffic monitoring of the app through the /monitoring endpoint. By
default is None, which enables this endpoint. If explicitly True, will also
print the monitoring URL to the console. If False, will disable monitoring
altogether.
strict_cors: bool
default `= True`
If True, prevents external domains from making requests to a Gradio server
running on localhost. If False, allows requests to localhost that originate
from localhost but also, crucially, from "null". This parameter should
normally be True to prevent CSRF attacks but may need to be False when
embedding a *locally-running Gradio app* using web components.
node_server_name: str | None
default `= None`
node_port: int | None
default `= None`
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.
pwa: bool | None
default `= None`
If True, the Gradio app will be set up as an installable PWA (Progressive Web
App). If set to None (default behavior), then the PWA feature will be enabled
if this Gradio app is launched on Spaces, but not otherwise.
mcp_server: bool | None
default `= None`
If True, the Gradio app will be set up as an MCP server and documented
functions will be added as MCP tools. If None (default behavior), then the
GRADIO_M
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
mcp_server: bool | None
default `= None`
If True, the Gradio app will be set up as an MCP server and documented
functions will be added as MCP tools. If None (default behavior), then the
GRADIO_MCP_SERVER environment variable will be used to determine if the MCP
server should be enabled (which is "True" on Hugging Face Spaces).
i18n: I18n | None
default `= None`
An I18n instance containing custom translations, which are used to translate
strings in our components (e.g. the labels of components or Markdown strings).
This feature can only be used to translate static text in the frontend, not
values in the backend.
|
launch
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Interface.load(block, ···)
Description
%20Copyright%202022%20Fonticons,%2
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
This listener is triggered when the Interface initially loads in the browser.
Parameters ▼
block: Block | None
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 correspondin
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is 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
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
w the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this 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 met
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
f other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api w
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ew_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
|
load
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Interface.from_pipeline(pipeline, ···)
Description
%20Copyright%202022%20
|
from_pipeline
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
20640%20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Class method that constructs an Interface from a Hugging Face
transformers.Pipeline or diffusers.DiffusionPipeline object. The input and
output components are automatically determined from the pipeline.
Example Usage
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
import gradio as gr
from transformers import pipeline
pipe = pipeline("image-classification")
gr.Interface.from_pipeline(pipe).launch()
Parameters ▼
pipeline: Pipeline | DiffusionPipeline
the pipeline object to use.
|
from_pipeline
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ne object to use.
|
from_pipeline
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Interface.integrate(···)
Description
%20Copyright%202022%20Fonticons,%20I
|
integrate
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
A catch-all method for integrating with other libraries. This method should be
run after launch()
Parameters ▼
comet_ml: <class 'inspect._empty'>
default `= None`
If a comet_ml Experiment object is provided, will integrate with the
experiment and appear on Comet dashboard
wandb: ModuleType | None
default `= None`
If the wandb module is provided, will integrate with it and appear on WandB
dashboard
mlflow: ModuleType | None
default `= None`
|
integrate
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
wandb: ModuleType | None
default `= None`
If the wandb module is provided, will integrate with it and appear on WandB
dashboard
mlflow: ModuleType | None
default `= None`
If the mlflow module is provided, will integrate with the experiment and
appear on ML Flow dashboard
|
integrate
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Interface.queue(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.%
|
queue
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
By enabling the queue you can control when users know their position in the
queue, and set a limit on maximum number of events allowed.
Example Usage
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.
|
queue
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
ro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
demo = gr.Interface(image_generator, gr.Textbox(), gr.Image())
demo.queue(max_size=20)
demo.launch()
Parameters ▼
status_update_rate: float | Literal['auto']
default `= "auto"`
If "auto", Queue will send status estimations to all clients whenever a job is
finished. Otherwise Queue will send status at regular intervals set by this
parameter as the number of seconds.
api_open: bool | None
default `= None`
If True, the REST routes of the backend will be open, allowin
|
queue
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
send status at regular intervals set by this
parameter as the number of seconds.
api_open: bool | None
default `= None`
If True, the REST routes of the backend will be open, allowing requests made
directly to those endpoints to skip the queue.
max_size: int | None
default `= None`
The maximum number of events the queue will store at any given moment. If the
queue is full, new events will not be added and a user will receive a message
saying that the queue is full. If None, the queue size will be unlimited.
default_concurrency_limit: int | None | Literal['not_set']
default `= "not_set"`
The default value of `concurrency_limit` to use for event listeners that don't
specify a value. Can be set by environment variable
GRADIO_DEFAULT_CONCURRENCY_LIMIT. Defaults to 1 if not set otherwise.
|
queue
|
https://gradio.app/docs/gradio/interface
|
Gradio - Interface Docs
|
This class is a wrapper over the Dataset component and can be used to
create Examples for Blocks / Interfaces. Populates the Dataset component with
examples and assigns event listener so that clicking on an example populates
the input/output components. Optionally handles example caching for fast
inference.
|
Description
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Parameters ▼
examples: list[Any] | list[list[Any]] | str
example inputs that can be clicked to populate specific components. Should be
nested list, in which the outer list consists of samples and each inner list
consists of an input corresponding to each input component. A string path to a
directory of examples can also be provided but it should be within the
directory with the python file running the gradio app. If there are multiple
input components and a directory is provided, a log.csv file must be present
in the directory to link corresponding inputs.
inputs: Component | list[Component]
the component or list of components corresponding to the examples
outputs: Component | list[Component] | None
default `= None`
optionally, provide the component or list of components corresponding to the
output of the examples. Required if `cache_examples` is not False.
fn: Callable | None
default `= None`
optionally, provide the function to run to generate the outputs corresponding
to the examples. Required if `cache_examples` is not False. Also required if
`run_on_click` is True.
cache_examples: bool | None
default `= None`
If True, caches examples in the server for fast runtime in examples. If
"lazy", then examples are cached (for all users of the app) after their first
use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES
environment variable, which should be either "true" or "false". In HuggingFace
Spaces, this parameter is True (as long as `fn` and `outputs` are also
provided). The default option otherwise is False. Note that examples are
cached separately from Gradio's queue() so certain features, such as
gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
d in Gradio's
UI for cached examples.
cache_mode: Literal['eager', 'lazy'] | None
default `= None`
if "lazy", examples are cached after their first use. If "eager", all examples
are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment
variable if defined, or default to "eager".
examples_per_page: int
default `= 10`
how many examples to show per page.
label: str | I18nData | None
default `= "Examples"`
the label to use for the examples component (by default, "Examples")
elem_id: str | None
default `= None`
an optional string that is assigned as the id of this component in the HTML
DOM.
run_on_click: bool
default `= False`
if cache_examples is False, clicking on an example does not run the function
when an example is clicked. Set this to True to run the function when an
example is clicked. Has no effect if cache_examples is True.
preprocess: bool
default `= True`
if True, preprocesses the example input before running the prediction function
and caching the output. Only applies if `cache_examples` is not False.
postprocess: bool
default `= True`
if True, postprocesses the example output after running the prediction
function and before caching. Only applies if `cache_examples` is not False.
show_api: bool
default `= False`
Whether to show the event associated with clicking on the examples in the
"view API" page of the Gradio app, or in the ".view_api()" method of the
Gradio clients.
api_name: str | Literal[False]
default `= "load_example"`
Defines how the event associated with clicking on the examples appears in the
API docs. Can be a string or False. If set to a string, the endpoint will be
exposed in the API docs with the given name. If False, the endpoint will not
be exposed in the API docs and downstream apps (including those that `gr.load`
this app) will not be able to use the example
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
posed in the API docs with the given name. If False, the endpoint will not
be exposed in the API docs and downstream apps (including those that `gr.load`
this app) will not be able to use the example function.
api_description: str | None | Literal[False]
default `= None`
Description of the event associated with clicking on the examples in the API
docs. Can be a string, None, or False. If set to a string, the endpoint will
be exposed in the API docs with the given description. If None, the function's
docstring will be used as the API endpoint description. If False, then no
description will be displayed in the API docs.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. Used only if
cache_examples is not False.
example_labels: list[str] | None
default `= None`
A list of labels for each example. If provided, the length of this list should
be the same as the number of examples, and these labels will be used in the UI
instead of rendering the example values.
visible: bool
default `= True`
If False, the examples component will be hidden in the UI.
preload: int | Literal[False]
default `= False`
If an integer is provided (and examples are being cached), the example at that
index in the examples list will be preloaded when the Gradio app is loaded. If
False, no example will be preloaded.
|
Initialization
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Parameters ▼
dataset: gradio.Dataset
The `gr.Dataset` component corresponding to this Examples object.
load_input_event: gradio.events.Dependency
The Gradio event that populates the input values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event.
cache_event: gradio.events.Dependency | None
The Gradio event that populates the cached output values when the examples are
clicked. You can attach a `.then()` or a `.success()` to this event to trigger
subsequent events to fire after this event. This event is `None` if
`cache_examples` if False, and is the same as `load_input_event` if
`cache_examples` is `'lazy'`.
|
Attributes
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
**Updating Examples**
In this demo, we show how to update the examples by updating the samples of
the underlying dataset. Note that this only works if `cache_examples=False` as
updating the underlying dataset does not update the cache.
import gradio as gr
def update_examples(country):
if country == "USA":
return gr.Dataset(samples=[["Chicago"], ["Little Rock"], ["San Francisco"]])
else:
return gr.Dataset(samples=[["Islamabad"], ["Karachi"], ["Lahore"]])
with gr.Blocks() as demo:
dropdown = gr.Dropdown(label="Country", choices=["USA", "Pakistan"], value="USA")
textbox = gr.Textbox()
examples = gr.Examples([["Chicago"], ["Little Rock"], ["San Francisco"]], textbox)
dropdown.change(update_examples, dropdown, examples.dataset)
demo.launch()
|
Examples
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
calculator_blocks
Open in 🎢 ↗ import gradio as gr def calculator(num1, operation, num2): if
operation == "add": return num1 + num2 elif operation == "subtract": return
num1 - num2 elif operation == "multiply": return num1 * num2 elif operation ==
"divide": return num1 / num2 with gr.Blocks() as demo: with gr.Row(): with
gr.Column(): num_1 = gr.Number(value=4) operation = gr.Radio(["add",
"subtract", "multiply", "divide"]) num_2 = gr.Number(value=0) submit_btn =
gr.Button(value="Calculate") with gr.Column(): result = gr.Number()
submit_btn.click( calculator, inputs=[num_1, operation, num_2],
outputs=[result], api_name=False ) examples = gr.Examples( examples=[ [5,
"add", 3], [4, "divide", 2], [-4, "multiply", 2.5], [0, "subtract", 1.2], ],
inputs=[num_1, operation, num_2], ) if __name__ == "__main__":
demo.launch(show_api=False)
import gradio as gr
def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2
elif operation == "divide":
return num1 / num2
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
num_1 = gr.Number(value=4)
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
num_2 = gr.Number(value=0)
submit_btn = gr.Button(value="Calculate")
with gr.Column():
result = gr.Number()
submit_btn.click(
calculator, inputs=[num_1, operation, num_2], outputs=[result], api_name=False
)
examples = gr.Examples(
examples=[
[5, "add", 3],
[4, "divide", 2],
[-4, "multiply", 2.5],
[0, "subtract", 1.2],
],
inputs=[num_1, operation, num_2],
)
if __name__ == "__mai
|
Demos
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
[4, "divide", 2],
[-4, "multiply", 2.5],
[0, "subtract", 1.2],
],
inputs=[num_1, operation, num_2],
)
if __name__ == "__main__":
demo.launch(show_api=False)
|
Demos
|
https://gradio.app/docs/gradio/examples
|
Gradio - Examples Docs
|
Gradio includes pre-built components that can be used as inputs or outputs
in your Interface or Blocks with a single line of code. Components include
preprocessing steps that convert user data submitted through browser to
something that be can used by a Python function, and postprocessing steps to
convert values returned by a Python function into something that can be
displayed in a browser.
Consider an example with three inputs (Textbox, Number, and Image) and two
outputs (Number and Gallery), below is a diagram of what our preprocessing
will send to the function and what our postprocessing will require from it.

|
Introduction
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
Components also come with certain events that they support. These are
methods that are triggered with user actions. Below is a table showing which
events are supported for each component. All events are also listed (with
parameters) in the component’s docs.
| example_select| release| undo| retry| focus| pause| stream| blur|
double_click| tick| preview_open| option_select| edit| play| download|
pause_recording| preview_close| start_recording| apply| clear| click|
stop_recording| submit| copy| change| stop| end| input| delete| upload|
key_up| select| like
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---
[AnnotatedImage](annotatedimage) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[Audio](audio) | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✓ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✕
[BrowserState](browserstate) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Button](button) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Chatbot](chatbot) | ✓ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓
[Checkbox](checkbox) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[CheckboxGroup](checkboxgroup) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[ClearButton](clearbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Code](code) | ✕ | ✕ | ✕ | ✕ | ✓
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
| ✕
[ClearButton](clearbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Code](code) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕
[ColorPicker](colorpicker) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕
[Dataframe](dataframe) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[Dataset](dataset) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[DateTime](datetime) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[DeepLinkButton](deeplinkbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Dialogue](dialogue) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕
[DownloadButton](downloadbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Dropdown](dropdown) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✓ | ✕
[DuplicateButton](duplicatebutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[File](file) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✓ | ✕
[FileExplorer](fileexplorer) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✓ | ✕
[FileExplorer](fileexplorer) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Gallery](gallery) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕
[HighlightedText](highlightedtext) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[HTML](html) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[ImageEditor](imageeditor) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕
[Image](image) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕
[ImageSlider](imageslider) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕
[JSON](json) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Label](label) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[LoginButton](loginbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Markdown](markdown) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Model3D](model3d) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
[Textbox](textbox) | ✕ | ✕ | ✕
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
✕ | ✕ | ✕ | ✕
[Model3D](model3d) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
[Textbox](textbox) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✓ | ✓ | ✓ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[MultimodalTextbox](multimodaltextbox) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✓ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[BarPlot](barplot) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[LinePlot](lineplot) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[ScatterPlot](scatterplot) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕
[Number](number) | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕
[ParamViewer](paramviewer) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
[Plot](plot) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Radio](radio) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕
[Slider](slider) | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕
[State](state) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Timer](timer) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[Timer](timer) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕
[UploadButton](uploadbutton) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
[Video](video) | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✓ | ✕ | ✓ | ✕ | ✓ | ✕ | ✕ | ✓ | ✓ | ✓ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
[SimpleImage](simpleimage) | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕ | ✕ | ✓ | ✕ | ✕ | ✕
|
Events
|
https://gradio.app/docs/gradio/introduction
|
Gradio - Introduction Docs
|
Any code in a `if gr.NO_RELOAD` code-block will not be re-evaluated when
the source file is reloaded. This is helpful for importing modules that do not
like to be reloaded (tiktoken, numpy) as well as database connections and long
running set up code.
|
Description
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
import gradio as gr
if gr.NO_RELOAD:
from transformers import pipeline
pipe = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
gr.Interface.from_pipeline(pipe).launch()
|
Example Usage
|
https://gradio.app/docs/gradio/NO_RELOAD
|
Gradio - No_Reload Docs
|
Displays an interactive table of parameters and their descriptions and
default values with syntax highlighting. For each parameter, the user should
provide a type (e.g. a `str`), a human-readable description, and a default
value. As this component does not accept user input, it is rarely used as an
input component. Internally, this component is used to display the parameters
of components in the Custom Component Gallery (https://www.gradio.app/custom-
components/gallery).
|
Description
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
**As input component** : (Rarely used) passes value as a `dict[str, dict]`.
The key in the outer dictionary is the parameter name, while the inner
dictionary has keys "type", "description", and "default" for each parameter.
Your function should accept one of these types:
def predict(
value: dict[str, Parameter]
)
...
**As output component** : Expects value as a `dict[str, dict]`. The key in
the outer dictionary is the parameter name, while the inner dictionary has
keys "type", "description", and "default" for each parameter.
Your function should return one of these types:
def predict(···) -> dict[str, Parameter]
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Parameters ▼
value: dict[str, Parameter] | None
default `= None`
A dictionary of dictionaries. The key in the outer dictionary is the parameter
name, while the inner dictionary has keys "type", "description", and "default"
for each parameter. Markdown links are supported in "description".
language: Literal['python', 'typescript']
default `= "python"`
The language to display the code in. One of "python" or "typescript".
linkify: list[str] | None
default `= None`
A list of strings to linkify. If any of these strings is found in the
description, it will be rendered as a link.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
er()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
header: str | None
default `= "Parameters"`
The header to display above the table of parameters, also includes a toggle
button that closes/opens all details at once. If None, no header will be
displayed.
anchor_links: bool | str
default `= False`
If True, creates anchor links for each parameter that can be used to link
directly to that parameter. If a string, creates anchor links with the given
string as the prefix to prevent conflicts with other ParamViewer components.
|
Initialization
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.ParamViewer` | "paramviewer" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The ParamViewer component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`ParamViewer.change(fn, ···)` | Triggered when the value of the ParamViewer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.
`ParamViewer.upload(fn, ···)` | This listener is triggered when the user uploads a file into the ParamViewer.
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, o
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
on returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
sh
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method t
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
|
Event Listeners
|
https://gradio.app/docs/gradio/paramviewer
|
Gradio - Paramviewer Docs
|
The gr.LikeData class is a subclass of gr.EventData that specifically
carries information about the `.like()` event. When gr.LikeData is added as a
type hint to an argument of an event listener method, a gr.LikeData object
will automatically be passed as the value of that argument. The attributes of
this object contains information about the event that triggered the listener.
|
Description
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
import gradio as gr
def test(value, like_data: gr.LikeData):
return {
"chatbot_value": value,
"liked_message": like_data.value,
"liked_index": like_data.index,
"liked_or_disliked_as_bool": like_data.liked
}
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def")])
t = gr.JSON()
c.like(test, c, t)
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
Parameters ▼
index: int | tuple[int, int]
The index of the liked/disliked item. Is a tuple if the component is two
dimensional.
value: Any
The value of the liked/disliked item.
liked: bool
True if the item was liked, False if disliked, or string value if any other
feedback.
|
Attributes
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
chatbot_core_components_simple
Open in 🎢 ↗ import gradio as gr import random Chatbot demo with multimodal
input (text, markdown, LaTeX, code blocks, image, audio, video, & model3d).
Plus shows support for streaming text. color_map = { "harmful": "crimson",
"neutral": "gray", "beneficial": "green", } def html_src(harm_level): return
f""" <div style="display: flex; gap: 5px;"> <div style="background-color:
{color_map[harm_level]}; padding: 2px; border-radius: 5px;"> {harm_level}
</div> </div> """ def print_like_dislike(x: gr.LikeData): print(x.index,
x.value, x.liked) def add_message(history, message): for x in
message["files"]: history.append(((x,), None)) if message["text"] is not None:
history.append((message["text"], None)) return history,
gr.MultimodalTextbox(value=None, interactive=False) def bot(history,
response_type): if response_type == "gallery": history[-1][1] = gr.Gallery( [
"https://raw.githubusercontent.com/gradio-
app/gradio/main/test/test_files/bus.png",
"https://raw.githubusercontent.com/gradio-
app/gradio/main/test/test_files/bus.png", ] ) elif response_type == "image":
history[-1][1] = gr.Image( "https://raw.githubusercontent.com/gradio-
app/gradio/main/test/test_files/bus.png" ) elif response_type == "video":
history[-1][1] = gr.Video( "https://github.com/gradio-
app/gradio/raw/main/demo/video_component/files/world.mp4" ) elif response_type
== "audio": history[-1][1] = gr.Audio( "https://github.com/gradio-
app/gradio/raw/main/test/test_files/audio_sample.wav" ) elif response_type ==
"html": history[-1][1] = gr.HTML( html_src(random.choice(["harmful",
"neutral", "beneficial"])) ) elif response_type == "model3d": history[-1][1] =
gr.Model3D( "https://github.com/gradio-
app/gradio/raw/main/test/test_files/Fox.gltf" ) else: history[-1][1] = "Cool!"
return history with gr.Blocks(fill_height=True) as demo: chatbot = gr.Chatbot(
elem_id="chatbot", bubble_full_width=False, scale=1, ) response_type =
gr.Radio( [ "image", "text", "gallery", "video", "aud
|
Demos
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
urn history with gr.Blocks(fill_height=True) as demo: chatbot = gr.Chatbot(
elem_id="chatbot", bubble_full_width=False, scale=1, ) response_type =
gr.Radio( [ "image", "text", "gallery", "video", "audio", "html", "model3d",
], value="text", label="Response Type", ) chat_input = gr.MultimodalTextbox(
interactive=True, placeholder="Enter message or upload file...",
show_label=False, ) chat_msg = chat_input.submit( add_message, [chatbot,
chat_input], [chatbot, chat_input] ) bot_msg = chat_msg.then( bot, [chatbot,
response_type], chatbot, api_name="bot_response" ) bot_msg.then(lambda:
gr.MultimodalTextbox(interactive=True), None, [chat_input])
chatbot.like(print_like_dislike, None, None) if __name__ == "__main__":
demo.launch()
import gradio as gr
import random
Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, image, audio, video, & model3d). Plus shows support for streaming text.
color_map = {
"harmful": "crimson",
"neutral": "gray",
"beneficial": "green",
}
def html_src(harm_level):
return f"""
{harm_level}
"""
def print_like_dislike(x: gr.LikeData):
print(x.index, x.value, x.liked)
def add_message(history, message):
for x in message["files"]:
history.append(((x,), None))
if message["text"] is not None:
history.append((message["text"], None))
return history, gr.MultimodalTextbox(value=None, interactive=False)
def bot(history, response_type):
if response_type == "gallery":
history[-1][1] = gr.Gallery(
[
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
]
)
elif response_type == "image"
|
Demos
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
/test/test_files/bus.png",
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
]
)
elif response_type == "image":
history[-1][1] = gr.Image(
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"
)
elif response_type == "video":
history[-1][1] = gr.Video(
"https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4"
)
elif response_type == "audio":
history[-1][1] = gr.Audio(
"https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav"
)
elif response_type == "html":
history[-1][1] = gr.HTML(
html_src(random.choice(["harmful", "neutral", "beneficial"]))
)
elif response_type == "model3d":
history[-1][1] = gr.Model3D(
"https://github.com/gradio-app/gradio/raw/main/test/test_files/Fox.gltf"
)
else:
history[-1][1] = "Cool!"
return history
with gr.Blocks(fill_height=True) as demo:
chatbot = gr.Chatbot(
elem_id="chatbot",
bubble_full_width=False,
scale=1,
)
response_type = gr.Radio(
[
"image",
"text",
"gallery",
"video",
"audio",
"html",
"model3d",
],
value="text",
label="Response Type",
)
chat_input = gr.MultimodalTextbox(
interactive=True,
placeholder="Enter message or upload file...",
show_label=False,
)
chat_msg = chat_input.submit(
add_message, [chatbot, chat_input], [chatbot, chat_input]
)
bot_msg = chat_msg.then(
bo
|
Demos
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
show_label=False,
)
chat_msg = chat_input.submit(
add_message, [chatbot, chat_input], [chatbot, chat_input]
)
bot_msg = chat_msg.then(
bot, [chatbot, response_type], chatbot, api_name="bot_response"
)
bot_msg.then(lambda: gr.MultimodalTextbox(interactive=True), None, [chat_input])
chatbot.like(print_like_dislike, None, None)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/likedata
|
Gradio - Likedata Docs
|
Creates an image component that, as an input, can be used to upload and
edit images using simple editing tools such as brushes, strokes, cropping, and
layers. Or, as an output, this component can be used to display images.
|
Description
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
**As input component** : Passes the uploaded images as an instance of
EditorValue, which is just a `dict` with keys: 'background', 'layers', and
'composite'. The values corresponding to 'background' and 'composite' are
images, while 'layers' is a `list` of images. The images are of type
`PIL.Image`, `np.array`, or `str` filepath, depending on the `type` parameter.
Your function should accept one of these types:
def predict(
value: EditorValue | None
)
...
**As output component** : Expects a EditorValue, which is just a dictionary
with keys: 'background', 'layers', and 'composite'. The values corresponding
to 'background' and 'composite' should be images or None, while `layers`
should be a list of images. Images can be of type `PIL.Image`, `np.array`, or
`str` filepath/URL. Or, the value can be simply a single image (`ImageType`),
in which case it will be used as the background.
Your function should return one of these types:
def predict(···) -> EditorValue | ImageType | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
Parameters ▼
value: EditorValue | ImageType | None
default `= None`
Optional initial image(s) to populate the image editor. Should be a dictionary
with keys: `background`, `layers`, and `composite`. The values corresponding
to `background` and `composite` should be images or None, while `layers`
should be a list of images. Images can be of type PIL.Image, np.array, or str
filepath/URL. Or, the value can be a callable, in which case the function will
be called whenever the app loads to set the initial value of the component.
height: int | str | None
default `= None`
The height of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
files or numpy arrays, but will affect the displayed images. Beware of
conflicting values with the canvas_size paramter. If the canvas_size is larger
than the height, the editing canvas will not fit in the component.
width: int | str | None
default `= None`
The width of the component, specified in pixels if a number is passed, or in
CSS units if a string is passed. This has no effect on the preprocessed image
files or numpy arrays, but will affect the displayed images. Beware of
conflicting values with the canvas_size paramter. If the canvas_size is larger
than the height, the editing canvas will not fit in the component.
image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F']
default `= "RGBA"`
"RGB" if color, or "L" if black and white. See
https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other
supported image modes and their meaning.
sources: Iterable[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | None
default `= ('upload', 'webcam', 'clipboard')`
List of sources that can be used to set the background image. "upload" creates
a box where user can drop an image file, "webc
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
bcam', 'clipboard'] | None
default `= ('upload', 'webcam', 'clipboard')`
List of sources that can be used to set the background image. "upload" creates
a box where user can drop an image file, "webcam" allows user to take snapshot
from their webcam, "clipboard" allows users to paste an image from the
clipboard.
type: Literal['numpy', 'pil', 'filepath']
default `= "numpy"`
The format the images are converted to before being passed into the prediction
function. "numpy" converts the images to numpy arrays with shape (height,
width, 3) and values from 0 to 255, "pil" converts the images to PIL image
objects, "filepath" passes images as str filepaths to temporary copies of the
images.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
show_download_button: bool
default `= True`
If True, will display button to download image.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Componen
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
ue`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, will allow users to upload and edit an image; if False, can only be
used to display images. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool
default `= True`
If False, component 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 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
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
mponent, 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.
placeholder: str | None
default `= None`
Custom text for the upload area. Overrides default upload messages when
provided. Accepts new lines and `` to designate a heading.
mirror_webcam: bool | None
default `= None`
show_share_button: bool | None
default `= None`
If True, will show a share icon in the corner of the component that allows
user to share outputs to Hugging Face Spaces Discussions. If False, icon does
not appear. If set to None (default behavior), then the icon appears if this
Gradio app is launched on Spaces, but not otherwise.
crop_size: tuple[int | float, int | float] | str | None
default `= None`
Deprecated. Used to set the `canvas_size` parameter.
transforms: Iterable[Literal['crop', 'resize']] | None
default `= ('crop', 'resize')`
The transforms tools to make available to users. "crop" allows the user to
crop the image.
eraser: Eraser | None | Literal[False]
default `= None`
The options for the eraser tool in the image editor. Should be an instance of
the `gr.Eraser` class, or None to use the default settings. Can also be False
to hide the eraser tool. See `gr.Eraser` docs.
brush: Brush | None | Literal[False]
default `= None`
The options for the brush tool in the image editor. Should be an instance of
the `gr.Brush` class, or None to use the default settings. Can also be False
to hide the brush tool, which will also hide t
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
The options for the brush tool in the image editor. Should be an instance of
the `gr.Brush` class, or None to use the default settings. Can also be False
to hide the brush tool, which will also hide the eraser tool. See `gr.Brush`
docs.
format: str
default `= "webp"`
Format to save image if it does not already have a valid format (e.g. if the
image is being returned to the frontend as a numpy array or PIL Image). The
format should be supported by the PIL library. This parameter has no effect on
SVG files.
layers: bool | LayerOptions
default `= True`
The options for the layer tool in the image editor. Can be a boolean or an
instance of the `gr.LayerOptions` class. If True, will allow users to add
layers to the image. If False, the layers option will be hidden. If an
instance of `gr.LayerOptions`, it will be used to configure the layer tool.
See `gr.LayerOptions` docs.
canvas_size: tuple[int, int]
default `= (800, 800)`
The initial size of the canvas in pixels. The first value is the width and the
second value is the height. If `fixed_canvas` is `True`, uploaded images will
be rescaled to fit the canvas size while preserving the aspect ratio.
Otherwise, the canvas size will change to match the size of an uploaded image.
fixed_canvas: bool
default `= False`
If True, the canvas size will not change based on the size of the background
image and the image will be rescaled to fit (while preserving the aspect
ratio) and placed in the center of the canvas.
show_fullscreen_button: bool
default `= True`
If True, will display button to view image in fullscreen mode.
webcam_options: WebcamOptions | None
default `= None`
The options for the webcam tool in the image editor. Can be an instance of the
`gr.WebcamOptions` class, or None to use the default settings. See
`gr.WebcamOptions` docs.
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
be an instance of the
`gr.WebcamOptions` class, or None to use the default settings. See
`gr.WebcamOptions` docs.
|
Initialization
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.ImageEditor` | "imageeditor" | Uses default values
`gradio.Sketchpad` | "sketchpad" | Uses sources=(), brush=Brush(colors=["000000"], color_mode="fixed")
`gradio.Paint` | "paint" | Uses sources=()
`gradio.ImageMask` | "imagemask" | Uses brush=Brush(colors=["000000"], color_mode="fixed")
|
Shortcuts
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
image_editor
Open in 🎢 ↗ import gradio as gr import time def sleep(im): time.sleep(5)
return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
def predict(im): return im["composite"] with gr.Blocks() as demo: with
gr.Row(): im = gr.ImageEditor( type="numpy", crop_size="1:1", ) im_preview =
gr.Image() n_upload = gr.Number(0, label="Number of upload events", step=1)
n_change = gr.Number(0, label="Number of change events", step=1) n_input =
gr.Number(0, label="Number of input events", step=1) im.upload(lambda x: x +
1, outputs=n_upload, inputs=n_upload) im.change(lambda x: x + 1,
outputs=n_change, inputs=n_change) im.input(lambda x: x + 1, outputs=n_input,
inputs=n_input) im.change(predict, outputs=im_preview, inputs=im,
show_progress="hidden") if __name__ == "__main__": demo.launch()
import gradio as gr
import time
def sleep(im):
time.sleep(5)
return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
def predict(im):
return im["composite"]
with gr.Blocks() as demo:
with gr.Row():
im = gr.ImageEditor(
type="numpy",
crop_size="1:1",
)
im_preview = gr.Image()
n_upload = gr.Number(0, label="Number of upload events", step=1)
n_change = gr.Number(0, label="Number of change events", step=1)
n_input = gr.Number(0, label="Number of input events", step=1)
im.upload(lambda x: x + 1, outputs=n_upload, inputs=n_upload)
im.change(lambda x: x + 1, outputs=n_change, inputs=n_change)
im.input(lambda x: x + 1, outputs=n_input, inputs=n_input)
im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden")
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor 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 ImageEditor component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`ImageEditor.clear(fn, ···)` | This listener is triggered when the user clears the ImageEditor using the clear button for the component.
`ImageEditor.change(fn, ···)` | Triggered when the value of the ImageEditor 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.
`ImageEditor.input(fn, ···)` | This listener is triggered when the user changes the value of the ImageEditor.
`ImageEditor.select(fn, ···)` | Event listener for when the user selects or deselects the ImageEditor. Uses event data gradio.SelectData to carry `value` referring to the label of the ImageEditor, and `selected` to refer to state of the ImageEditor. See EventData documentation on how to use this event data
`ImageEditor.upload(fn, ···)` | This listener is triggered when the user uploads a file into the ImageEditor.
`ImageEditor.apply(fn, ···)` | This listener is triggered when the user applies changes to the ImageEditor through an integrated UI action.
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 ele
|
Event Listeners
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
ten a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "mi
|
Event Listeners
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of
|
Event Listeners
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
ne
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this ev
|
Event Listeners
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
|
Event Listeners
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
Helper Classes
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
|
gradio.Brush(···)
Description
A dataclass for specifying options for the brush tool in the ImageEditor
component. An instance of this class can be passed to the `brush` parameter of
`gr.ImageEditor`.
Initialization
Parameters ▼
default_size: int | Literal['auto']
default `= "auto"`
The default radius, in pixels, of the brush tool. Defaults to "auto" in which
case the radius is automatically determined based on the size of the image
(generally 1/50th of smaller dimension).
colors: list[str | tuple[str, float]] | str | tuple[str, float] | None
default `= None`
A list of colors to make available to the user when using the brush. Defaults
to a list of 5 colors.
default_color: str | tuple[str, float] | None
default `= None`
The default color of the brush. Defaults to the first color in the `colors`
list.
color_mode: Literal['fixed', 'defaults']
default `= "defaults"`
If set to "fixed", user can only select from among the colors in `colors`. If
"defaults", the colors in `colors` are provided as a default palette, but the
user can also select any color using a color picker.
|
Brush
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
gradio.Eraser(···)
Description
A dataclass for specifying options for the eraser tool in the ImageEditor
component. An instance of this class can be passed to the `eraser` parameter
of `gr.ImageEditor`.
Initialization
Parameters ▼
default_size: int | Literal['auto']
default `= "auto"`
The default radius, in pixels, of the eraser tool. Defaults to "auto" in which
case the radius is automatically determined based on the size of the image
(generally 1/50th of smaller dimension).
|
Eraser
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
gradio.LayerOptions(···)
Description
A dataclass for specifying options for the layer tool in the ImageEditor
component. An instance of this class can be passed to the `layers` parameter
of `gr.ImageEditor`.
Initialization
Parameters ▼
allow_additional_layers: bool
default `= True`
If True, users can add additional layers to the image. If False, the add layer
button will not be shown.
layers: list[str] | None
default `= None`
A list of layers to make available to the user when using the layer tool. One
layer must be provided, if the length of the list is 0 then a layer will be
generated automatically.
disabled: bool
default `= False`
|
Layer Options
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
gradio.WebcamOptions(···)
Description
A dataclass for specifying options for the webcam tool in the ImageEditor
component. An instance of this class can be passed to the `webcam_options`
parameter of `gr.ImageEditor`.
Initialization
Parameters ▼
mirror: bool
default `= True`
If True, the webcam will be mirrored.
constraints: dict[str, Any] | None
default `= None`
A dictionary of constraints for the webcam.
|
Webcam Options
|
https://gradio.app/docs/gradio/imageeditor
|
Gradio - Imageeditor Docs
|
Creates a button that redirects the user to Sign with Hugging Face using
OAuth. If created inside of a Blocks context, it will add an event to check if
the user is logged in and update the button text accordingly. If created
outside of a Blocks context, call the `LoginButton.activate()` method to add
the event.
|
Description
|
https://gradio.app/docs/gradio/loginbutton
|
Gradio - Loginbutton Docs
|
**As input component** : (Rarely used) the `str` corresponding to the
button label when the button is clicked
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : string corresponding to the button label
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
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`
visible: bool
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
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.LoginButton` | "loginbutton" | Uses default values
|
Shortcuts
|
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.
Listener | Description
---|---
`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 | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_descripti
|
Event Listeners
|
https://gradio.app/docs/gradio/loginbutton
|
Gradio - Loginbutton Docs
|
API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to 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`
Maximu
|
Event Listeners
|
https://gradio.app/docs/gradio/loginbutton
|
Gradio - Loginbutton Docs
|
ed* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no c
|
Event Listeners
|
https://gradio.app/docs/gradio/loginbutton
|
Gradio - Loginbutton Docs
|
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
|
Event Listeners
|
https://gradio.app/docs/gradio/loginbutton
|
Gradio - Loginbutton Docs
|
The Progress class provides a custom progress tracker that is used in a
function signature. To attach a Progress tracker to a function, simply add a
parameter right after the input parameters that has a default value set to a
`gradio.Progress()` instance. The Progress tracker can then be updated in the
function by calling the Progress object or using the `tqdm` method on an
Iterable.
|
Description
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
import gradio as gr
import time
def my_function(x, progress=gr.Progress()):
progress(0, desc="Starting...")
time.sleep(1)
for i in progress.tqdm(range(100)):
time.sleep(0.1)
return x
gr.Interface(my_function, gr.Textbox(), gr.Textbox()).queue().launch()
|
Example Usage
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Parameters ▼
track_tqdm: bool
default `= False`
If True, the Progress object will track any tqdm.tqdm iterations with the tqdm
library in the function.
|
Initialization
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Methods
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
|
%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
gradio.Progress.__call__(progress, ···)
Description
%20Copyright%202022%20Fontic
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
Updates progress tracker with progress and message text.
Parameters ▼
progress: float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If Tuple, first
number represents steps completed, and second value represents total steps or
None if unknown. If None, hides progress bar.
desc: str | None
default `= None`
description to display.
total: int | float | None
default `= None`
estimated total
|
__call__
|
https://gradio.app/docs/gradio/progress
|
Gradio - Progress Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.