text
stringlengths
0
2k
heading1
stringlengths
4
79
source_page_url
stringclasses
183 values
source_page_title
stringclasses
183 values
r(). 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/checkbox
Gradio - Checkbox Docs
Creates a dropdown of choices from which a single entry or multiple entries can be selected (as an input component) or displayed (as an output component).
Description
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
**Using Dropdown as an input component.** How Dropdown will pass its value to your function: Type: `str | int | float | list[str | int | float] | list[int | None] | None` Passes the value of the selected dropdown choice as a `str | int | float` or its index as an `int` into the function, depending on `type`. Or, if `multiselect` is True, passes the values of the selected dropdown choices as a list of corresponding values/indices instead. Example Code import gradio as gr def predict( value: str | int | float | list[str | int | float] | list[int | None] | None ): process value from the Dropdown component return "prediction" interface = gr.Interface(predict, gr.Dropdown(), gr.Textbox()) interface.launch() **Using Dropdown as an output component** How Dropdown expects you to return a value: Type: `str | int | float | list[str | int | float] | None` Expects a `str | int | float` corresponding to the value of the dropdown entry to be selected. Or, if `multiselect` is True, expects a `list` of values corresponding to the selected dropdown entries. Example Code import gradio as gr def predict(text) -> str | int | float | list[str | int | float] | None process value to return to the Dropdown component return value interface = gr.Interface(predict, gr.Textbox(), gr.Dropdown()) interface.launch()
Behavior
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
Parameters ▼ choices: list[str | int | float | tuple[str, str | int | float]] | None default `= None` a list of string or numeric options to choose from. An option can also be a tuple of the form (name, value), where name is the displayed name of the dropdown choice and value is the value to be passed to the function, or returned by the function. value: str | int | float | list[str | int | float] | Callable | DefaultValue | None default `= DefaultValue()` the value selected in dropdown. If `multiselect` is true, this should be list, otherwise a single string or number from among `choices`. By default, the first choice in `choices` is initally selected. If set explicitly to None, no value is initally selected. If a function is provided, the function will be called each time the app loads to set the initial value of this component. type: Literal['value', 'index'] default `= "value"` type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected. multiselect: bool | None default `= None` if True, multiple choices can be selected. allow_custom_value: bool default `= False` if True, allows user to enter a custom value that is not in the list of choices. max_choices: int | None default `= None` maximum number of choices that can be selected. If None, no limit is enforced. filterable: bool default `= True` if True, user will be able to type into the dropdown and filter the choices by typing. Can only be set to False if `allow_custom_value` is False. 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 compon
Initialization
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
`show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to. info: str | I18nData | None default `= None` additional component description, appears below the label in smaller font. Supports markdown / HTML syntax. every: Timer | float | None default `= None` continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if True, will display label. container: bool default `= True` if True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, choices in this dropdown will be selectable; if False, selection will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.
Initialization
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
ne` if True, choices in this dropdown will be selectable; if False, selection 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 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` preserved_by_key: list[str] | str | None default `= "value"` buttons: list[Button] | None default `= None` A list of gr.Button() instances to show in the top right corner of the component. Custom buttons will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button.
Initialization
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
Shortcuts gradio.Dropdown Interface String Shortcut `"dropdown"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
sentence_builder
Demos
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown 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 Dropdown component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners Dropdown.change(fn, ···) Triggered when the value of the Dropdown 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. Dropdown.input(fn, ···) This listener is triggered when the user changes the value of the Dropdown. Dropdown.select(fn, ···) Event listener for when the user selects or deselects the Dropdown. Uses event data gradio.SelectData to carry `value` referring to the label of the Dropdown, and `selected` to refer to state of the Dropdown. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. Dropdown.focus(fn, ···) This listener is triggered when the Dropdown is focused. Dropdown.blur(fn, ···) This listener is triggered when the Dropdown is unfocused/blurred. Dropdown.key_up(fn, ···) This listener is triggered when the user presses a key while the Dropdown is focused. 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.
Event Listeners
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
he function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given 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 s
Event Listeners
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'alway
Event Listeners
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
e 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. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5`
Event Listeners
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
r.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called. The validator receives the same inputs as the main function and should return a `gr.validate()` for each input value.
Event Listeners
https://gradio.app/docs/gradio/dropdown
Gradio - Dropdown Docs
Creates a component with arbitrary HTML. Can include CSS and JavaScript to create highly customized and interactive components.
Description
https://gradio.app/docs/gradio/html
Gradio - Html Docs
**Using HTML as an input component.** How HTML will pass its value to your function: Type: `str | None` (Rarely used) passes the HTML as a `str`. Example Code import gradio as gr def predict( value: str | None ): process value from the HTML component return "prediction" interface = gr.Interface(predict, gr.HTML(), gr.Textbox()) interface.launch() **Using HTML as an output component** How HTML expects you to return a value: Type: `str | None` Expects a `str` consisting of valid HTML. Example Code import gradio as gr def predict(text) -> str | None process value to return to the HTML component return value interface = gr.Interface(predict, gr.Textbox(), gr.HTML()) interface.launch()
Behavior
https://gradio.app/docs/gradio/html
Gradio - Html Docs
Parameters ▼ value: Any | Callable | None default `= None` The HTML content in the ${value} tag in the html_template. For example, if html_template="<p>${value}</p>" and value="Hello, world!", the component will render as `"<p>Hello, world!</p>"`. label: str | I18nData | None default `= None` The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to. html_template: str default `= "${value}"` A string representing the HTML template for this component as a JS template string and Handlebars template. The `${value}` tag will be replaced with the `value` parameter, and all other tags will be filled in with the values from `props`. This element can have children when used in a `with gr.HTML(...):` context, and the children will be rendered to replace `@children` substring, which cannot be nested inside any HTML tags. css_template: str default `= ""` A string representing the CSS template for this component as a JS template string and Handlebars template. The CSS will be automatically scoped to this component, and rules outside a block will target the component's root element. The `${value}` tag will be replaced with the `value` parameter, and all other tags will be filled in with the values from `props`. js_on_load: str | None default `= "element.addEventListener('click', function() { trigger('click') });"` A string representing the JavaScript code that will be executed when the component is loaded. The `element` variable refers to the HTML element of this component, and can be used to access children such as `element.querySelector()`. The `trigger` function can be used to trigger events, such as `trigger('click')`. The value and other props can be edited through `props`, e.g. `props.value = "new value"` which will re-render th
Initialization
https://gradio.app/docs/gradio/html
Gradio - Html Docs
()`. The `trigger` function can be used to trigger events, such as `trigger('click')`. The value and other props can be edited through `props`, e.g. `props.value = "new value"` which will re-render the HTML template. If `server_functions` is provided, a `server` object is also available in `js_on_load`, where each function is accessible as an async method, e.g. `server.list_files(path).then(files => ...)` or `const files = await server.list_files(path)`. The `upload` async function can be used to upload a JavaScript `File` object to the Gradio server, returning a dictionary with `path` (the server-side file path) and `url` (the public URL to access the file), e.g. `const { path, url } = await upload(file)`. apply_default_css: bool default `= True` If True, default Gradio CSS styles will be applied to the HTML component. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool default `= False` If True, the label will be displayed. If False, the label will be hidden. visible: bool | Literal['hidden'] default `= True` If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional list of strings that a
Initialization
https://gradio.app/docs/gradio/html
Gradio - Html Docs
s 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. min_height: int | None default `= None` The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If HTML content exceeds the height, the component will expand to fit the content. max_height: int | None default `= None` The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll. container: bool default `= False` If True, the HTML component will be displayed in a container. Default is False. padding: bool default `= False` If True, the HTML component will have a certain padding (set by the `--block- padding` CSS variable) in all directions. Default
Initialization
https://gradio.app/docs/gradio/html
Gradio - Html Docs
ner. Default is False. padding: bool default `= False` If True, the HTML component will have a certain padding (set by the `--block- padding` CSS variable) in all directions. Default is False. autoscroll: bool default `= False` If True, will automatically scroll to the bottom of the component when the content changes, unless the user has scrolled up. If False, will not scroll to the bottom when the content changes. buttons: list[Button] | None default `= None` A list of gr.Button() instances to show in the top right corner of the component. Custom buttons will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button. server_functions: list[Callable] | None default `= None` A list of Python functions that can be called from `js_on_load` via the `server` object. For example, if you pass `server_functions=[my_func]`, you can call `server.my_func(arg1, arg2)` in your `js_on_load` code. Each function becomes an async method that sends the call to the Python backend and returns the result. props: Any Additional keyword arguments to pass into the HTML and CSS templates for rendering.
Initialization
https://gradio.app/docs/gradio/html
Gradio - Html Docs
Shortcuts gradio.HTML Interface String Shortcut `"html"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/html
Gradio - Html Docs
super_html
Demos
https://gradio.app/docs/gradio/html
Gradio - Html Docs
Description Event listeners allow you to respond to user interactions with the UI components you've defined in a Gradio Blocks app. When a user interacts with an element, such as changing a slider value or uploading an image, a function is called. Supported Event Listeners The HTML component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners HTML.change(fn, ···) Triggered when the value of the HTML changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. HTML.input(fn, ···) This listener is triggered when the user changes the value of the HTML. HTML.click(fn, ···) Triggered when the HTML is clicked. HTML.double_click(fn, ···) Triggered when the HTML is double clicked. HTML.submit(fn, ···) This listener is triggered when the user presses the Enter key while the HTML is focused. HTML.stop(fn, ···) This listener is triggered when the user reaches the end of the media playing in the HTML. HTML.edit(fn, ···) This listener is triggered when the user edits the HTML (e.g. image) using the built-in editor. HTML.clear(fn, ···) This listener is triggered when the user clears the HTML using the clear button for the component. HTML.play(fn, ···) This listener is triggered when the user plays the media in the HTML. HTML.pause(fn, ···) This listener is triggered when the media in the HTML stops for any reason. HTML.end(fn, ···) This listener is triggered when the user reaches the end of the media playing in the HTML. HTML.start_recording(fn, ···) This listener is triggered when the user starts recordi
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
, ···) This listener is triggered when the user reaches the end of the media playing in the HTML. HTML.start_recording(fn, ···) This listener is triggered when the user starts recording with the HTML. HTML.pause_recording(fn, ···) This listener is triggered when the user pauses recording with the HTML. HTML.stop_recording(fn, ···) This listener is triggered when the user stops recording with the HTML. HTML.focus(fn, ···) This listener is triggered when the HTML is focused. HTML.blur(fn, ···) This listener is triggered when the HTML is unfocused/blurred. HTML.upload(fn, ···) This listener is triggered when the user uploads a file into the HTML. HTML.release(fn, ···) This listener is triggered when the user releases the mouse on this HTML. HTML.select(fn, ···) Event listener for when the user selects or deselects the HTML. Uses event data gradio.SelectData to carry `value` referring to the label of the HTML, and `selected` to refer to state of the HTML. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. HTML.stream(fn, ···) This listener is triggered when the user streams the HTML. HTML.like(fn, ···) This listener is triggered when the user likes/dislikes from within the HTML. This event has EventData of type gradio.LikeData that carries information, accessible through LikeData.index and LikeData.value. See EventData documentation on how to use this event data. HTML.example_select(fn, ···) This listener is triggered when the user clicks on an example from within the HTML. This event has SelectData of type gradio.SelectData that carries information, accessible through SelectData.index and SelectData.value. See SelectData documentation on how to use this event data. HTML.option_select(fn, ···) This listener is triggered when the user clicks on an option from
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
ta.index and SelectData.value. See SelectData documentation on how to use this event data. HTML.option_select(fn, ···) This listener is triggered when the user clicks on an option from within the HTML. This event has SelectData of type gradio.SelectData that carries information, accessible through SelectData.index and SelectData.value. See SelectData documentation on how to use this event data. HTML.load(fn, ···) This listener is triggered when the HTML initially loads in the browser. HTML.key_up(fn, ···) This listener is triggered when the user presses a key while the HTML is focused. HTML.apply(fn, ···) This listener is triggered when the user applies changes to the HTML through an integrated UI action. HTML.delete(fn, ···) This listener is triggered when the user deletes and item from the HTML. Uses event data gradio.DeletedFileData to carry `value` referring to the file that was deleted as an instance of FileData. See EventData documentation on how to use this event data HTML.tick(fn, ···) This listener is triggered at regular intervals defined by the HTML. HTML.undo(fn, ···) This listener is triggered when the user clicks the undo button in the chatbot message. HTML.retry(fn, ···) This listener is triggered when the user clicks the retry button in the chatbot message. HTML.expand(fn, ···) This listener is triggered when the HTML is expanded. HTML.collapse(fn, ···) This listener is triggered when the HTML is collapsed. HTML.download(fn, ···) This listener is triggered when the user downloads a file from the HTML. Uses event data gradio.DownloadData to carry information about the downloaded file as a FileData object. See EventData documentation on how to use this event data HTML.copy(fn, ···) This listener is triggered when the user copies content from the HTML. Uses event d
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
e as a FileData object. See EventData documentation on how to use this event data HTML.copy(fn, ···) This listener is triggered when the user copies content from the HTML. Uses event data gradio.CopyData to carry information about the copied content. See EventData documentation on how to use this event data Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If Tru
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
he function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of 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
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
g 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, 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 conc
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called. The validator receives the same inputs as the main function and should return a `gr.validate()` for each input value. [Custom HTML Components](../../guides/custom-HTML-components/)[Custom CSS And JS](../../guides/custom-CSS-and-JS/)
Event Listeners
https://gradio.app/docs/gradio/html
Gradio - Html Docs
Used to display arbitrary JSON output prettily. As this component does not accept user input, it is rarely used as an input component.
Description
https://gradio.app/docs/gradio/json
Gradio - Json Docs
**Using JSON as an input component.** How JSON will pass its value to your function: Type: `dict | list | None` Passes the JSON value as a `dict` or `list` depending on the value. Example Code import gradio as gr def predict( value: dict | list | None ): process value from the JSON component return "prediction" interface = gr.Interface(predict, gr.JSON(), gr.Textbox()) interface.launch() **Using JSON as an output component** How JSON expects you to return a value: Type: `dict | list | str | None` Expects a valid JSON `str` \-- or a `list` or `dict` that can be serialized to a JSON string. The `list` or `dict` value can contain numpy arrays. Example Code import gradio as gr def predict(text) -> dict | list | str | None process value to return to the JSON component return value interface = gr.Interface(predict, gr.Textbox(), gr.JSON()) interface.launch()
Behavior
https://gradio.app/docs/gradio/json
Gradio - Json Docs
Parameters ▼ value: str | dict | list | Callable | None default `= None` Default value as a valid JSON `str` -- or a `list` or `dict` that can be serialized to a JSON string. 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. 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_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.
Initialization
https://gradio.app/docs/gradio/json
Gradio - Json Docs
rap 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. open: bool default `= False` If True, all JSON nodes will be expanded when rendered. By default, node levels deeper than 3 are collapsed. show_indices: bool default `= False` Whether to show numerical indices when displaying the elements of a list within the JSON object.
Initialization
https://gradio.app/docs/gradio/json
Gradio - Json Docs
levels deeper than 3 are collapsed. show_indices: bool default `= False` Whether to show numerical indices when displaying the elements of a list within the JSON object. height: int | str | None default `= None` Height of the JSON component in pixels if a number is passed, or in CSS units if a string is passed. Overflow will be scrollable. If None, the height will be automatically adjusted to fit the content. max_height: int | str | None default `= 500` min_height: int | str | None default `= None` buttons: list[Literal['copy'] | Button] | None default `= None` A list of buttons to show for the component. Valid options are "copy" or a gr.Button() instance. The "copy" button allows users to copy the JSON to the clipboard. Custom gr.Button() instances will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button. By default, the copy button is shown.
Initialization
https://gradio.app/docs/gradio/json
Gradio - Json Docs
Shortcuts gradio.JSON Interface String Shortcut `"json"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/json
Gradio - Json Docs
zip_to_jsonblocks_xray
Demos
https://gradio.app/docs/gradio/json
Gradio - Json 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 JSON component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners JSON.change(fn, ···) Triggered when the value of the JSON 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. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint.
Event Listeners
https://gradio.app/docs/gradio/json
Gradio - Json Docs
PI docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size:
Event Listeners
https://gradio.app/docs/gradio/json
Gradio - Json Docs
he function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can
Event Listeners
https://gradio.app/docs/gradio/json
Gradio - Json Docs
output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called. The validator receives the same inputs as the main function and should return a `gr.validate()` for each input value.
Event Listeners
https://gradio.app/docs/gradio/json
Gradio - Json Docs
lidate()` for each input value.
Event Listeners
https://gradio.app/docs/gradio/json
Gradio - Json Docs
Creates a video component that can be used to upload/record videos (as an input) or display videos (as an output). For the video to be playable in the browser it must have a compatible container and codec combination. Allowed combinations are .mp4 with h264 codec, .ogg with theora codec, and .webm with vp9 codec. If the component detects that the output video would not be playable in the browser it will attempt to convert it to a playable mp4 video. If the conversion fails, the original video is returned.
Description
https://gradio.app/docs/gradio/video
Gradio - Video Docs
**Using Video as an input component.** How Video will pass its value to your function: Type: `str | None` Passes the uploaded video as a `str` filepath or URL whose extension can be modified by `format`. Example Code import gradio as gr def predict( value: str | None ): process value from the Video component return "prediction" interface = gr.Interface(predict, gr.Video(), gr.Textbox()) interface.launch() **Using Video as an output component** How Video expects you to return a value: Type: `str | Path | None` Expects one of either: * a `str` or `pathlib.Path` filepath to a video which is displayed * a `Tuple[str | pathlib.Path, str | pathlib.Path | None]` where the first element is a filepath to a video and the second element is an optional filepath to a subtitle file. Example Code import gradio as gr def predict(text) -> str | Path | None process value to return to the Video component return value interface = gr.Interface(predict, gr.Textbox(), gr.Video()) interface.launch()
Behavior
https://gradio.app/docs/gradio/video
Gradio - Video Docs
Parameters ▼ value: str | Path | Callable | None default `= None` path or URL for the default value that Video component is going to take. Or can be callable, in which case the function will be called whenever the app loads to set the initial value of the component. format: str | None default `= None` the file extension with which to save video, such as 'avi' or 'mp4'. This parameter applies both when this component is used as an input to determine which file format to convert user-provided video to, and when this component is used as an output to determine the format of video returned to the user. If None, no file format conversion is done and the video is kept as is. Use 'mp4' to ensure browser playability. sources: list[Literal['upload', 'webcam']] | Literal['upload', 'webcam'] | None default `= None` list of sources permitted for video. "upload" creates a box where user can drop a video file, "webcam" allows user to record a video from their webcam. If None, defaults to both ["upload, "webcam"]. 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 video file, but will affect the displayed video. 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 video file, but will affect the displayed video. 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 reca
Initialization
https://gradio.app/docs/gradio/video
Gradio - Video Docs
nd used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to. every: Timer | float | None default `= None` continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if True, will display label. container: bool default `= True` if True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, will allow users to upload a video; if False, can only be used to display videos. 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 i
Initialization
https://gradio.app/docs/gradio/video
Gradio - Video Docs
e 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. webcam_options: WebcamOptions | None default `= None` A `gr.WebcamOptions` instance that allows developers to specify custom media constraints for the webcam stream. This parameter provides flexibility to control the video stream's properties, such as resolution and front or rear camera on mobile devices. See $demo/webcam_constraints include_audio: bool | None default `= None` whether the component should record/retain the audio track for a video. By default, audio is excluded for webcam videos and included for uploaded videos. autoplay: bool d
Initialization
https://gradio.app/docs/gradio/video
Gradio - Video Docs
lt `= None` whether the component should record/retain the audio track for a video. By default, audio is excluded for webcam videos and included for uploaded videos. autoplay: bool default `= False` whether to automatically play the video when the component is used as an output. Note: browsers will not autoplay video files if the user has not interacted with the page yet. buttons: list[Literal['download', 'share'] | Button] | None default `= None` A list of buttons to show in the top right corner of the component. Valid options are "download", "share", or a gr.Button() instance. The "download" button allows the user to save the video to their device. The "share" button allows the user to share the video via Hugging Face Spaces Discussions. Custom gr.Button() instances will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button. By default, no buttons are shown if the component is interactive and both buttons are shown if the component is not interactive. loop: bool default `= False` if True, the video will loop when it reaches the end and continue playing from the beginning. streaming: bool default `= False` when used set as an output, takes video chunks yielded from the backend and combines them into one streaming video output. Each chunk should be a video file with a .ts extension using an h.264 encoding. Mp4 files are also accepted but they will be converted to h.264 encoding. watermark: WatermarkOptions | None default `= None` A `gr.WatermarkOptions` instance that includes an image file and position to be used as a watermark on the video. The image is not scaled and is displayed on the provided position on the video. Valid formats for the image are: jpeg, png. subtitles: str | Path | list[dict[str, Any]] | None default `= None` A subtitle file (srt, vtt, or json) for the v
Initialization
https://gradio.app/docs/gradio/video
Gradio - Video Docs
position on the video. Valid formats for the image are: jpeg, png. subtitles: str | Path | list[dict[str, Any]] | None default `= None` A subtitle file (srt, vtt, or json) for the video, or a list of subtitle dictionaries in the format [{"text": str, "timestamp": [start, end]}] where timestamps are in seconds. JSON files should contain an array of subtitle objects. playback_position: float default `= 0` The starting playback position in seconds. This value is also updated as the video plays, reflecting the current playback position.
Initialization
https://gradio.app/docs/gradio/video
Gradio - Video Docs
Shortcuts gradio.Video Interface String Shortcut `"video"` Initialization Uses default values gradio.PlayableVideo Interface String Shortcut `"playablevideo"` Initialization Uses format="mp4"
Shortcuts
https://gradio.app/docs/gradio/video
Gradio - Video Docs
video_identity_2
Demos
https://gradio.app/docs/gradio/video
Gradio - Video 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 Video component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners Video.change(fn, ···) Triggered when the value of the Video 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. Video.clear(fn, ···) This listener is triggered when the user clears the Video using the clear button for the component. Video.start_recording(fn, ···) This listener is triggered when the user starts recording with the Video. Video.stop_recording(fn, ···) This listener is triggered when the user stops recording with the Video. Video.stop(fn, ···) This listener is triggered when the user reaches the end of the media playing in the Video. Video.play(fn, ···) This listener is triggered when the user plays the media in the Video. Video.pause(fn, ···) This listener is triggered when the media in the Video stops for any reason. Video.end(fn, ···) This listener is triggered when the user reaches the end of the media playing in the Video. Video.upload(fn, ···) This listener is triggered when the user uploads a file into the Video. Video.input(fn, ···) This listener is triggered when the user changes the value of the Video. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this
Event Listeners
https://gradio.app/docs/gradio/video
Gradio - Video Docs
d when the user changes the value of the Video. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given 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 runti
Event Listeners
https://gradio.app/docs/gradio/video
Gradio - Video Docs
s: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event,
Event Listeners
https://gradio.app/docs/gradio/video
Gradio - Video Docs
ict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not c
Event Listeners
https://gradio.app/docs/gradio/video
Gradio - Video Docs
undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called. The validator receives the same inputs as the main function and should return a `gr.validate()` for each input value.
Event Listeners
https://gradio.app/docs/gradio/video
Gradio - Video Docs
Helper Classes
https://gradio.app/docs/gradio/video
Gradio - Video 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/video
Gradio - Video Docs
Validates that the audio length is within the specified min and max length (in seconds). You can use this to construct a validator that will check if the user-provided audio is either too short or too long. import gradio as gr demo = gr.Interface( lambda x: x, inputs="video", outputs="video", validator=lambda video: gr.validators.is_video_correct_length(video, min_length=1, max_length=5) ) demo.launch() Initialization Parameters ▼ video: <class 'str'> The path to the video file. min_length: float | None Minimum length of video in seconds. If None, no minimum length check is performed. max_length: float | None Maximum length of video in seconds. If None, no maximum length check is performed. [Streaming Inputs](../../guides/streaming-inputs/)[Streaming Outputs](../../guides/streaming-outputs/)[Object Detection From Video](../../guides/object-detection-from-video/)
is_video_correct_length
https://gradio.app/docs/gradio/video
Gradio - Video 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 | pathlib.Path | list[str | pathlib.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. [File Access](../../guides/file-access)
Initialization
https://gradio.app/docs/gradio/set_static_paths
Gradio - Set_Static_Paths 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
**Using ImageEditor as an input component.** How ImageEditor will pass its value to your function: Type: `EditorValue | None` 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 * the value corresponding to 'layers' is a `list` of images. Depending on the `type` parameter, the images are of type: * `PIL.Image` * `np.array` * `str` filepath. Example Code import gradio as gr def predict( value: EditorValue | None ): process value from the ImageEditor component return "prediction" interface = gr.Interface(predict, gr.ImageEditor(), gr.Textbox()) interface.launch() **Using ImageEditor as an output component** How ImageEditor expects you to return a value: Type: `EditorValue | ImageType | None` 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 * the value corresponding to `layers` should be a list of images. Images can be of type: * `PIL.Image` * `np.array` * `str` filepath/URL Or, the value can be simply a single image (`ImageType`), in which case it will be used as the background. Example Code import gradio as gr def predict(text) -> EditorValue | ImageType | None process value to return to the ImageEditor component return value interface = gr.Interface(predict, gr.Textbox(), gr.ImageEditor()) interface.launch()
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 parameter. 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 parameter. 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, "we
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
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, "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. buttons: list[Literal['download', 'share', 'fullscreen']] | None default `= None` A list of buttons to show in the corner of the component. Valid options are "download" to download the image, "share" to share to Hugging Face Spaces Discussions, and "fullscreen" to view in fullscreen mode. By default, all buttons are shown.
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
nt. Valid options are "download" to download the image, "share" to share to Hugging Face Spaces Discussions, and "fullscreen" to view in fullscreen mode. By default, all buttons are shown. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, 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.
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
r: 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. 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. transforms: Iterable[Literal['crop', 'resize']] | None default `= ('crop', 'resize')` The transforms tools to make available to users. "crop" allows the user to crop the image. eraser: Eraser | None | Literal[False] default `= None` The options for the eraser tool in the image editor. Should be an instance of the `gr.Eraser` class, or None to use the default settings. Can also be False to hide the eraser tool. See `gr.Eraser` docs. brush: Brush | None | Literal[False] default `= None` The options for the brush tool in the image editor. Should be an instance of the `gr.Brush` class, or None to use the default settings. Can also be False to hide the brush tool, which will also hide 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
Initialization
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
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. 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
Shortcuts gradio.ImageEditor Interface String Shortcut `"imageeditor"` Initialization Uses default values gradio.Sketchpad Interface String Shortcut `"sketchpad"` Initialization Uses sources=(), brush=Brush(colors=["000000"], color_mode="fixed") gradio.Paint Interface String Shortcut `"paint"` Initialization Uses sources=() gradio.ImageMask Interface String Shortcut `"imagemask"` Initialization Uses brush=Brush(colors=["000000"], color_mode="fixed")
Shortcuts
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
image_editor
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. Listeners 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 <https://www.gradio.app/main/docs/gradio/eventdata> for more details. 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
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given 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
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
nt area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but function
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
ll 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. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private".
Event Listeners
https://gradio.app/docs/gradio/imageeditor
Gradio - Imageeditor Docs
en from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called. The validator receives the same inputs as the main function and should return a `gr.validate()` for each input value.
Event Listeners
https://gradio.app/docs/gradio/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
A Gradio request object that can be used to access the request headers, cookies, query parameters and other information about the request from within the prediction function. The class is a thin wrapper around the fastapi.Request class. Attributes of this class include: `headers`, `client`, `query_params`, `session_hash`, and `path_params`. If auth is enabled, the `username` attribute can be used to get the logged in user. In some environments, the dict-like attributes (e.g. `requests.headers`, `requests.query_params`) of this class are automatically converted to dictionaries, so we recommend converting them to dictionaries before accessing attributes for consistent behavior in different environments.
Description
https://gradio.app/docs/gradio/request
Gradio - Request Docs
import gradio as gr def echo(text, request: gr.Request): if request: print("Request headers dictionary:", request.headers) print("IP address:", request.client.host) print("Query parameters:", dict(request.query_params)) print("Session hash:", request.session_hash) return text io = gr.Interface(echo, "textbox", "textbox").launch()
Example Usage
https://gradio.app/docs/gradio/request
Gradio - Request Docs
Parameters ▼ request: fastapi.Request | None default `= None` A fastapi.Request username: str | None default `= None` The username of the logged in user (if auth is enabled) session_hash: str | None default `= None` The session hash of the current session. It is unique for each page load.
Initialization
https://gradio.app/docs/gradio/request
Gradio - Request Docs
request_ip_headers
Demos
https://gradio.app/docs/gradio/request
Gradio - Request Docs
Displays text that contains spans that are highlighted by category or numerical value.
Description
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
**Using HighlightedText as an input component.** How HighlightedText will pass its value to your function: Type: `list[tuple[str, str | float | None]] | None` Passes the value as a list of tuples: `list[tuple]`. Each `tuple` consists of: * a `str` substring of the text (so the entire text is included) * a `str | float | None` label, which is the category or confidence of that substring. Example Code import gradio as gr def predict( value: list[tuple[str, str | float | None]] | None ): process value from the HighlightedText component return "prediction" interface = gr.Interface(predict, gr.HighlightedText(), gr.Textbox()) interface.launch() **Using HighlightedText as an output component** How HighlightedText expects you to return a value: Type: `list[tuple[str, str | float | None]] | dict | None` Expects either of: * a list of (word, category) tuples * a dictionary of two keys: "text", and "entities". * "entities" itself is a list of dictionaries, each of which have the keys: "entity" (or "entity_group"), "start", and "end" Example Code import gradio as gr def predict(text) -> list[tuple[str, str | float | None]] | dict | None process value to return to the HighlightedText component return value interface = gr.Interface(predict, gr.Textbox(), gr.HighlightedText()) interface.launch()
Behavior
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
Parameters ▼ value: list[tuple[str, str | float | None]] | dict | Callable | None default `= None` Default value to show. If a function is provided, the function will be called each time the app loads to set the initial value of this component. color_map: dict[str, str] | None default `= None` A dictionary mapping labels to colors. The colors may be specified as hex codes or by their names. For example: {"person": "red", "location": "FFEE22"} show_legend: bool default `= False` whether to show span categories in a separate legend or inline. show_inline_category: bool default `= True` If False, will not display span category label. Only applies if show_legend=False and interactive=False. combine_adjacent: bool default `= False` If True, will merge the labels of adjacent tokens belonging to the same category. adjacent_separator: str default `= ""` Specifies the separator to be used between tokens if combine_adjacent is True. show_whitespaces: bool default `= True` If False, leading and trailing whitespace of each token will be stripped before display. 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 r
Initialization
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if True, will display label. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. 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 k
Initialization
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
e 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. interactive: bool | None default `= None` If True, the component will be editable, and allow user to select spans of text and label them. rtl: bool default `= False` If True, will display the text in right-to-left direction, and the labels in the legend will also be aligned to the right. buttons: list[Button] | None default `= None` A list of gr.Button() instances to show in the top right corner of the component. Custom buttons will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button.
Initialization
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
Shortcuts gradio.HighlightedText Interface String Shortcut `"highlightedtext"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
diff_texts
Demos
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
Description Event listeners allow you to respond to user interactions with the UI components you've defined in a Gradio Blocks app. When a user interacts with an element, such as changing a slider value or uploading an image, a function is called. Supported Event Listeners The HighlightedText component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners HighlightedText.change(fn, ···) Triggered when the value of the HighlightedText changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. HighlightedText.select(fn, ···) Event listener for when the user selects or deselects the HighlightedText. Uses event data gradio.SelectData to carry `value` referring to the label of the HighlightedText, and `selected` to refer to state of the HighlightedText. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.componen
Event Listeners
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
puts, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function
Event Listeners
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
l not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] |
Event Listeners
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
llowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default `= None` Optional validation function to run before the main function. If provided, this function will be execut
Event Listeners
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
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. [Named Entity Recognition](../../guides/named-entity-recognition/)
Event Listeners
https://gradio.app/docs/gradio/highlightedtext
Gradio - Highlightedtext Docs
Creates a set of checkboxes. Can be used as an input to pass a set of values to a function or as an output to display values, a subset of which are selected.
Description
https://gradio.app/docs/gradio/checkboxgroup
Gradio - Checkboxgroup Docs
**Using CheckboxGroup as an input component.** How CheckboxGroup will pass its value to your function: Type: `list[str | int | float] | list[int | None]` Passes the list of checked checkboxes as a `list[str | int | float]` or their indices as a `list[int]` into the function, depending on `type`. Example Code import gradio as gr def predict( value: list[str | int | float] | list[int | None] ): process value from the CheckboxGroup component return "prediction" interface = gr.Interface(predict, gr.CheckboxGroup(), gr.Textbox()) interface.launch() **Using CheckboxGroup as an output component** How CheckboxGroup expects you to return a value: Type: `list[str | int | float] | str | int | float | None` Expects a `list[str | int | float]` of values or a single `str | int | float` value, the checkboxes with these values are checked. Example Code import gradio as gr def predict(text) -> list[str | int | float] | str | int | float | None process value to return to the CheckboxGroup component return value interface = gr.Interface(predict, gr.Textbox(), gr.CheckboxGroup()) interface.launch()
Behavior
https://gradio.app/docs/gradio/checkboxgroup
Gradio - Checkboxgroup Docs
Parameters ▼ choices: list[str | int | float | tuple[str, str | int | float]] | None default `= None` A list of string or numeric options to select from. An option can also be a tuple of the form (name, value), where name is the displayed name of the checkbox button and value is the value to be passed to the function, or returned by the function. value: list[str | float | int] | str | float | int | Callable | None default `= None` Default selected list of options. If a single choice is selected, it can be passed in as a string or numeric type. If a function is provided, the function will be called each time the app loads to set the initial value of this component. type: Literal['value', 'index'] default `= "value"` Type of value to be returned by component. "value" returns the list of strings of the choices selected, "index" returns the list of indices of the choices selected. label: str | I18nData | None default `= None` the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to. info: str | I18nData | None default `= None` additional component description, appears below the label in smaller font. Supports markdown / HTML syntax. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
Initialization
https://gradio.app/docs/gradio/checkboxgroup
Gradio - Checkboxgroup Docs
nt] | 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_select_all: bool default `= False` If True, will display a select/deselect all checkbox next to the label. Only available when show_label is True. container: bool default `= True` If True, will place the component in a container - providing some extra padding around the border. scale: int | None default `= None` Relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer. min_width: int default `= 160` Minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` If True, choices in this checkbox group will be checkable; if False, checking 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,
Initialization
https://gradio.app/docs/gradio/checkboxgroup
Gradio - Checkboxgroup Docs
None` An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. render: bool default `= True` If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= "value"` A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor. buttons: list[Button] | None default `= None` A list of gr.Button() instances to show in the top right corner of the component. Custom buttons will appear in the toolbar with their configured icon and/or label, and clicking them will trigger any .click() events registered on the button.
Initialization
https://gradio.app/docs/gradio/checkboxgroup
Gradio - Checkboxgroup Docs