text
stringlengths 0
2k
| heading1
stringlengths 4
79
| source_page_url
stringclasses 180
values | source_page_title
stringclasses 180
values |
|---|---|---|---|
--!%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 Sidebar is expanded.
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 | B
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
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 display, "hidden"
shows no progress animation at all
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
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 method. Functions that have
not yet run (or generators that are ite
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
ample,
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 will automatically be set
to False.
time_limit: i
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
expand
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar 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.Sidebar.collapse(···)
Description
%20Copyright%202022%20Fonticons,%20Inc.
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar 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)
This listener is triggered when the Sidebar is collapsed.
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
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
nds 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 display, "hidden"
shows no progress animation at all
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
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 method. Functions that have
not yet run (or generators that are
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
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 will automatically be set
to False.
time_limit
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
me to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
collapse
|
https://gradio.app/docs/gradio/sidebar
|
Gradio - Sidebar Docs
|
Creates a gallery component that allows displaying a grid of images or
videos, and optionally captions. If used as an input, the user can upload
images or videos to the gallery. If used as an output, the user can click on
individual images or videos to view them at a higher resolution.
|
Description
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
**As input component** : Passes the list of images or videos as a list of
(media, caption) tuples, or a list of (media, None) tuples if no captions are
provided (which is usually the case). Images can be a `str` file path, a
`numpy` array, or a `PIL.Image` object depending on `type`. Videos are always
`str` file path.
Your function should accept one of these types:
def predict(
value: List[tuple[str, str | None]] | List[tuple[PIL.Image.Image, str | None]] | List[tuple[np.ndarray, str | None]] | None
)
...
**As output component** : Expects the function to return a `list` of images
or videos, or `list` of (media, `str` caption) tuples. Each image can be a
`str` file path, a `numpy` array, or a `PIL.Image` object. Each video can be a
`str` file path.
Your function should return one of these types:
def predict(···) -> list[GalleryImageType | CaptionedGalleryImageType] | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
Parameters ▼
value: list[np.ndarray | PIL.Image.Image | str | Path | tuple] | Callable | None
default `= None`
List of images or videos to display in the gallery by default. If a function
is provided, the function will be called each time the app loads to set the
initial value of this component.
format: str
default `= "webp"`
Format to save images before they are returned to the frontend, such as 'jpeg'
or 'png'. This parameter only applies to images that are returned from the
prediction function as numpy arrays or PIL Images. The format should be
supported by the PIL library.
file_types: list[str] | None
default `= None`
List of file extensions or types of files to be uploaded (e.g. ['image',
'.mp4']), when this is used as an input component. "image" allows only image
files to be uploaded, "video" allows only video files to be uploaded, ".mp4"
allows only mp4 files to be uploaded, etc. If None, any image and video files
types are allowed.
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.
container: bool
default `= True`
If Tru
|
Initialization
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: lis
|
Initialization
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
columns: int | None
default `= 2`
Represents the number of images that should be shown in one row.
rows: int | None
default `= None`
Represents the number of rows in the image grid.
height: int | float | str | None
default `= None`
The height of the gallery component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If more images are displayed
than can fit in the height, a scrollbar will appear.
allow_preview: bool
default `= True`
If True, images in the gallery will be enlarged when they are clicked. Default
is True.
preview: bool | None
default `= None`
If True, Gallery will start in preview mode, which shows all of the images as
thumbnails and allows the user to click on them to view them in full size.
Only works if allow_preview is True.
selected_index: int | None
default `= None`
The index of the image that should be initially selected. If None, no image
will be selected at start. If provided, will set Gallery to preview mode
unless allow_preview is set to False.
object_fit: Literal['contain', 'cover', 'fill', 'none', 'scale-down'] | None
default `= None`
CSS object-fit property for the thumbnail images in the gallery. Can be
"contain", "cover", "fill", "none", or "scale-down".
show_share_button: bool | None
default `= None`
|
Initialization
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
`= None`
CSS object-fit property for the thumbnail images in the gallery. Can be
"contain", "cover", "fill", "none", or "scale-down".
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.
show_download_button: bool | None
default `= True`
If True, will show a download button in the corner of the selected image. If
False, the icon does not appear. Default is True.
interactive: bool | None
default `= None`
If True, the gallery will be interactive, allowing the user to upload images.
If False, the gallery will be static. Default is True.
type: Literal['numpy', 'pil', 'filepath']
default `= "filepath"`
The format the image is converted to before being passed into the prediction
function. "numpy" converts the image to a numpy array with shape (height,
width, 3) and values from 0 to 255, "pil" converts the image to a PIL image
object, "filepath" passes a str path to a temporary file containing the image.
If the image is SVG, the `type` is ignored and the filepath of the SVG is
returned.
show_fullscreen_button: bool
default `= True`
If True, will show a fullscreen icon in the corner of the component that
allows user to view the gallery in fullscreen mode. 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.
|
Initialization
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.Gallery` | "gallery" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
fake_gangif_maker
Open in 🎢 ↗ This demo needs to be run from the repo folder. python
demo/fake_gan/run.py import random import gradio as gr def fake_gan(): images
= [ (random.choice( [ "http://www.marketingtool.online/en/face-
generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg",
"http://www.marketingtool.online/en/face-
generator/img/faces/avatar-116b5e92936b766b7fdfc242649337f7.jpg",
"http://www.marketingtool.online/en/face-
generator/img/faces/avatar-1163530ca19b5cebe1b002b8ec67b6fc.jpg",
"http://www.marketingtool.online/en/face-
generator/img/faces/avatar-1116395d6e6a6581eef8b8038f4c8e55.jpg",
"http://www.marketingtool.online/en/face-
generator/img/faces/avatar-11319be65db395d0e8e6855d18ddcef0.jpg", ] ), f"label
{i}") for i in range(3) ] return images with gr.Blocks() as demo: gallery =
gr.Gallery( label="Generated images", show_label=False, elem_id="gallery" ,
columns=1, object_fit="contain", height="auto") btn = gr.Button("Generate
images", scale=0) btn.click(fake_gan, None, gallery) if __name__ ==
"__main__": demo.launch()
This demo needs to be run from the repo folder.
python demo/fake_gan/run.py
import random
import gradio as gr
def fake_gan():
images = [
(random.choice(
[
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg",
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-116b5e92936b766b7fdfc242649337f7.jpg",
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1163530ca19b5cebe1b002b8ec67b6fc.jpg",
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-1116395d6e6a6581eef8b8038f4c8e55.jpg",
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-11319be65db395d0e8e6855d18ddcef0.jpg",
]
), f"label {i}")
for i i
|
Demos
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
.jpg",
"http://www.marketingtool.online/en/face-generator/img/faces/avatar-11319be65db395d0e8e6855d18ddcef0.jpg",
]
), f"label {i}")
for i in range(3)
]
return images
with gr.Blocks() as demo:
gallery = gr.Gallery(
label="Generated images", show_label=False, elem_id="gallery"
, columns=1, object_fit="contain", height="auto")
btn = gr.Button("Generate images", scale=0)
btn.click(fake_gan, None, gallery)
if __name__ == "__main__":
demo.launch()
Open in 🎢 ↗ import gradio as gr import os import tempfile from PIL import
Image def gif_maker(img_files): img_array = [] for filename, _ in img_files:
pil_img = Image.open(filename) if pil_img.mode in ('RGBA', 'LA', 'P'): pil_img
= pil_img.convert('RGB') img_array.append(pil_img) with
tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as tmp_file:
output_file = tmp_file.name if img_array: img_array[0].save( output_file,
save_all=True, append_images=img_array[1:], duration=200, loop=0 ) return
output_file demo = gr.Interface( gif_maker, inputs=gr.Gallery(),
outputs=gr.Image(), examples=[ [[ os.path.join(os.path.dirname(__file__),
"images/1.png"), os.path.join(os.path.dirname(__file__), "images/2.png"),
os.path.join(os.path.dirname(__file__), "images/3.png"), ]], ], ) if __name__
== "__main__": demo.launch()
import gradio as gr
import os
import tempfile
from PIL import Image
def gif_maker(img_files):
img_array = []
for filename, _ in img_files:
pil_img = Image.open(filename)
if pil_img.mode in ('RGBA', 'LA', 'P'):
pil_img = pil_img.convert('RGB')
img_array.append(pil_img)
with tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as tmp_file:
output_file = tmp_file.name
if img_array:
img_array[0].save
|
Demos
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
il_img)
with tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as tmp_file:
output_file = tmp_file.name
if img_array:
img_array[0].save(
output_file,
save_all=True,
append_images=img_array[1:],
duration=200,
loop=0
)
return output_file
demo = gr.Interface(
gif_maker,
inputs=gr.Gallery(),
outputs=gr.Image(),
examples=[
[[
os.path.join(os.path.dirname(__file__), "images/1.png"),
os.path.join(os.path.dirname(__file__), "images/2.png"),
os.path.join(os.path.dirname(__file__), "images/3.png"),
]],
],
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery 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 Gallery component supports the following event listeners. Each event
listener takes the same parameters, which are listed in the Event Parameters
table below.
Listener | Description
---|---
`Gallery.select(fn, ···)` | Event listener for when the user selects or deselects the Gallery. Uses event data gradio.SelectData to carry `value` referring to the label of the Gallery, and `selected` to refer to state of the Gallery. See EventData documentation on how to use this event data
`Gallery.upload(fn, ···)` | This listener is triggered when the user uploads a file into the Gallery.
`Gallery.change(fn, ···)` | Triggered when the value of the Gallery 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.
`Gallery.delete(fn, ···)` | This listener is triggered when the user deletes and item from the Gallery. Uses event data gradio.DeletedFileData to carry `value` referring to the file that was deleted as an instance of FileData. See EventData documentation on how to use this event data
`Gallery.preview_close(fn, ···)` | This event is triggered when the Gallery preview is closed by the user
`Gallery.preview_open(fn, ···)` | This event is triggered when the Gallery preview is opened by the user
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
|
Event Listeners
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
lt `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output c
|
Event Listeners
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
ion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_eve
|
Event Listeners
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
wser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to Fal
|
Event Listeners
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/gallery
|
Gradio - Gallery Docs
|
Constructs a Gradio app automatically from a Hugging Face model/Space repo
name or a 3rd-party API provider. Note that if a Space repo is loaded, certain
high-level attributes of the Blocks (e.g. custom `css`, `js`, and `head`
attributes) will not be loaded.
|
Description
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
import gradio as gr
demo = gr.load("gradio/question-answering", src="spaces")
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
Parameters ▼
name: str
the name of the model (e.g. "google/vit-base-patch16-224") or Space (e.g.
"flax-community/spanish-gpt2"). This is the first parameter passed into the
`src` function. Can also be formatted as {src}/{repo name} (e.g.
"models/google/vit-base-patch16-224") if `src` is not provided.
src: Callable[[str, str | None], Blocks] | Literal['models', 'spaces', 'huggingface'] | None
default `= None`
function that accepts a string model `name` and a string or None `token` and
returns a Gradio app. Alternatively, this parameter takes one of two strings
for convenience: "models" (for loading a Hugging Face model through the
Inference API) or "spaces" (for loading a Hugging Face Space). If None, uses
the prefix of the `name` parameter to determine `src`.
token: str | None
default `= None`
optional token that is passed as the second parameter to the `src` function.
If not explicitly provided, will use the HF_TOKEN environment variable or
fallback to the locally-saved HF token when loading models but not Spaces
(when loading Spaces, only provide a token if you are loading a trusted
private Space as the token can be read by the Space you are loading). Find
your HF tokens here: https://huggingface.co/settings/tokens.
hf_token: str | None
default `= None`
accept_token: bool | LoginButton
default `= False`
if True, a Textbox component is first rendered to allow the user to provide a
token, which will be used instead of the `token` parameter when calling the
loaded model or Space. Can also provide an instance of a gr.LoginButton in the
same Blocks scope, which allows the user to login with a Hugging Face account
whose token will be used instead of the `token` parameter when calling the
loaded model or Space.
provider: PROVIDER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova
|
Initialization
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
loaded model or Space.
provider: PROVIDER_T | None
default `= None`
the name of the third-party (non-Hugging Face) providers to use for model
inference (e.g. "replicate", "sambanova", "fal-ai", etc). Should be one of the
providers supported by `huggingface_hub.InferenceClient`. This parameter is
only used when `src` is "models"
kwargs: <class 'inspect._empty'>
additional keyword parameters to pass into the `src` function. If `src` is
"models" or "Spaces", these parameters are passed into the `gr.Interface` or
`gr.ChatInterface` constructor.
|
Initialization
|
https://gradio.app/docs/gradio/load
|
Gradio - Load Docs
|
Creates a component to display arbitrary HTML output. As this component
does not accept user input, it is rarely used as an input component.
|
Description
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
**As input component** : (Rarely used) passes the HTML as a `str`.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a `str` consisting of valid HTML.
Your function should return one of these types:
def predict(···) -> str | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
Parameters ▼
value: str | Callable | None
default `= None`
The HTML content to display. Only static HTML is rendered (e.g. no JavaScript.
To render JavaScript, use the `js` or `head` parameters in the `Blocks`
constructor). If a function is provided, the function will be called each time
the app loads to set the initial value of this component.
label: str | I18nData | None
default `= None`
The label for this component. Is 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
default `= False`
If True, the label will be displayed. If False, the label will be hidden.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the
|
Initialization
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
min_height: int | None
default `= None`
The minimum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If HTML content exceeds the
height, the component will expand to fit the content.
max_height: int | None
default `= None`
The maximum height of the component, specified in pixels if a number is
passed, or in CSS units if a string is passed. If content exceeds the height,
the component will scroll.
container: bool
default `= False`
If True, the HTML component will be displayed in a container. Default is
False.
padding: bool
default `= True`
If True, the HTML component will have a certain padding (set by the `--block-
padding` CSS variable) in all directions. Default is True.
autoscroll: bool
default `= False`
If True, will automatically scroll to the bottom of the component when the
content changes, unless the user has scrolled up. If False, will n
|
Initialization
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
True.
autoscroll: bool
default `= False`
If True, will automatically scroll to the bottom of the component when the
content changes, unless the user has scrolled up. If False, will not scroll to
the bottom when the content changes.
|
Initialization
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.HTML` | "html" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
blocks_scroll
Open in 🎢 ↗ import gradio as gr demo = gr.Blocks() with demo: inp =
gr.Textbox(placeholder="Enter text.") scroll_btn = gr.Button("Scroll")
no_scroll_btn = gr.Button("No Scroll") big_block = gr.HTML(""" <div
style='height: 800px; width: 100px; background-color: pink;'></div> """) out =
gr.Textbox() scroll_btn.click(lambda x: x, inputs=inp, outputs=out,
scroll_to_output=True) no_scroll_btn.click(lambda x: x, inputs=inp,
outputs=out) if __name__ == "__main__": demo.launch()
import gradio as gr
demo = gr.Blocks()
with demo:
inp = gr.Textbox(placeholder="Enter text.")
scroll_btn = gr.Button("Scroll")
no_scroll_btn = gr.Button("No Scroll")
big_block = gr.HTML("""
""")
out = gr.Textbox()
scroll_btn.click(lambda x: x,
inputs=inp,
outputs=out,
scroll_to_output=True)
no_scroll_btn.click(lambda x: x,
inputs=inp,
outputs=out)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/html
|
Gradio - Html 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 HTML component supports the following event listeners. Each event listener
takes the same parameters, which are listed in the Event Parameters table
below.
Listener | Description
---|---
`HTML.change(fn, ···)` | Triggered when the value of the HTML 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.
`HTML.click(fn, ···)` | Triggered when the HTML 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 do
|
Event Listeners
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
i_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
should accept a list of input values for each parameter. The lists should
|
Event Listeners
|
https://gradio.app/docs/gradio/html
|
Gradio - Html 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. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of
|
Event Listeners
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
er the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same i
|
Event Listeners
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/html
|
Gradio - Html Docs
|
Displays text that contains spans that are highlighted by category or
numerical value.
|
Description
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
**As input component** : Passes the value as a list of tuples as a `list[tuple]` into the function. Each `tuple` consists of a `str` substring of the text (so the entire text is included) and `str | float | None` label, which is the category or confidence of that substring.
Your function should accept one of these types:
def predict(
value: list[tuple[str, str | float | None]] | None
)
...
**As output component** : Expects a list of (word, category) tuples, or a
dictionary of two keys: "text", and "entities", which itself is a list of
dictionaries, each of which have the keys: "entity" (or "entity_group"),
"start", and "end"
Your function should return one of these types:
def predict(···) -> list[tuple[str, str | float | None]] | dict | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Parameters ▼
value: list[tuple[str, str | float | None]] | dict | Callable | None
default `= None`
Default value to show. If a function is provided, the function will be called
each time the app loads to set the initial value of this component.
color_map: dict[str, str] | None
default `= None`
A dictionary mapping labels to colors. The colors may be specified as hex
codes or by their names. For example: {"person": "red", "location": "FFEE22"}
show_legend: bool
default `= False`
whether to show span categories in a separate legend or inline.
show_inline_category: bool
default `= True`
If False, will not display span category label. Only applies if
show_legend=False and interactive=False.
combine_adjacent: bool
default `= False`
If True, will merge the labels of adjacent tokens belonging to the same
category.
adjacent_separator: str
default `= ""`
Specifies the separator to be used between tokens if combine_adjacent is True.
label: str | I18nData | None
default `= None`
the label for this component. Appears above the component and is also used as
the header if there are a table of examples for this component. If None and
used in a `gr.Interface`, the label will be the name of the parameter this
component is assigned to.
every: Timer | float | None
default `= None`
Continously calls `value` to recalculate it if `value` is a function (has no
effect otherwise). Can provide a Timer whose tick resets `value`, or a float
that provides the regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
Components that are used as inputs to calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
con
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
container: bool
default `= True`
If True, will place the component in a container - providing some extra
padding around the border.
scale: int | None
default `= None`
relative size compared to adjacent Components. For example if Components A and
B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide
as B. Should be an integer. scale applies in Rows, and to top-level Components
in Blocks where fill_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
`= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
interactive: bool | None
default `= None`
If True, the component will be editable, and allow user to select spans of
text and label them.
rtl: bool
default `= False`
If True, will display the text in right-to-left direction, and the labels in
the legend will also be aligned to the right.
|
Initialization
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Class | Interface String Shortcut | Initialization
---|---|---
`gradio.HighlightedText` | "highlightedtext" | Uses default values
|
Shortcuts
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
diff_texts
Open in 🎢 ↗ from difflib import Differ import gradio as gr def
diff_texts(text1, text2): d = Differ() return [ (token[2:], token[0] if
token[0] != " " else None) for token in d.compare(text1, text2) ] demo =
gr.Interface( diff_texts, [ gr.Textbox( label="Text 1", info="Initial text",
lines=3, value="The quick brown fox jumped over the lazy dogs.", ),
gr.Textbox( label="Text 2", info="Text to compare", lines=3, value="The fast
brown fox jumps over lazy dogs.", ), ], gr.HighlightedText( label="Diff",
combine_adjacent=True, show_legend=True, color_map={"+": "red", "-":
"green"}), theme=gr.themes.Base() ) if __name__ == "__main__": demo.launch()
from difflib import Differ
import gradio as gr
def diff_texts(text1, text2):
d = Differ()
return [
(token[2:], token[0] if token[0] != " " else None)
for token in d.compare(text1, text2)
]
demo = gr.Interface(
diff_texts,
[
gr.Textbox(
label="Text 1",
info="Initial text",
lines=3,
value="The quick brown fox jumped over the lazy dogs.",
),
gr.Textbox(
label="Text 2",
info="Text to compare",
lines=3,
value="The fast brown fox jumps over lazy dogs.",
),
],
gr.HighlightedText(
label="Diff",
combine_adjacent=True,
show_legend=True,
color_map={"+": "red", "-": "green"}),
theme=gr.themes.Base()
)
if __name__ == "__main__":
demo.launch()
|
Demos
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The HighlightedText component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Parameters table below.
Listener | Description
---|---
`HighlightedText.change(fn, ···)` | Triggered when the value of the HighlightedText changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.
`HighlightedText.select(fn, ···)` | Event listener for when the user selects or deselects the HighlightedText. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedText, and `selected` to refer to state of the HighlightedText. See EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. Each parameter of the function corresponds to one
input component, and the function should return a single value or a tuple of
values, with each element in the tuple corresponding to one output component.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
s should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outputs, this should be an empty list.
api_name: str | None | Literal[False]
default `= None`
defines how the endpoint appears in the API docs. Can be a string, None, or
False. If set to a string, the endpoint will be exposed in the API docs with
the given name. If None (default), the name of the function will be used as
the API endpoint. If False, the endpoint will not be exposed in the API docs
and downstream apps (including those that `gr.load` this app) will not be able
to use this event.
api_description: str | None | Literal[False]
default `= None`
Description of the API endpoint. Can be a string, None, or False. If set to a
string, the endpoint will be exposed in the API docs with the given
description. If None, the function's docstring will be used as the API
endpoint description. If False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
how to show the progress animation while event is running: "full" shows a
spinner which covers the output component area as well as a runtime display in
the upper right corner, "minimal" only shows the runtime display, "hidden"
shows no progress animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
on on all of the output components.
queue: bool
default `= True`
If True, will place the request on the queue, if the queue has been enabled.
If False, will not put this event on the queue, even if the queue has been
enabled. If None, will use the queue setting of the gradio app.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
should accept a list of input values for each parameter. The lists should be
of equal length (and be up to length `max_batch_size`). The function is then
*required* to return a tuple of lists (even if there is only 1 output
component), with each list in the tuple corresponding to one output component.
max_batch_size: int
default `= 4`
Maximum number of inputs to batch together if this is called from the queue
(only relevant if batch=True)
preprocess: bool
default `= True`
If False, will not run preprocessing of component data before running 'fn'
(e.g. leaving it as a base64 string if this method is called with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this listener is triggered. For example,
setting cancels=[click_event] will cancel the click_event, where click_event
is the return value of another components .click method. Functions that have
not yet run (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
`= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an event is pending. If set to "multiple", unlimited
submissions are allowed while pending, and "always_last" (default for
`.change()` and `.key_up()` events) would allow a second submission after the
pending event is complete.
js: str | Literal[True] | None
default `= None`
Optional frontend js method to run before running 'fn'. Input arguments for js
method are values of 'inputs' and 'outputs', return should be a list of values
for output components.
concurrency_limit: int | None | Literal['default']
default `= "default"`
If set, this is the maximum number of this event that can be running
simultaneously. Can be set to None to mean no concurrency_limit (any number of
this event can be running simultaneously). Set to "default" to use the default
concurrency limit (defined by the `default_concurrency_limit` parameter in
`Blocks.queue()`, which itself is 1 by default).
concurrency_id: str | None
default `= None`
If set, this is the id of the concurrency group. Events with the same
concurrency_id will be limited by the lowest set concurrency_limit.
show_api: bool
default `= True`
whether to show this event in the "view API" page of the Gradio app, or in the
".view_api()" method of the Gradio clients. Unlike setting api_name to False,
setting show_api to False will still allow downstream apps as well as the
Clients to use this event. If fn is None, show_api will automatically be set
to False.
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
like_user_message: bool
default `= False`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
| str, ...] | None
default `= None`
A unique key for this event listener to be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
Event Listeners
|
https://gradio.app/docs/gradio/highlightedtext
|
Gradio - Highlightedtext Docs
|
Interface is Gradio's main high-level class, and allows you to create a
web-based GUI / demo around a machine learning model (or any Python function)
in a few lines of code. You must specify three parameters: (1) the function to
create a GUI for (2) the desired input components and (3) the desired output
components. Additional parameters can be used to control the appearance and
behavior of the demo.
|
Description
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
import gradio as gr
def image_classifier(inp):
return {'cat': 0.3, 'dog': 0.7}
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
demo.launch()
|
Example Usage
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
Parameters ▼
fn: Callable
the function to wrap an interface around. 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: str | Component | list[str | Component] | 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.
The number of input components should match the number of parameters in fn. If
set to None, then only the output components will be displayed.
outputs: str | Component | list[str | Component] | 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.
The number of output components should match the number of values returned by
fn. If set to None, then only the input components will be displayed.
examples: list[Any] | list[list[Any]] | str | None
default `= None`
sample inputs for the function; if provided, appear below the UI components
and can be clicked to populate the interface. 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.
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
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
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 defaults to True (as long as `fn` and `outputs` are
also provided). 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 cached at app launch. If None, will use the GRADIO_CACHE_MODE environment
variable if defined, or default to "eager". In HuggingFace Spaces, this
parameter defaults to "eager" except for ZeroGPU Spaces, in which case it
defaults to "lazy".
examples_per_page: int
default `= 10`
if examples are provided, how many to display per page.
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.
preload_example: 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 first
loaded. If False, no example will be preloaded.
live: bool
default `= False`
whether the interface should automatically rerun if any of the inputs change.
title: str | I18nData | None
default `= None`
a title for the interface; if provided, appears above the input and output
components in large font. Also used as the tab title when opened in a browser
window.
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
I18nData | None
default `= None`
a title for the interface; if provided, appears above the input and output
components in large font. Also used as the tab title when opened in a browser
window.
description: str | None
default `= None`
a description for the interface; if provided, appears above the input and
output components and beneath the title in regular font. Accepts Markdown and
HTML content.
article: str | None
default `= None`
an expanded article explaining the interface; if provided, appears below the
input and output components in regular font. Accepts Markdown and HTML
content. If it is an HTTP(S) link to a downloadable remote file, the content
of this file is displayed.
theme: Theme | str | None
default `= None`
a Theme object or a string representing a theme. If a string, will look for a
built-in theme with that name (e.g. "soft" or "default"), or will attempt to
load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None,
will use the Default theme.
flagging_mode: Literal['never'] | Literal['auto'] | Literal['manual'] | None
default `= None`
one of "never", "auto", or "manual". If "never" or "auto", users will not see
a button to flag an input and output. If "manual", users will see a button to
flag. If "auto", every input the user submits will be automatically flagged,
along with the generated output. If "manual", both the input and outputs are
flagged when the user clicks flag button. This parameter can be set with
environmental variable GRADIO_FLAGGING_MODE; otherwise defaults to "manual".
flagging_options: list[str] | list[tuple[str, str]] | None
default `= None`
if provided, allows user to select from the list of options when flagging.
Only applies 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 i
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
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 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.
a
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
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 webpage
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
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: str
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
ner 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, "hid
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
s 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.
validator: Callable | None
default `= None`
a function that takes in the inputs and can optionally return a gr.validate()
object for each input.
|
Initialization
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
Methods
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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.
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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
completes successfully will the main function be called. The validator
receives the same inputs as the main function and should return a
`gr.validate()` for each input value.
|
load
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
ne object to use.
|
from_pipeline
|
https://gradio.app/docs/gradio/interface#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue 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#interface-queue
|
Gradio - Interface#Interface Queue Docs
|
Group is a layout element within Blocks which groups together children so
that they do not have any padding or margin between them.
|
Description
|
https://gradio.app/docs/gradio/group
|
Gradio - Group Docs
|
with gr.Group():
gr.Textbox(label="First")
gr.Textbox(label="Last")
|
Example Usage
|
https://gradio.app/docs/gradio/group
|
Gradio - Group Docs
|
Parameters ▼
visible: bool | Literal['hidden']
default `= True`
If False, group will be hidden.
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional string or list of strings that are assigned as the class of this
component in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, this layout will not be rendered in the Blocks context. Should be
used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= None`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
provided during constructor.
|
Initialization
|
https://gradio.app/docs/gradio/group
|
Gradio - Group Docs
|
Creates an image component that can be used to upload images (as an input)
or display images (as an output).
|
Description
|
https://gradio.app/docs/gradio/simpleimage
|
Gradio - Simpleimage Docs
|
**As input component** : A `str` containing the path to the image.
Your function should accept one of these types:
def predict(
value: str | None
)
...
**As output component** : Expects a `str` or `pathlib.Path` object
containing the path to the image.
Your function should return one of these types:
def predict(···) -> str | Path | None
...
return value
|
Behavior
|
https://gradio.app/docs/gradio/simpleimage
|
Gradio - Simpleimage Docs
|
Parameters ▼
value: str | None
default `= None`
A path or URL for the default value that SimpleImage component is going to
take. If a function is provided, the function will be called each time the app
loads to set the initial value of this component.
label: str | I18nData | None
default `= None`
the label for this component, displayed above the component if `show_label` is
`True` and is also used as the header if there are a table of examples for
this component. If None and used in a `gr.Interface`, the label will be the
name of the parameter this component corresponds to.
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 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
|
Initialization
|
https://gradio.app/docs/gradio/simpleimage
|
Gradio - Simpleimage Docs
|
ll_height=True.
min_width: int
default `= 160`
minimum pixel width, will wrap if not sufficient screen space to satisfy this
value. If a certain scale value results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, will allow users to upload and edit an image; if False, can only be
used to display images. If not provided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in the HTML DOM. Can be used for targeting CSS styles.
render: bool
default `= True`
If False, component will not render be rendered in the Blocks context. Should
be used if the intention is to assign event listeners now but render the
component later.
key: int | str | tuple[int | str, ...] | None
default `= None`
in a gr.render, Components with the same key across re-renders are treated as
the same component, not a new component. Properties set in 'preserved_by_key'
are not reset across a re-render.
preserved_by_key: list[str] | str | None
default `= "value"`
A list of parameters from this component's constructor. Inside a gr.render()
function, if a component is re-rendered with the same key, these (and only
these) parameters will be preserved in the UI (if they have been changed by
the user or an event listener) instead of re-rendered based on the values
|
Initialization
|
https://gradio.app/docs/gradio/simpleimage
|
Gradio - Simpleimage Docs
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.