text
stringlengths
0
2k
heading1
stringlengths
4
79
source_page_url
stringclasses
180 values
source_page_title
stringclasses
180 values
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/dataset
Gradio - Dataset Docs
r 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 in
Event Listeners
https://gradio.app/docs/gradio/dataset
Gradio - Dataset 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/dataset
Gradio - Dataset Docs
Set the static paths to be served by the gradio app. Static files are are served directly from the file system instead of being copied. They are served to users with The Content-Disposition HTTP header set to "inline" when sending these files to users. This indicates that the file should be displayed directly in the browser window if possible. This function is useful when you want to serve files that you know will not be modified during the lifetime of the gradio app (like files used in gr.Examples). By setting static paths, your app will launch faster and it will consume less disk space. Calling this function will set the static paths for all gradio applications defined in the same interpreter session until it is called again or the session ends.
Description
https://gradio.app/docs/gradio/set_static_paths
Gradio - Set_Static_Paths Docs
import gradio as gr Paths can be a list of strings or pathlib.Path objects corresponding to filenames or directories. gr.set_static_paths(paths=["test/test_files/"]) The example files and the default value of the input will not be copied to the gradio cache and will be served directly. demo = gr.Interface( lambda s: s.rotate(45), gr.Image(value="test/test_files/cheetah1.jpg", type="pil"), gr.Image(), examples=["test/test_files/bus.png"], ) demo.launch()
Example Usage
https://gradio.app/docs/gradio/set_static_paths
Gradio - Set_Static_Paths Docs
Parameters ▼ paths: str | Path | list[str | Path] filepath or list of filepaths or directory names to be served by the gradio app. If it is a directory name, ALL files located within that directory will be considered static and not moved to the gradio cache. This also means that ALL files in that directory will be accessible over the network.
Initialization
https://gradio.app/docs/gradio/set_static_paths
Gradio - Set_Static_Paths Docs
Mount a gradio.Blocks to an existing FastAPI application.
Description
https://gradio.app/docs/gradio/mount_gradio_app
Gradio - Mount_Gradio_App Docs
from fastapi import FastAPI import gradio as gr app = FastAPI() @app.get("/") def read_main(): return {"message": "This is your main app"} io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox") app = gr.mount_gradio_app(app, io, path="/gradio") Then run `uvicorn run:app` from the terminal and navigate to http://localhost:8000/gradio.
Example Usage
https://gradio.app/docs/gradio/mount_gradio_app
Gradio - Mount_Gradio_App Docs
Parameters ▼ app: fastapi.FastAPI The parent FastAPI application. blocks: gradio.Blocks The blocks object we want to mount to the parent app. path: str The path at which the gradio application will be mounted, e.g. "/gradio". server_name: str default `= "0.0.0.0"` The server name on which the Gradio app will be run. server_port: int default `= 7860` The port on which the Gradio app will be run. show_api: bool | None default `= None` If False, hides the "Use via API" button on the Gradio interface. app_kwargs: dict[str, Any] | None default `= None` Additional keyword arguments to pass to the underlying FastAPI app as a dictionary of parameter keys and argument values. For example, `{"docs_url": "/docs"}` auth: Callable | tuple[str, str] | list[tuple[str, str]] | None default `= None` If provided, username and password (or list of username-password tuples) required to access the gradio app. Can also provide function that takes username and password and returns True if valid login. auth_message: str | None default `= None` If provided, HTML message provided on login page for this gradio app. auth_dependency: Callable[[fastapi.Request], str | None] | None default `= None` A function that takes a FastAPI request and returns a string user ID or None. If the function returns None for a specific request, that user is not authorized to access the gradio app (they will see a 401 Unauthorized response). To be used with external authentication systems like OAuth. Cannot be used with `auth`. root_path: str | None default `= None` The subpath corresponding to the public deployment of this FastAPI application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". A full URL beginning with http:// or https:// can be provided, wh
Initialization
https://gradio.app/docs/gradio/mount_gradio_app
Gradio - Mount_Gradio_App Docs
tAPI application. For example, if the application is served at "https://example.com/myapp", the `root_path` should be set to "/myapp". A full URL beginning with http:// or https:// can be provided, which will be used in its entirety. Normally, this does not need to provided (even if you are using a custom `path`). However, if you are serving the FastAPI app behind a proxy, the proxy may not provide the full path to the Gradio app in the request headers. In which case, you can provide the root path here. allowed_paths: list[str] | None default `= None` List of complete filepaths or parent directories that this gradio app is allowed to serve. Must be absolute paths. Warning: if you provide directories, any files in these directories or their subdirectories are accessible to all users of your app. blocked_paths: list[str] | None default `= None` List of complete filepaths or parent directories that this gradio app is not allowed to serve (i.e. users of your app are not allowed to access). Must be absolute paths. Warning: takes precedence over `allowed_paths` and all other directories exposed by Gradio by default. favicon_path: str | None default `= None` If a path to a file (.png, .gif, or .ico) is provided, it will be used as the favicon for this gradio app's page. show_error: bool default `= True` If True, any errors in the gradio app will be displayed in an alert modal and printed in the browser console log. Otherwise, errors will only be visible in the terminal session running the Gradio app. max_file_size: str | int | None default `= None` The maximum file size in bytes that can be uploaded. Can be a string of the form "<value><unit>", where value is any positive integer and unit is one of "b", "kb", "mb", "gb", "tb". If None, no limit is set. ssr_mode: bool | None default `= None` If True, the Gradio app will be rendered using server-side rendering mode, wh
Initialization
https://gradio.app/docs/gradio/mount_gradio_app
Gradio - Mount_Gradio_App Docs
is one of "b", "kb", "mb", "gb", "tb". If None, no limit is set. ssr_mode: bool | None default `= None` If True, the Gradio app will be rendered using server-side rendering mode, which is typically more performant and provides better SEO, but this requires Node 20+ to be installed on the system. If False, the app will be rendered using client-side rendering mode. If None, will use GRADIO_SSR_MODE environment variable or default to False. node_server_name: str | None default `= None` The name of the Node server to use for SSR. If None, will use GRADIO_NODE_SERVER_NAME environment variable or search for a node binary in the system. node_port: int | None default `= None` The port on which the Node server should run. If None, will use GRADIO_NODE_SERVER_PORT environment variable or find a free port. enable_monitoring: bool | None default `= None` pwa: bool | None default `= None` i18n: I18n | None default `= None` If provided, the i18n instance to use for this gradio app. mcp_server: bool | None default `= None` If True, the MCP server will be launched on the gradio app. If None, will use GRADIO_MCP_SERVER environment variable or default to False.
Initialization
https://gradio.app/docs/gradio/mount_gradio_app
Gradio - Mount_Gradio_App Docs
Sets up an API or MCP endpoint for a generic function without needing define events listeners or components. Derives its typing from type hints in the provided function's signature rather than the components.
Description
https://gradio.app/docs/gradio/api
Gradio - Api Docs
import gradio as gr with gr.Blocks() as demo: with gr.Row(): input = gr.Textbox() button = gr.Button("Submit") output = gr.Textbox() def fn(a: int, b: int, c: list[str]) -> tuple[int, str]: return a + b, c[a:b] gr.api(fn, api_name="add_and_slice") _, url, _ = demo.launch() from gradio_client import Client client = Client(url) result = client.predict( a=3, b=5, c=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], api_name="/add_and_slice" ) print(result)
Example Usage
https://gradio.app/docs/gradio/api
Gradio - Api Docs
Parameters ▼ fn: Callable | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. The function should be fully typed, and the type hints will be used to derive the typing information for the API/MCP endpoint. api_name: str | None | Literal[False] default `= None` Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, will use the functions name as the endpoint route. If set to a string, the endpoint will be exposed in the api docs with the given name. api_description: str | None default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) concurrency_limit: int | None | Literal['default'] default `= "default"` I
Initialization
https://gradio.app/docs/gradio/api
Gradio - Api Docs
Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running 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` The time limit for the function to run. Parameter only used for the `.stream()` event. stream_every: float default `= 0.5` The latency (in seconds) at which stream chunks are sent to the backend. Defaults to 0.5 seconds. Parameter only used for the `.stream()` event.
Initialization
https://gradio.app/docs/gradio/api
Gradio - Api Docs
Row is a layout element within Blocks that renders all children horizontally.
Description
https://gradio.app/docs/gradio/row
Gradio - Row Docs
with gr.Blocks() as demo: with gr.Row(): gr.Image("lion.jpg", scale=2) gr.Image("tiger.jpg", scale=1) demo.launch()
Example Usage
https://gradio.app/docs/gradio/row
Gradio - Row Docs
Parameters ▼ variant: Literal['default', 'panel', 'compact'] default `= "default"` row type, 'default' (no background), 'panel' (gray background color and rounded corners), or 'compact' (rounded corners and no internal gap). visible: bool | Literal['hidden'] default `= True` If False, row will be hidden. elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles. scale: int | None default `= None` relative height compared to adjacent elements. 1 or greater indicates the Row will expand in height, and any child columns will also expand to fill the height. render: bool default `= True` If False, this layout will not be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. height: int | str | None default `= None` The height of the row, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the row will scroll vertically. If not set, the row will expand to fit the content. max_height: int | str | None default `= None` The maximum height of the row, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the row will scroll vertically. If content is shorter than the height, the row will shrink to fit the content. Will not have any effect if `height` is set and is smaller than `max_height`. min_height: int | str | None default `= None` The minimum height of the row, specified in pixels if a number is passed, or in CSS units if a string is
Initialization
https://gradio.app/docs/gradio/row
Gradio - Row Docs
is smaller than `max_height`. min_height: int | str | None default `= None` The minimum height of the row, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the row will expand to fit the content. Will not have any effect if `height` is set and is larger than `min_height`. equal_height: bool default `= False` If True, makes every child element have equal height show_progress: bool default `= False` If True, shows progress animation when being updated. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= None` A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
Initialization
https://gradio.app/docs/gradio/row
Gradio - Row Docs
Creates a numeric field for user to enter numbers as input or display numeric output.
Description
https://gradio.app/docs/gradio/number
Gradio - Number Docs
**As input component** : Passes field value as a `float` or `int` into the function, depending on `precision`. Your function should accept one of these types: def predict( value: float | int | None ) ... **As output component** : Expects an `int` or `float` returned from the function and sets field value to it. Your function should return one of these types: def predict(···) -> float | int | None ... return value
Behavior
https://gradio.app/docs/gradio/number
Gradio - Number Docs
Parameters ▼ value: float | Callable | None default `= None` default value. If None, the component will be empty and show the `placeholder` if is set. If no `placeholder` is set, the component will show 0. 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. placeholder: str | I18nData | None default `= None` placeholder hint to provide behind number input. info: str | I18nData | None default `= None` additional component description, appears below the label in smaller font. Supports markdown / HTML syntax. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if 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 applie
Initialization
https://gradio.app/docs/gradio/number
Gradio - Number Docs
` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, will be editable; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. visible: bool | Literal['hidden'] default `= True` If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. render: bool default `= True` If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component 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() funct
Initialization
https://gradio.app/docs/gradio/number
Gradio - Number Docs
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. precision: int | None default `= None` Precision to round input/output to. If set to 0, will round to nearest integer and convert type to int. If None, no rounding happens. minimum: float | None default `= None` Minimum value. Only applied when component is used as an input. If a user provides a smaller value, a gr.Error exception is raised by the backend. maximum: float | None default `= None` Maximum value. Only applied when component is used as an input. If a user provides a larger value, a gr.Error exception is raised by the backend. step: float default `= 1` The interval between allowed numbers in the component. Can be used along with optional parameters `minimum` and `maximum` to create a range of legal values starting from `minimum` and incrementing according to this parameter.
Initialization
https://gradio.app/docs/gradio/number
Gradio - Number Docs
Class | Interface String Shortcut | Initialization ---|---|--- `gradio.Number` | "number" | Uses default values
Shortcuts
https://gradio.app/docs/gradio/number
Gradio - Number Docs
tax_calculatorblocks_simple_squares Open in 🎢 ↗ import gradio as gr def tax_calculator(income, marital_status, assets): tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)] total_deductible = sum(assets["Cost"]) taxable_income = income - total_deductible total_tax = 0 for bracket, rate in tax_brackets: if taxable_income > bracket: total_tax += (taxable_income - bracket) * rate / 100 if marital_status == "Married": total_tax *= 0.75 elif marital_status == "Divorced": total_tax *= 0.8 return round(total_tax) demo = gr.Interface( tax_calculator, [ "number", gr.Radio(["Single", "Married", "Divorced"]), gr.Dataframe( headers=["Item", "Cost"], datatype=["str", "number"], label="Assets Purchased this Year", ), ], "number", examples=[ [10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]], [80000, "Single", [["Suit", 800], ["Watch", 1800], ["Car", 800]]], ], ) demo.launch() import gradio as gr def tax_calculator(income, marital_status, assets): tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)] total_deductible = sum(assets["Cost"]) taxable_income = income - total_deductible total_tax = 0 for bracket, rate in tax_brackets: if taxable_income > bracket: total_tax += (taxable_income - bracket) * rate / 100 if marital_status == "Married": total_tax *= 0.75 elif marital_status == "Divorced": total_tax *= 0.8 return round(total_tax) demo = gr.Interface( tax_calculator, [ "number", gr.Radio(["Single", "Married", "Divorced"]), gr.Dataframe( headers=["Item", "Cost"], datatype=["str", "number"], label="Assets Purchased this Year", ), ], "number", examples=[ [10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]],
Demos
https://gradio.app/docs/gradio/number
Gradio - Number Docs
label="Assets Purchased this Year", ), ], "number", examples=[ [10000, "Married", [["Suit", 5000], ["Laptop", 800], ["Car", 1800]]], [80000, "Single", [["Suit", 800], ["Watch", 1800], ["Car", 800]]], ], ) demo.launch() Open in 🎢 ↗ import gradio as gr demo = gr.Blocks(css="""btn {color: red} .abc {font-family: "Comic Sans MS", "Comic Sans", cursive !important}""") with demo: default_json = {"a": "a"} num = gr.State(value=0) squared = gr.Number(value=0) btn = gr.Button("Next Square", elem_id="btn", elem_classes=["abc", "def"]) stats = gr.State(value=default_json) table = gr.JSON() def increase(var, stats_history): var += 1 stats_history[str(var)] = var**2 return var, var**2, stats_history, stats_history btn.click(increase, [num, stats], [num, squared, stats, table]) if __name__ == "__main__": demo.launch() import gradio as gr demo = gr.Blocks(css="""btn {color: red} .abc {font-family: "Comic Sans MS", "Comic Sans", cursive !important}""") with demo: default_json = {"a": "a"} num = gr.State(value=0) squared = gr.Number(value=0) btn = gr.Button("Next Square", elem_id="btn", elem_classes=["abc", "def"]) stats = gr.State(value=default_json) table = gr.JSON() def increase(var, stats_history): var += 1 stats_history[str(var)] = var**2 return var, var**2, stats_history, stats_history btn.click(increase, [num, stats], [num, squared, stats, table]) if __name__ == "__main__": demo.launch()
Demos
https://gradio.app/docs/gradio/number
Gradio - Number 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 Number component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listener | Description ---|--- `Number.change(fn, ···)` | Triggered when the value of the Number 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. `Number.input(fn, ···)` | This listener is triggered when the user changes the value of the Number. `Number.submit(fn, ···)` | This listener is triggered when the user presses the Enter key while the Number is focused. `Number.focus(fn, ···)` | This listener is triggered when the Number is focused. `Number.blur(fn, ···)` | This listener is triggered when the Number is unfocused/blurred. 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 defau
Event Listeners
https://gradio.app/docs/gradio/number
Gradio - Number Docs
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 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 enab
Event Listeners
https://gradio.app/docs/gradio/number
Gradio - Number Docs
n on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['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
Event Listeners
https://gradio.app/docs/gradio/number
Gradio - Number Docs
', '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: 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
Event Listeners
https://gradio.app/docs/gradio/number
Gradio - Number Docs
` 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/number
Gradio - Number Docs
Creates an image component that, as an input, can be used to upload and edit images using simple editing tools such as brushes, strokes, cropping, and layers. Or, as an output, this component can be used to display images.
Description
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
**As input component** : Passes the uploaded images as an instance of EditorValue, which is just a `dict` with keys: 'background', 'layers', and 'composite'. The values corresponding to 'background' and 'composite' are images, while 'layers' is a `list` of images. The images are of type `PIL.Image`, `np.array`, or `str` filepath, depending on the `type` parameter. Your function should accept one of these types: def predict( value: EditorValue | None ) ... **As output component** : Expects a EditorValue, which is just a dictionary with keys: 'background', 'layers', and 'composite'. The values corresponding to 'background' and 'composite' should be images or None, while `layers` should be a list of images. Images can be of type `PIL.Image`, `np.array`, or `str` filepath/URL. Or, the value can be simply a single image (`ImageType`), in which case it will be used as the background. Your function should return one of these types: def predict(···) -> EditorValue | ImageType | None ... return value
Behavior
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
Parameters ▼ value: EditorValue | ImageType | None default `= None` Optional initial image(s) to populate the image editor. Should be a dictionary with keys: `background`, `layers`, and `composite`. The values corresponding to `background` and `composite` should be images or None, while `layers` should be a list of images. Images can be of type PIL.Image, np.array, or str filepath/URL. Or, the value can be a callable, in which case the function will be called whenever the app loads to set the initial value of the component. height: int | str | None default `= None` The height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. This has no effect on the preprocessed image files or numpy arrays, but will affect the displayed images. Beware of conflicting values with the canvas_size paramter. If the canvas_size is larger than the height, the editing canvas will not fit in the component. width: int | str | None default `= None` The width of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. This has no effect on the preprocessed image files or numpy arrays, but will affect the displayed images. Beware of conflicting values with the canvas_size paramter. If the canvas_size is larger than the height, the editing canvas will not fit in the component. image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] default `= "RGBA"` "RGB" if color, or "L" if black and white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other supported image modes and their meaning. sources: Iterable[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | None default `= ('upload', 'webcam', 'clipboard')` List of sources that can be used to set the background image. "upload" creates a box where user can drop an image file, "webc
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
bcam', 'clipboard'] | None default `= ('upload', 'webcam', 'clipboard')` List of sources that can be used to set the background image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "clipboard" allows users to paste an image from the clipboard. type: Literal['numpy', 'pil', 'filepath'] default `= "numpy"` The format the images are converted to before being passed into the prediction function. "numpy" converts the images to numpy arrays with shape (height, width, 3) and values from 0 to 255, "pil" converts the images to PIL image objects, "filepath" passes images as str filepaths to temporary copies of the images. label: str | I18nData | None default `= None` the label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if True, will display label. show_download_button: bool default `= True` If True, will display button to download image. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Componen
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
ue` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output. visible: bool | 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
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
nt | 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. placeholder: str | None default `= None` Custom text for the upload area. Overrides default upload messages when provided. Accepts new lines and `` to designate a heading. mirror_webcam: bool | None default `= None` show_share_button: bool | None default `= None` If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise. crop_size: tuple[int | float, int | float] | str | None default `= None` Deprecated. Used to set the `canvas_size` parameter. transforms: Iterable[Literal['crop', 'resize']] | None default `= ('crop', 'resize')` The transforms tools to make available to users. "crop" allows the user to crop the image. eraser: Eraser | None | Literal[False] default `= None` The options for the eraser tool in the image editor. Should be an instance of the `gr.Eraser` class, or None to use the default settings. Can also be False to hide the eraser tool. See `gr.Eraser` docs. brush: Brush | None | Literal[False] default `= None` The options for the brush tool in the image editor. Should be an insta
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
o be False to hide the eraser tool. See `gr.Eraser` docs. brush: Brush | None | Literal[False] default `= None` The options for the brush tool in the image editor. Should be an instance of the `gr.Brush` class, or None to use the default settings. Can also be False to hide the brush tool, which will also hide the eraser tool. See `gr.Brush` docs. format: str default `= "webp"` Format to save image if it does not already have a valid format (e.g. if the image is being returned to the frontend as a numpy array or PIL Image). The format should be supported by the PIL library. This parameter has no effect on SVG files. layers: bool | LayerOptions default `= True` The options for the layer tool in the image editor. Can be a boolean or an instance of the `gr.LayerOptions` class. If True, will allow users to add layers to the image. If False, the layers option will be hidden. If an instance of `gr.LayerOptions`, it will be used to configure the layer tool. See `gr.LayerOptions` docs. canvas_size: tuple[int, int] default `= (800, 800)` The initial size of the canvas in pixels. The first value is the width and the second value is the height. If `fixed_canvas` is `True`, uploaded images will be rescaled to fit the canvas size while preserving the aspect ratio. Otherwise, the canvas size will change to match the size of an uploaded image. fixed_canvas: bool default `= False` If True, the canvas size will not change based on the size of the background image and the image will be rescaled to fit (while preserving the aspect ratio) and placed in the center of the canvas. show_fullscreen_button: bool default `= True` If True, will display button to view image in fullscreen mode. webcam_options: WebcamOptions | None default `= None` The options for the webcam tool in the image editor. Can be an instance of the `gr.WebcamOptions` class, or None to use the def
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
webcam_options: WebcamOptions | None default `= None` The options for the webcam tool in the image editor. Can be an instance of the `gr.WebcamOptions` class, or None to use the default settings. See `gr.WebcamOptions` docs.
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
Class | Interface String Shortcut | Initialization ---|---|--- `gradio.ImageEditor` | "imageeditor" | Uses default values `gradio.Sketchpad` | "sketchpad" | Uses sources=(), brush=Brush(colors=["000000"], color_mode="fixed") `gradio.Paint` | "paint" | Uses sources=() `gradio.ImageMask` | "imagemask" | Uses brush=Brush(colors=["000000"], color_mode="fixed")
Shortcuts
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
image_editor Open in 🎢 ↗ import gradio as gr import time def sleep(im): time.sleep(5) return [im["background"], im["layers"][0], im["layers"][1], im["composite"]] def predict(im): return im["composite"] with gr.Blocks() as demo: with gr.Row(): im = gr.ImageEditor( type="numpy", crop_size="1:1", ) im_preview = gr.Image() n_upload = gr.Number(0, label="Number of upload events", step=1) n_change = gr.Number(0, label="Number of change events", step=1) n_input = gr.Number(0, label="Number of input events", step=1) im.upload(lambda x: x + 1, outputs=n_upload, inputs=n_upload) im.change(lambda x: x + 1, outputs=n_change, inputs=n_change) im.input(lambda x: x + 1, outputs=n_input, inputs=n_input) im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden") if __name__ == "__main__": demo.launch() import gradio as gr import time def sleep(im): time.sleep(5) return [im["background"], im["layers"][0], im["layers"][1], im["composite"]] def predict(im): return im["composite"] with gr.Blocks() as demo: with gr.Row(): im = gr.ImageEditor( type="numpy", crop_size="1:1", ) im_preview = gr.Image() n_upload = gr.Number(0, label="Number of upload events", step=1) n_change = gr.Number(0, label="Number of change events", step=1) n_input = gr.Number(0, label="Number of input events", step=1) im.upload(lambda x: x + 1, outputs=n_upload, inputs=n_upload) im.change(lambda x: x + 1, outputs=n_change, inputs=n_change) im.input(lambda x: x + 1, outputs=n_input, inputs=n_input) im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden") if __name__ == "__main__": demo.launch()
Demos
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
Description Event listeners allow you to respond to user interactions with the UI components you've defined in a Gradio Blocks app. When a user interacts with an element, such as changing a slider value or uploading an image, a function is called. Supported Event Listeners The ImageEditor component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listener | Description ---|--- `ImageEditor.clear(fn, ···)` | This listener is triggered when the user clears the ImageEditor using the clear button for the component. `ImageEditor.change(fn, ···)` | Triggered when the value of the ImageEditor changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. `ImageEditor.input(fn, ···)` | This listener is triggered when the user changes the value of the ImageEditor. `ImageEditor.select(fn, ···)` | Event listener for when the user selects or deselects the ImageEditor. Uses event data gradio.SelectData to carry `value` referring to the label of the ImageEditor, and `selected` to refer to state of the ImageEditor. See EventData documentation on how to use this event data `ImageEditor.upload(fn, ···)` | This listener is triggered when the user uploads a file into the ImageEditor. `ImageEditor.apply(fn, ···)` | This listener is triggered when the user applies changes to the ImageEditor through an integrated UI action. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each ele
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
ten a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None | Literal[False] default `= None` defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "mi
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
ne default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. show_api: bool default `= True` whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps as well as the Clients to use this ev
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps as well as the Clients to use this event. If fn is None, show_api will automatically be set to False. time_limit: int | None default `= None` stream_every: float default `= 0.5` like_user_message: bool default `= False` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. 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/imageeditor
Gradio - Imageeditor Docs
Helper Classes
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
gradio.Brush(···) Description A dataclass for specifying options for the brush tool in the ImageEditor component. An instance of this class can be passed to the `brush` parameter of `gr.ImageEditor`. Initialization Parameters ▼ default_size: int | Literal['auto'] default `= "auto"` The default radius, in pixels, of the brush tool. Defaults to "auto" in which case the radius is automatically determined based on the size of the image (generally 1/50th of smaller dimension). colors: list[str | tuple[str, float]] | str | tuple[str, float] | None default `= None` A list of colors to make available to the user when using the brush. Defaults to a list of 5 colors. default_color: str | tuple[str, float] | None default `= None` The default color of the brush. Defaults to the first color in the `colors` list. color_mode: Literal['fixed', 'defaults'] default `= "defaults"` If set to "fixed", user can only select from among the colors in `colors`. If "defaults", the colors in `colors` are provided as a default palette, but the user can also select any color using a color picker.
Brush
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
gradio.Eraser(···) Description A dataclass for specifying options for the eraser tool in the ImageEditor component. An instance of this class can be passed to the `eraser` parameter of `gr.ImageEditor`. Initialization Parameters ▼ default_size: int | Literal['auto'] default `= "auto"` The default radius, in pixels, of the eraser tool. Defaults to "auto" in which case the radius is automatically determined based on the size of the image (generally 1/50th of smaller dimension).
Eraser
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
gradio.LayerOptions(···) Description A dataclass for specifying options for the layer tool in the ImageEditor component. An instance of this class can be passed to the `layers` parameter of `gr.ImageEditor`. Initialization Parameters ▼ allow_additional_layers: bool default `= True` If True, users can add additional layers to the image. If False, the add layer button will not be shown. layers: list[str] | None default `= None` A list of layers to make available to the user when using the layer tool. One layer must be provided, if the length of the list is 0 then a layer will be generated automatically. disabled: bool default `= False`
Layer Options
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
gradio.WebcamOptions(···) Description A dataclass for specifying options for the webcam tool in the ImageEditor component. An instance of this class can be passed to the `webcam_options` parameter of `gr.ImageEditor`. Initialization Parameters ▼ mirror: bool default `= True` If True, the webcam will be mirrored. constraints: dict[str, Any] | None default `= None` A dictionary of constraints for the webcam.
Webcam Options
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
Displays a classification label, along with confidence scores of top categories, if provided. As this component does not accept user input, it is rarely used as an input component.
Description
https://gradio.app/docs/gradio/label
Gradio - Label Docs
**As input component** : Depending on the value, passes the label as a `str | int | float`, or the labels and confidences as a `dict[str, float]`. Your function should accept one of these types: def predict( value: dict[str, float] | str | int | float | None ) ... **As output component** : Expects a `dict[str, float]` of classes and confidences, or `str` with just the class or an `int | float` for regression outputs, or a `str` path to a .json file containing a json dictionary in one of the preceding formats. Your function should return one of these types: def predict(···) -> dict[str, float] | str | int | float | None ... return value
Behavior
https://gradio.app/docs/gradio/label
Gradio - Label Docs
Parameters ▼ value: dict[str, float] | str | float | Callable | None default `= None` Default value to show in the component. If a str or number is provided, simply displays the string or number. If a {Dict[str, float]} of classes and confidences is provided, displays the top class on top and the `num_top_classes` below, along with their confidence bars. If a function is provided, the function will be called each time the app loads to set the initial value of this component. num_top_classes: int | None default `= None` number of most confident classes to show. 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 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_he
Initialization
https://gradio.app/docs/gradio/label
Gradio - Label Docs
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: 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. color: str | Non
Initialization
https://gradio.app/docs/gradio/label
Gradio - Label Docs
meters 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. color: str | None default `= None` The background color of the label (either a valid css color name or hexadecimal string). show_heading: bool default `= True` If False, the heading will not be displayed if a dictionary of labels and confidences is provided. The heading will still be visible if the value is a string or number.
Initialization
https://gradio.app/docs/gradio/label
Gradio - Label Docs
Class | Interface String Shortcut | Initialization ---|---|--- `gradio.Label` | "label" | Uses default values
Shortcuts
https://gradio.app/docs/gradio/label
Gradio - Label 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 Label component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listener | Description ---|--- `Label.change(fn, ···)` | Triggered when the value of the Label 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. `Label.select(fn, ···)` | Event listener for when the user selects or deselects the Label. Uses event data gradio.SelectData to carry `value` referring to the label of the Label, and `selected` to refer to state of the Label. See EventData documentation on how to use this event data Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an emp
Event Listeners
https://gradio.app/docs/gradio/label
Gradio - Label Docs
ontext | 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 queue, even if the queue has been enabled. If None, will use the queu
Event Listeners
https://gradio.app/docs/gradio/label
Gradio - Label Docs
lt `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would al
Event Listeners
https://gradio.app/docs/gradio/label
Gradio - Label Docs
not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. 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
Event Listeners
https://gradio.app/docs/gradio/label
Gradio - Label Docs
ener 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/label
Gradio - Label Docs
Creates a bar plot component to display data from a pandas DataFrame.
Description
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
**As input component** : The data to display in a line plot. Your function should accept one of these types: def predict( value: AltairPlotData ) ... **As output component** : Expects a pandas DataFrame containing the data to display in the line plot. The DataFrame should contain at least two columns, one for the x-axis (corresponding to this component's `x` argument) and one for the y-axis (corresponding to `y`). Your function should return one of these types: def predict(···) -> pd.DataFrame | None ... return value
Behavior
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
Parameters ▼ value: pd.DataFrame | Callable | None default `= None` The pandas dataframe containing the data to display in the plot. x: str | None default `= None` Column corresponding to the x axis. Column can be numeric, datetime, or string/category. y: str | None default `= None` Column corresponding to the y axis. Column must be numeric. color: str | None default `= None` Column corresponding to series, visualized by color. Column must be string/category. title: str | None default `= None` The title to display on top of the chart. x_title: str | None default `= None` The title given to the x axis. By default, uses the value of the x parameter. y_title: str | None default `= None` The title given to the y axis. By default, uses the value of the y parameter. color_title: str | None default `= None` The title given to the color legend. By default, uses the value of color parameter. x_bin: str | float | None default `= None` Grouping used to cluster x values. If x column is numeric, should be number to bin the x values. If x column is datetime, should be string such as "1h", "15m", "10s", using "s", "m", "h", "d" suffixes. y_aggregate: Literal['sum', 'mean', 'median', 'min', 'max', 'count'] | None default `= None` Aggregation function used to aggregate y values, used if x_bin is provided or x is a string/category. Must be one of "sum", "mean", "median", "min", "max". color_map: dict[str, str] | None default `= None` Mapping of series to color names or codes. For example, {"success": "green", "fail": "FF8888"}. x_lim: list[float] | None default `= None` A tuple or list containing the limits for the x-axis, specified as [x_min, x_max]. If x column is datetime type, x_lim should be timestamps. y_lim: list[float | None] default `= None` A
Initialization
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
ple or list containing the limits for the x-axis, specified as [x_min, x_max]. If x column is datetime type, x_lim should be timestamps. y_lim: list[float | None] default `= None` A tuple of list containing the limits for the y-axis, specified as [y_min, y_max]. To fix only one of these values, set the other to None, e.g. [0, None] to scale from 0 to the maximum to value. x_label_angle: float default `= 0` The angle of the x-axis labels in degrees offset clockwise. y_label_angle: float default `= 0` The angle of the y-axis labels in degrees offset clockwise. x_axis_labels_visible: bool | Literal['hidden'] default `= True` Whether the x-axis labels should be visible. Can be hidden when many x-axis labels are present. caption: str | I18nData | None default `= None` The (optional) caption to display below the plot. sort: Literal['x', 'y', '-x', '-y'] | list[str] | None default `= None` The sorting order of the x values, if x column is type string/category. Can be "x", "y", "-x", "-y", or list of strings that represent the order of the categories. tooltip: Literal['axis', 'none', 'all'] | list[str] default `= "axis"` The tooltip to display when hovering on a point. "axis" shows the values for the axis columns, "all" shows all column values, and "none" shows no tooltips. Can also provide a list of strings representing columns to show in the tooltip, which will be displayed along with axis values. height: int | None default `= None` The height of the plot in pixels. label: str | I18nData | None default `= None` The (optional) label to display on the top left corner of the plot. show_label: bool | None default `= None` Whether the label should be displayed. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the
Initialization
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
default `= None` Whether the label should be displayed. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | Set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. visible: bool | Literal['hidden'] default `= True` Whether the plot should be visible. elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional list of strings that are 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 re
Initialization
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
S 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. show_fullscreen_button: bool default `= False` If True, will show a button to make plot visible in fullscreen mode. show_export_button: bool default `= False` If True, will show a button to export and download the current view of the plot as a PNG image. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= "value"` A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
Initialization
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
Class | Interface String Shortcut | Initialization ---|---|--- `gradio.BarPlot` | "barplot" | Uses default values
Shortcuts
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
bar_plot_demo Open in 🎢 ↗ import pandas as pd from random import randint, random import gradio as gr temp_sensor_data = pd.DataFrame( { "time": pd.date_range("2021-01-01", end="2021-01-05", periods=200), "temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)], "humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)], "location": ["indoor", "outdoor"] * 100, } ) food_rating_data = pd.DataFrame( { "cuisine": [["Italian", "Mexican", "Chinese"][i % 3] for i in range(100)], "rating": [random() * 4 + 0.5 * (i % 3) for i in range(100)], "price": [randint(10, 50) + 4 * (i % 3) for i in range(100)], "wait": [random() for i in range(100)], } ) with gr.Blocks() as bar_plots: with gr.Row(): start = gr.DateTime("2021-01-01 00:00:00", label="Start") end = gr.DateTime("2021-01-05 00:00:00", label="End") apply_btn = gr.Button("Apply", scale=0) with gr.Row(): group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by") aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation") temp_by_time = gr.BarPlot( temp_sensor_data, x="time", y="temperature", ) temp_by_time_location = gr.BarPlot( temp_sensor_data, x="time", y="temperature", color="location", ) time_graphs = [temp_by_time, temp_by_time_location] group_by.change( lambda group: [gr.BarPlot(x_bin=None if group == "None" else group)] * len(time_graphs), group_by, time_graphs ) aggregate.change( lambda aggregate: [gr.BarPlot(y_aggregate=aggregate)] * len(time_graphs), aggregate, time_graphs ) def rescale(select: gr.SelectData): return select.index rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end]) for trigger in [apply_btn.click, rescale_evt.then]: trigger( lambda start, end: [gr.BarPlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs ) with gr.Row(): price_by_cuisine = gr.BarPlot( food_rating_data, x="cuisine", y="price", ) with gr.Column(scale=0): gr.Button("Sort $
Demos
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
_lim=[start, end])] * len(time_graphs), [start, end], time_graphs ) with gr.Row(): price_by_cuisine = gr.BarPlot( food_rating_data, x="cuisine", y="price", ) with gr.Column(scale=0): gr.Button("Sort $ > $$$").click(lambda: gr.BarPlot(sort="y"), None, price_by_cuisine) gr.Button("Sort $$$ > $").click(lambda: gr.BarPlot(sort="-y"), None, price_by_cuisine) gr.Button("Sort A > Z").click(lambda: gr.BarPlot(sort=["Chinese", "Italian", "Mexican"]), None, price_by_cuisine) with gr.Row(): price_by_rating = gr.BarPlot( food_rating_data, x="rating", y="price", x_bin=1, ) price_by_rating_color = gr.BarPlot( food_rating_data, x="rating", y="price", color="cuisine", x_bin=1, color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"}, ) if __name__ == "__main__": bar_plots.launch() import pandas as pd from random import randint, random import gradio as gr temp_sensor_data = pd.DataFrame( { "time": pd.date_range("2021-01-01", end="2021-01-05", periods=200), "temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)], "humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)], "location": ["indoor", "outdoor"] * 100, } ) food_rating_data = pd.DataFrame( { "cuisine": [["Italian", "Mexican", "Chinese"][i % 3] for i in range(100)], "rating": [random() * 4 + 0.5 * (i % 3) for i in range(100)], "price": [randint(10, 50) + 4 * (i % 3) for i in range(100)], "wait": [random() for i in range(100)], } ) with gr.Blocks() as bar_plots: with gr.Row(): start = gr.DateTime("2021-01-01 00:00:00", label="Start") end = gr.DateTime("2021-01-05 00:00:00", label="End") apply_btn = gr.Button("Apply", scale=0) with gr.Row(): group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Gro
Demos
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
021-01-05 00:00:00", label="End") apply_btn = gr.Button("Apply", scale=0) with gr.Row(): group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by") aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation") temp_by_time = gr.BarPlot( temp_sensor_data, x="time", y="temperature", ) temp_by_time_location = gr.BarPlot( temp_sensor_data, x="time", y="temperature", color="location", ) time_graphs = [temp_by_time, temp_by_time_location] group_by.change( lambda group: [gr.BarPlot(x_bin=None if group == "None" else group)] * len(time_graphs), group_by, time_graphs ) aggregate.change( lambda aggregate: [gr.BarPlot(y_aggregate=aggregate)] * len(time_graphs), aggregate, time_graphs ) def rescale(select: gr.SelectData): return select.index rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end]) for trigger in [apply_btn.click, rescale_evt.then]: trigger( lambda start, end: [gr.BarPlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs ) with gr.Row(): price_by_cuisine = gr.BarPlot( food_rating_data, x="cuisine", y="price", ) with gr.Column(scale=0): gr.Button("Sort $ > $$$").click(lambda: gr.BarPlot(sort="y"), None, price_by_cuisine) gr.Button("Sort $$$ > $").click(lambda: gr.BarPlot(sort="-y"), None, price_by_cuisine) gr.Button("Sort A > Z").click(lambda: gr.BarPlot(sort=["Chinese", "Italian", "Mexican"]), None, price_by_cuisine) with gr.Row():
Demos
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
sort="-y"), None, price_by_cuisine) gr.Button("Sort A > Z").click(lambda: gr.BarPlot(sort=["Chinese", "Italian", "Mexican"]), None, price_by_cuisine) with gr.Row(): price_by_rating = gr.BarPlot( food_rating_data, x="rating", y="price", x_bin=1, ) price_by_rating_color = gr.BarPlot( food_rating_data, x="rating", y="price", color="cuisine", x_bin=1, color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"}, ) if __name__ == "__main__": bar_plots.launch()
Demos
https://gradio.app/docs/gradio/barplot
Gradio - Barplot 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 BarPlot component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listener | Description ---|--- `BarPlot.select(fn, ···)` | Event listener for when the user selects or deselects the NativePlot. Uses event data gradio.SelectData to carry `value` referring to the label of the NativePlot, and `selected` to refer to state of the NativePlot. See EventData documentation on how to use this event data `BarPlot.double_click(fn, ···)` | Triggered when the NativePlot is double clicked. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None | 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
Event Listeners
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
list. api_name: str | None | Literal[False] default `= None` defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each pa
Event Listeners
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for
Event Listeners
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
w 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. 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 vali
Event Listeners
https://gradio.app/docs/gradio/barplot
Gradio - Barplot Docs
alidation 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/barplot
Gradio - Barplot Docs
The Progress class provides a custom progress tracker that is used in a function signature. To attach a Progress tracker to a function, simply add a parameter right after the input parameters that has a default value set to a `gradio.Progress()` instance. The Progress tracker can then be updated in the function by calling the Progress object or using the `tqdm` method on an Iterable.
Description
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
import gradio as gr import time def my_function(x, progress=gr.Progress()): progress(0, desc="Starting...") time.sleep(1) for i in progress.tqdm(range(100)): time.sleep(0.1) return x gr.Interface(my_function, gr.Textbox(), gr.Textbox()).queue().launch()
Example Usage
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
Parameters ▼ track_tqdm: bool default `= False` If True, the Progress object will track any tqdm.tqdm iterations with the tqdm library in the function.
Initialization
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
Methods
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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) gradio.Progress.__call__(progress, ···) Description ![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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%20Fontic
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e) Updates progress tracker with progress and message text. Parameters ▼ progress: float | tuple[int, int | None] | None If float, should be between 0 and 1 representing completion. If Tuple, first number represents steps completed, and second value represents total steps or None if unknown. If None, hides progress bar. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
None if unknown. If None, hides progress bar. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total number of steps. unit: str default `= "steps"` unit of iterations.
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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) gradio.Progress.tqdm(iterable, ···) Description ![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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,
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
2'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e) Attaches progress tracker to iterable, like tqdm. Parameters ▼ iterable: Iterable | None iterable to attach progress tracker to. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total number of steps. unit: str default `= "steps"` unit of iterations.
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
total number of steps. unit: str default `= "steps"` unit of iterations.
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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) gradio.Progress.__call__(progress, ···) Description ![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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%20Fontic
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
20512'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e) Updates progress tracker with progress and message text. Parameters ▼ progress: float | tuple[int, int | None] | None If float, should be between 0 and 1 representing completion. If Tuple, first number represents steps completed, and second value represents total steps or None if unknown. If None, hides progress bar. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
None if unknown. If None, hides progress bar. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total number of steps. unit: str default `= "steps"` unit of iterations.
__call__
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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) gradio.Progress.tqdm(iterable, ···) Description ![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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,
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
2'%3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e) Attaches progress tracker to iterable, like tqdm. Parameters ▼ iterable: Iterable | None iterable to attach progress tracker to. desc: str | None default `= None` description to display. total: int | float | None default `= None` estimated total number of steps. unit: str default `= "steps"` unit of iterations.
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
total number of steps. unit: str default `= "steps"` unit of iterations.
tqdm
https://gradio.app/docs/gradio/progress
Gradio - Progress Docs
Sidebar is a collapsible panel that renders child components on the left side of the screen within a Blocks layout.
Description
https://gradio.app/docs/gradio/sidebar
Gradio - Sidebar Docs
with gr.Blocks() as demo: with gr.Sidebar(): gr.Textbox() gr.Button()
Example Usage
https://gradio.app/docs/gradio/sidebar
Gradio - Sidebar Docs
Parameters ▼ label: str | I18nData | None default `= None` name of the sidebar. Not displayed to the user. open: bool default `= True` if True, sidebar is open by default. visible: bool | Literal['hidden'] default `= True` 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. width: int | str default `= 320` The width of the sidebar, specified in pixels if a number is passed, or in CSS units if a string is passed. position: Literal['left', 'right'] default `= "left"` The position of the sidebar in the layout, either "left" or "right". Defaults to "left". 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/sidebar
Gradio - Sidebar Docs
Methods
https://gradio.app/docs/gradio/sidebar
Gradio - Sidebar Docs
![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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) gradio.Sidebar.expand(···) Description ![](data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20fill='%23808080'%20viewBox='0%200%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.%2
expand
https://gradio.app/docs/gradio/sidebar
Gradio - Sidebar Docs