text
stringlengths
0
2k
heading1
stringlengths
4
79
source_page_url
stringclasses
183 values
source_page_title
stringclasses
183 values
**Using Dataframe as an input component.** How Dataframe will pass its value to your function: Type: `pd.DataFrame | np.ndarray | pl.DataFrame | list[list]` Passes the uploaded spreadsheet data as a `pandas.DataFrame`, `numpy.array`, `polars.DataFrame`, or native 2D Python `list[list]` depending on `type`. Example Code import gradio as gr def predict( value: pd.DataFrame | np.ndarray | pl.DataFrame | list[list] ): process value from the Dataframe component return "prediction" interface = gr.Interface(predict, gr.Dataframe(), gr.Textbox()) interface.launch() **Using Dataframe as an output component** How Dataframe expects you to return a value: Type: `pd.DataFrame | Styler | np.ndarray | pl.DataFrame | list | list[list] | dict | str | None` Expects data in any of these formats: * `pandas.DataFrame` * `pandas.Styler` * `numpy.array` * `polars.DataFrame` * `list[list]` * `list` * `dict` with keys 'data' (and optionally 'headers') * `str` path to a csv, which is rendered as the spreadsheet. Example Code import gradio as gr def predict(text) -> pd.DataFrame | Styler | np.ndarray | pl.DataFrame | list | list[list] | dict | str | None process value to return to the Dataframe component return value interface = gr.Interface(predict, gr.Textbox(), gr.Dataframe()) interface.launch()
Behavior
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
Parameters ▼ value: pd.DataFrame | Styler | np.ndarray | pl.DataFrame | list | list[list] | dict | str | Callable | None default `= None` Default value to display in the DataFrame. Supports pandas, numpy, polars, and list of lists. If a Styler is provided, it will be used to set the displayed value in the DataFrame (e.g. to set precision of numbers) if the `interactive` is False. If a Callable function is provided, the function will be called whenever the app loads to set the initial value of the component. headers: list[str] | None default `= None` List of str header names. These are used to set the column headers of the dataframe if the value does not have headers. If None, no headers are shown. row_count: int | None default `= None` The number of rows to initially display in the dataframe. If None, the number of rows is determined automatically based on the `value`. row_limits: tuple[int | None, int | None] | None default `= None` A tuple of two integers specifying the minimum and maximum number of rows that can be created in the dataframe via the UI. If the first element is None, there is no minimum number of rows. If the second element is None, there is no maximum number of rows. Only applies if `interactive` is True. col_count: None default `= None` This parameter is deprecated. Please use `column_count` instead. column_count: int | None default `= None` The number of columns to initially display in the dataframe. If None, the number of columns is determined automatically based on the `value`. column_limits: tuple[int | None, int | None] | None default `= None` A tuple of two integers specifying the minimum and maximum number of columns that can be created in the dataframe via the UI. If the first element is None, there is no minimum number of columns. If the second element is None, there is no maximum number of columns. Only applies if
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
t can be created in the dataframe via the UI. If the first element is None, there is no minimum number of columns. If the second element is None, there is no maximum number of columns. Only applies if `interactive` is True. datatype: Literal['str', 'number', 'bool', 'date', 'markdown', 'html', 'image', 'auto'] | list[Literal['str', 'number', 'bool', 'date', 'markdown', 'html']] default `= "str"` Datatype of values in sheet. Can be provided per column as a list of strings, or for the entire sheet as a single string. Valid datatypes are "str", "number", "bool", "date", and "markdown". Boolean columns will display as checkboxes. If the datatype "auto" is used, the column datatypes are automatically selected based on the value input if possible. type: Literal['pandas', 'numpy', 'array', 'polars'] default `= "pandas"` Type of value to be returned by component. "pandas" for pandas dataframe, "numpy" for numpy array, "polars" for polars dataframe, or "array" for a Python list of lists. latex_delimiters: list[dict[str, str | bool]] | None default `= None` A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html). Only applies to columns whose datatype is "markdown". 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
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
e 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. show_label: bool | None default `= None` if True, will display label. 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. max_height: int | str default `= 500` The maximum height of the dataframe, specified in pixels if a number is passed, or in CSS units if a string is passed. If more rows are created than can fit in the height, a scrollbar will appear. 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 edit the dataframe; if False, can only be used to display data. 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, co
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
used to display data. If not provided, this is inferred based on whether the component is used as an input or output. visible: bool | Literal['hidden'] default `= True` If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. render: bool default `= True` If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= "value"` A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor. wrap: bool default `= False` If True, the text in table cells will wrap when appropriate. If False and the `column_width` parameter is not set, the column widths will expand based on the cell contents and the table may need to be horizontally scrolled. If `column_width` is set, then any overflow text will be hidden. line_breaks: bool default `= True`
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
nd based on the cell contents and the table may need to be horizontally scrolled. If `column_width` is set, then any overflow text will be hidden. line_breaks: bool default `= True` If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies for columns of type "markdown." column_widths: list[str | int] | None default `= None` An optional list representing the width of each column. The elements of the list should be in the format "100px" (ints are also accepted and converted to pixel values) or "10%". The percentage width is calculated based on the viewport width of the table. If not provided, the column widths will be automatically determined based on the content of the cells. buttons: list[Literal['fullscreen', 'copy']] | None default `= None` A list of buttons to show in the top right corner of the component. Valid options are "fullscreen" and "copy". The "fullscreen" button allows the user to view the table in fullscreen mode. The "copy" button allows the user to copy the table data to the clipboard. By default, all buttons are shown. show_row_numbers: bool default `= False` If True, will display row numbers in a separate column. max_chars: int | None default `= None` Maximum number of characters to display in each cell before truncating (single-clicking a cell value will still reveal the full content). If None, no truncation is applied. show_search: Literal['none', 'search', 'filter'] default `= "none"` Show a search input in the toolbar. If "search", a search input is shown. If "filter", a search input and filter buttons are shown. If "none", no search input is shown. pinned_columns: int | None default `= None` If provided, will pin the specified number of columns from the left. static_columns: list[int] | None default `= None` List o
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
pinned_columns: int | None default `= None` If provided, will pin the specified number of columns from the left. static_columns: list[int] | None default `= None` List of column indices (int) that should not be editable. Only applies when interactive=True. When specified, col_count is automatically set to "fixed" and columns cannot be inserted or deleted.
Initialization
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
Shortcuts gradio.Dataframe Interface String Shortcut `"dataframe"` Initialization Uses default values gradio.Numpy Interface String Shortcut `"numpy"` Initialization Uses type="numpy" gradio.Matrix Interface String Shortcut `"matrix"` Initialization Uses type="array" gradio.List Interface String Shortcut `"list"` Initialization Uses type="array", col_count=1
Shortcuts
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
filter_recordsmatrix_transposetax_calculatorsort_records
Demos
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe 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 Dataframe component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners Dataframe.change(fn, ···) Triggered when the value of the Dataframe 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. Dataframe.input(fn, ···) This listener is triggered when the user changes the value of the Dataframe. Dataframe.select(fn, ···) Event listener for when the user selects or deselects the Dataframe. Uses event data gradio.SelectData to carry `value` referring to the label of the Dataframe, and `selected` to refer to state of the Dataframe. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. Dataframe.edit(fn, ···) This listener is triggered when the user edits the Dataframe (e.g. image) using the built-in editor. 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 fun
Event Listeners
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
nent. 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 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 enabl
Event Listeners
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited
Event Listeners
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
, 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. 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 ide
Event Listeners
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
`= 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. [Styling The Gradio Dataframe](../../guides/styling-the-gradio- dataframe/)[Filters Tables And Stats](../../guides/filters-tables-and-stats/)
Event Listeners
https://gradio.app/docs/gradio/dataframe
Gradio - Dataframe Docs
ChatInterface is Gradio's high-level abstraction for creating chatbot UIs, and allows you to create a web-based demo around a chatbot model in a few lines of code. Only one parameter is required: fn, which takes a function that governs the response of the chatbot based on the user input and chat history. Additional parameters can be used to control the appearance and behavior of the demo.
Description
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
**Basic Example** : A chatbot that echoes back the users’s message import gradio as gr def echo(message, history): return message demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot") demo.launch() **Custom Chatbot** : A `gr.ChatInterface` with a custom `gr.Chatbot` that includes a placeholder as well as upvote/downvote buttons. The upvote/downvote buttons are automatically added when a `.like()` event is attached to a `gr.Chatbot`. In order to attach event listeners to your custom chatbot, wrap the `gr.Chatbot` as well as the `gr.ChatInterface` inside of a `gr.Blocks` like this: import gradio as gr def yes(message, history): return "yes" def vote(data: gr.LikeData): if data.liked: print("You upvoted this response: " + data.value["value"]) else: print("You downvoted this response: " + data.value["value"]) with gr.Blocks() as demo: chatbot = gr.Chatbot(placeholder="<strong>Your Personal Yes-Man</strong><br>Ask Me Anything") chatbot.like(vote, None, None) gr.ChatInterface(fn=yes, chatbot=chatbot) demo.launch()
Example Usage
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
Parameters ▼ fn: Callable the function to wrap the chat interface around. The function should accept two parameters: a `str` representing the input message and `list` of openai-style dictionaries: {"role": "user" | "assistant", "content": `str` | {"path": `str`} | `gr.Component`} representing the chat history. The function should return/yield a `str` (for a simple message), a supported Gradio component (e.g. gr.Image to return an image), a `dict` (for a complete openai-style message response), or a `list` of such messages. multimodal: bool default `= False` if True, the chat interface will use a `gr.MultimodalTextbox` component for the input, which allows for the uploading of multimedia files. If False, the chat interface will use a gr.Textbox component for the input. If this is True, the first argument of `fn` should accept not a `str` message but a `dict` message with keys "text" and "files" chatbot: Chatbot | None default `= None` an instance of the gr.Chatbot component to use for the chat interface, if you would like to customize the chatbot properties. If not provided, a default gr.Chatbot component will be created. textbox: Textbox | MultimodalTextbox | None default `= None` an instance of the gr.Textbox or gr.MultimodalTextbox component to use for the chat interface, if you would like to customize the textbox properties. If not provided, a default gr.Textbox or gr.MultimodalTextbox component will be created. additional_inputs: str | Component | list[str | Component] | None default `= None` an instance or list of instances of gradio components (or their string shortcuts) to use as additional inputs to the chatbot. If the components are not already rendered in a surrounding Blocks, then the components will be displayed under the chatbot, in an accordion. The values of these components will be passed into `fn` as arguments in order after the chat history. add
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
cks, then the components will be displayed under the chatbot, in an accordion. The values of these components will be passed into `fn` as arguments in order after the chat history. additional_inputs_accordion: str | Accordion | None default `= None` if a string is provided, this is the label of the `gr.Accordion` to use to contain additional inputs. A `gr.Accordion` object can be provided as well to configure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This parameter is only used if `additional_inputs` is provided. additional_outputs: Component | list[Component] | None default `= None` an instance or list of instances of gradio components to use as additional outputs from the chat function. These must be components that are already defined in the same Blocks scope. If provided, the chat function should return additional values for these components. See $demo/chatinterface_artifacts. editable: bool default `= False` if True, users can edit past messages to regenerate responses. examples: list[str] | list[MultimodalValue] | list[list] | None default `= None` sample inputs for the function; if provided, appear within the chatbot and can be clicked to populate the chatbot input. Should be a list of strings representing text-only examples, or a list of dictionaries (with keys `text` and `files`) representing multimodal examples. If `additional_inputs` are provided, the examples must be a list of lists, where the first element of each inner list is the string or dictionary example message and the remaining elements are the example values for the additional inputs -- in this case, the examples will appear under the chatbot. example_labels: list[str] | None default `= None` labels for the examples, to be displayed instead of the examples themselves. If provided, should be a list of strings with th
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
atbot. example_labels: list[str] | None default `= None` labels for the examples, to be displayed instead of the examples themselves. If provided, should be a list of strings with the same length as the examples list. Only applies when examples are displayed within the chatbot (i.e. when `additional_inputs` is not provided). example_icons: list[str] | None default `= None` icons for the examples, to be displayed above the examples. If provided, should be a list of string URLs or local paths with the same length as the examples list. Only applies when examples are displayed within the chatbot (i.e. when `additional_inputs` is not provided). run_examples_on_click: bool default `= True` if True, clicking on an example will run the example through the chatbot fn and the response will be displayed in the chatbot. If False, clicking on an example will only populate the chatbot input with the example message. Has no effect if `cache_examples` is True cache_examples: bool | None default `= None` if True, caches examples in the server for fast runtime in examples. The default option in HuggingFace Spaces is True. The default option elsewhere is False. Note that examples are cached separately from Gradio's queue() so certain features, such as gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's UI for cached examples. cache_mode: Literal['eager', 'lazy'] | None default `= None` if "eager", all examples are cached at app launch. If "lazy", examples are cached for all users after the first use by any user of the app. If None, will use the GRADIO_CACHE_MODE environment variable if defined, or default to "eager". title: str | I18nData | None default `= None` a title for the interface; if provided, appears above chatbot in large font. Also used as the tab title when opened in a browser window. description: str | None default `= None
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
None` a title for the interface; if provided, appears above chatbot in large font. Also used as the tab title when opened in a browser window. description: str | None default `= None` a description for the interface; if provided, appears above the chatbot and beneath the title in regular font. Accepts Markdown and HTML content. flagging_mode: Literal['never', 'manual'] | None default `= None` one of "never", "manual". If "never", users will not see a button to flag an input and output. If "manual", users will see a button to flag. flagging_options: list[str] | tuple[str, ...] | None default `= ('Like', 'Dislike')` a list of strings representing the options that users can choose from when flagging a message. Defaults to ["Like", "Dislike"]. These two case-sensitive strings will render as "thumbs up" and "thumbs down" icon respectively next to each bot message, but any other strings appear under a separate flag icon. flagging_dir: str default `= ".gradio/flagged"` path to the the directory where flagged data is stored. If the directory does not exist, it will be created. analytics_enabled: bool | None default `= None` whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True. autofocus: bool default `= True` if True, autofocuses to the textbox when the page loads. autoscroll: bool default `= True` If True, will automatically scroll to the bottom of the chatbot when a new message appears, unless the user scrolls up. If False, will not scroll to the bottom of the chatbot automatically. submit_btn: str | bool | None default `= True` If True, will show a submit button with a submit icon within the textbox. If a string, will use that string as the submit button text in place of the icon. If False, will not show a submit button. stop_btn: str | b
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
tton with a submit icon within the textbox. If a string, will use that string as the submit button text in place of the icon. If False, will not show a submit button. stop_btn: str | bool | None default `= True` If True, will show a button with a stop icon during generator executions, to stop generating. If a string, will use that string as the submit button text in place of the stop icon. If False, will not show a stop button. concurrency_limit: int | None | Literal['default'] default `= "default"` if set, this is the maximum number of chatbot submissions that can be running simultaneously. Can be set to None to mean no limit (any number of chatbot submissions can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `.queue()`, which is 1 by default). delete_cache: tuple[int, int] | None default `= None` a tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur. show_progress: Literal['full', 'minimal', 'hidden'] default `= "minimal"` 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 fill_height: bool default `= True` if True, the chat interface will expand to the height of window. fill_width: bool default `= False` Whether to horizontally expand to fill container fully. If False, centers and constrains app to
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
hat interface will expand to the height of window. fill_width: bool default `= False` Whether to horizontally expand to fill container fully. If False, centers and constrains app to a maximum width. api_name: str | None default `= None` defines how the chat 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, the name of the function will be used. 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. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` Controls the visibility of the chat endpoint. Can be "public" (shown in API docs and callable), "private" (hidden from API docs and not callable), or "undocumented" (hidden from API docs but callable). save_history: bool default `= False` if True, will save the chat history to the browser's local storage and display previous conversations in a side panel. validator: Callable | None default `= None` a function that takes in the inputs and can optionally return a gr.validate() object for each input.
Initialization
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
chatinterface_random_responsechatinterface_streaming_echochatinterface_artifacts [Creating A Chatbot Fast](../../guides/creating-a-chatbot-fast/)[Chatinterface Examples](../../guides/chatinterface-examples/)[Agents And Tool Usage](../../guides/agents-and-tool-usage/)[Chatbot Specific Events](../../guides/chatbot-specific-events/)
Demos
https://gradio.app/docs/gradio/chatinterface
Gradio - Chatinterface Docs
Group is a layout element within Blocks which groups together children so that they do not have any padding or margin between them.
Description
https://gradio.app/docs/gradio/group
Gradio - Group Docs
with gr.Group(): gr.Textbox(label="First") gr.Textbox(label="Last")
Example Usage
https://gradio.app/docs/gradio/group
Gradio - Group Docs
Parameters ▼ visible: bool | Literal['hidden'] default `= True` If False, group will be hidden. elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles. render: bool default `= True` If False, this layout will not be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= None` A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
Initialization
https://gradio.app/docs/gradio/group
Gradio - Group Docs
Creates a textarea for users to enter string input or display string output and also allows for the uploading of multimedia files.
Description
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
**Using MultimodalTextbox as an input component.** How MultimodalTextbox will pass its value to your function: Type: `MultimodalValue | None` Passes text value and list of file(s) as a `dict` into the function. Example Code import gradio as gr def predict( value: MultimodalValue | None ): process value from the MultimodalTextbox component return "prediction" interface = gr.Interface(predict, gr.MultimodalTextbox(), gr.Textbox()) interface.launch() **Using MultimodalTextbox as an output component** How MultimodalTextbox expects you to return a value: Type: `MultimodalValue | str | None` Expects a `dict` with "text" and "files", both optional. The files array is a list of file paths or URLs. Example Code import gradio as gr def predict(text) -> MultimodalValue | str | None process value to return to the MultimodalTextbox component return value interface = gr.Interface(predict, gr.Textbox(), gr.MultimodalTextbox()) interface.launch()
Behavior
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
Parameters ▼ value: str | dict[str, str | list] | Callable | None default `= None` Default value to show in MultimodalTextbox. A string value, or a dictionary of the form {"text": "sample text", "files": [{path: "files/file.jpg", orig_name: "file.jpg", url: "http://image_url.jpg", size: 100}]}. If a function is provided, the function will be called each time the app loads to set the initial value of this component. sources: list[Literal['upload', 'microphone']] | Literal['upload', 'microphone'] | None default `= None` A list of sources permitted. "upload" creates a button where users can click to upload or drop files, "microphone" creates a microphone input. If None, defaults to ["upload"]. file_types: list[str] | None default `= None` List of file extensions or types of files to be uploaded (e.g. ['image', '.json', '.mp4']). "file" allows any file to be uploaded, "image" allows only image files to be uploaded, "audio" allows only audio files to be uploaded, "video" allows only video files to be uploaded, "text" allows only text files to be uploaded. file_count: Literal['single', 'multiple', 'directory'] default `= "single"` if single, allows user to upload one file. If "multiple", user uploads multiple files. If "directory", user uploads all files in selected directory. Return type will be list for each file in case of "multiple" or "directory". lines: int default `= 1` minimum number of line rows to provide in textarea. max_lines: int default `= 20` maximum number of line rows to provide in textarea. placeholder: str | None default `= None` placeholder hint to provide behind textarea. 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.
Initialization
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
e` the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to. info: str | I18nData | None default `= None` additional component description, appears below the label in smaller font. Supports markdown / HTML syntax. every: Timer | float | None default `= None` Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer. inputs: Component | list[Component] | set[Component] | None default `= None` Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change. show_label: bool | None default `= None` if 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 be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on
Initialization
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
cted first. interactive: bool | None default `= None` if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. visible: bool | Literal['hidden'] default `= True` If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. autofocus: bool default `= False` If True, will focus on the textbox when the page loads. Use this carefully, as it can cause usability issues for sighted and non-sighted users. autoscroll: bool default `= True` If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes. 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
Initialization
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
rved_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. text_align: Literal['left', 'right'] | None default `= None` How to align the text in the textbox, can be: "left", "right", or None (default). If None, the alignment is left if `rtl` is False, or right if `rtl` is True. Can only be changed if `type` is "text". rtl: bool default `= False` If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right. submit_btn: str | bool | None default `= True` If False, will not show a submit button. If a string, will use that string as the submit button text. stop_btn: str | bool | None default `= False` If True, will show a stop button (useful for streaming demos). If a string, will use that string as the stop button text. max_plain_text_length: int default `= 1000` Maximum length of plain text in the textbox. If the text exceeds this length, the text will be pasted as a file. Default is 1000. html_attributes: InputHTMLAttributes | None default `= None` An instance of gr.InputHTMLAttributes, which can be used to set HTML attributes for the input/textarea elements. Example: InputHTMLAttributes(autocorrect="off", spellcheck=False) to disable autocorrect and spellcheck.
Initialization
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
Shortcuts gradio.MultimodalTextbox Interface String Shortcut `"multimodaltextbox"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
chatbot_multimodal
Demos
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox 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 MultimodalTextbox component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners MultimodalTextbox.change(fn, ···) Triggered when the value of the MultimodalTextbox 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. MultimodalTextbox.input(fn, ···) This listener is triggered when the user changes the value of the MultimodalTextbox. MultimodalTextbox.select(fn, ···) Event listener for when the user selects or deselects the MultimodalTextbox. Uses event data gradio.SelectData to carry `value` referring to the label of the MultimodalTextbox, and `selected` to refer to state of the MultimodalTextbox. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. MultimodalTextbox.submit(fn, ···) This listener is triggered when the user presses the Enter key while the MultimodalTextbox is focused. MultimodalTextbox.focus(fn, ···) This listener is triggered when the MultimodalTextbox is focused. MultimodalTextbox.blur(fn, ···) This listener is triggered when the MultimodalTextbox is unfocused/blurred. MultimodalTextbox.stop(fn, ···) This listener is triggered when the user reaches the end of the media playing in the MultimodalTextbox. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when thi
Event Listeners
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
d of the media playing in the MultimodalTextbox. 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 runt
Event Listeners
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
ss: 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/multimodaltextbox
Gradio - Multimodaltextbox Docs
dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. 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
Event Listeners
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox 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. [Creating A Custom Chatbot With Blocks](../../guides/creating-a-custom- chatbot-with-blocks/)
Event Listeners
https://gradio.app/docs/gradio/multimodaltextbox
Gradio - Multimodaltextbox Docs
This class allows you to pass custom error messages to the user. You can do so by raising a gr.Error("custom message") anywhere in the code, and when that line is executed the custom message will appear in a modal on the demo. You can control for how long the error message is displayed with the `duration` parameter. If it’s `None`, the message will be displayed forever until the user closes it. If it’s a number, it will be shown for that many seconds. You can also hide the error modal from being shown in the UI by setting `visible=False`. Below is a demo of how different values of duration control the error, info, and warning messages. You can see the code [here](https://huggingface.co/spaces/freddyaboulton/gradio-error- duration/blob/244331cf53f6b5fa2fd406ece3bf55c6ccb9f5f2/app.pyL17). ![modal_control](https://github.com/gradio- app/gradio/assets/41651716/f0977bcd-eaec-4eca-a2fd-ede95fdb8fd2)
Description
https://gradio.app/docs/gradio/error
Gradio - Error Docs
import gradio as gr def divide(numerator, denominator): if denominator == 0: raise gr.Error("Cannot divide by zero!") gr.Interface(divide, ["number", "number"], "number").launch()
Example Usage
https://gradio.app/docs/gradio/error
Gradio - Error Docs
Parameters ▼ message: str default `= "Error raised."` The error message to be displayed to the user. Can be HTML, which will be rendered in the modal. duration: float | None default `= 10` The duration in seconds to display the error message. If None or 0, the error message will be displayed until the user closes it. visible: bool default `= True` Whether the error message should be displayed in the UI. title: str default `= "Error"` The title to be displayed to the user at the top of the error modal. print_exception: bool default `= True` Whether to print traceback of the error to the console when the error is raised.
Initialization
https://gradio.app/docs/gradio/error
Gradio - Error Docs
calculatorblocks_chained_events [Alerts](../../guides/alerts/)
Demos
https://gradio.app/docs/gradio/error
Gradio - Error Docs
Creates a color picker for user to select a color as string input. Can be used as an input to pass a color value to a function or as an output to display a color value.
Description
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
**Using ColorPicker as an input component.** How ColorPicker will pass its value to your function: Type: `str | None` Passes selected color value as a hex `str` into the function. Example Code import gradio as gr def predict( value: str | None ): process value from the ColorPicker component return "prediction" interface = gr.Interface(predict, gr.ColorPicker(), gr.Textbox()) interface.launch() **Using ColorPicker as an output component** How ColorPicker expects you to return a value: Type: `str | None` Expects a hex `str` returned from function and sets color picker value to it. Example Code import gradio as gr def predict(text) -> str | None process value to return to the ColorPicker component return value interface = gr.Interface(predict, gr.Textbox(), gr.ColorPicker()) interface.launch()
Behavior
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
Parameters ▼ value: str | Callable | None default `= None` default color hex code to provide in color picker. If a function is provided, the function will be called each time the app loads to set the initial value of this component. label: str | I18nData | None default `= None` the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to. 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 cer
Initialization
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
to top-level Components in Blocks where fill_height=True. min_width: int default `= 160` minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. interactive: bool | None default `= None` if True, will be rendered as an editable color picker; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. visible: bool | Literal['hidden'] default `= True` If False, component will be hidden. If "hidden", component will be visually hidden and not take up space in the layout but still exist in the DOM elem_id: str | None default `= None` An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. elem_classes: list[str] | str | None default `= None` An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. render: bool default `= True` If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. key: int | str | tuple[int | str, ...] | None default `= None` in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render. preserved_by_key: list[str] | str | None default `= "value"` A list of parameters from this component's constructor. Inside a gr.render() 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
Initialization
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
ender() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
Initialization
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
Shortcuts gradio.ColorPicker Interface String Shortcut `"colorpicker"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
color_picker
Demos
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker 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 ColorPicker component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners ColorPicker.change(fn, ···) Triggered when the value of the ColorPicker 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. ColorPicker.input(fn, ···) This listener is triggered when the user changes the value of the ColorPicker. ColorPicker.submit(fn, ···) This listener is triggered when the user presses the Enter key while the ColorPicker is focused. ColorPicker.focus(fn, ···) This listener is triggered when the ColorPicker is focused. ColorPicker.blur(fn, ···) This listener is triggered when the ColorPicker is unfocused/blurred. Event Parameters Parameters ▼ fn: Callable | None | Literal['decorator'] default `= "decorator"` the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext
Event Listeners
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
| BlockContext] | None default `= None` List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None default `= None` List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. api_name: str | None default `= None` defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. scroll_to_output: bool default `= False` If True, will scroll to output component on completion show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all show_progress_on: Component | list[Component] | None default `= None` Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components. queue: bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will u
Event Listeners
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
bool default `= True` If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` event
Event Listeners
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
e()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. concurrency_limit: int | None | Literal['default'] default `= "default"` If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default). concurrency_id: str | None default `= None` If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit. api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable by clients), "private" (hidden from API docs and not callable by clients), or "undocumented" (hidden from API docs but callable by clients and via gr.load). If fn is None, api_visibility will automatically be set to "private". time_limit: int | None default `= None` stream_every: float default `= 0.5` key: int | str | tuple[int | str, ...] | None default `= None` A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical. validator: Callable | None default
Event Listeners
https://gradio.app/docs/gradio/colorpicker
Gradio - Colorpicker Docs
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/colorpicker
Gradio - Colorpicker Docs
Creates an image component that can be used to upload images (as an input) or display images (as an output).
Description
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
**Using ImageSlider as an input component.** How ImageSlider will pass its value to your function: Type: `image_tuple | None` Passes the uploaded image as a tuple of `numpy.array`, `PIL.Image` or `str` filepath depending on `type`. Example Code import gradio as gr def predict( value: image_tuple | None ): process value from the ImageSlider component return "prediction" interface = gr.Interface(predict, gr.ImageSlider(), gr.Textbox()) interface.launch() **Using ImageSlider as an output component** How ImageSlider expects you to return a value: Type: `tuple[np.ndarray | PIL.Image.Image | str | Path | None, np.ndarray | PIL.Image.Image | str | Path | None] | None` Expects a tuple of `numpy.array`, `PIL.Image`, or `str` or `pathlib.Path` filepath to an image which is displayed. Example Code import gradio as gr def predict(text) -> tuple[np.ndarray | PIL.Image.Image | str | Path | None, np.ndarray | PIL.Image.Image | str | Path | None] | None process value to return to the ImageSlider component return value interface = gr.Interface(predict, gr.Textbox(), gr.ImageSlider()) interface.launch()
Behavior
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
Parameters ▼ value: image_tuple | Callable | None default `= None` A tuple of PIL Image, numpy array, path or URL for the default value that ImageSlider component is going to take, this pair of images should be of equal size. If a function is provided, the function will be called each time the app loads to set the initial value of this component. format: str default `= "webp"` File format (e.g. "png" or "gif"). Used 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. Applies both when this component is used as an input or output. This parameter has no effect on SVG files. 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 tuple of image file or numpy array, but will affect the displayed image. 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 tuple of image file or numpy array, but will affect the displayed image. image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None default `= "RGB"` The pixel format and color depth that the image should be loaded and preprocessed as. "RGB" will load the image as a color image, or "L" as black- and-white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other supported image modes and their meaning. This parameter has no effect on SVG or GIF files. If set to None, the image_mode will be inferred from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other cases). type: Literal['numpy', 'pil', 'filepath'] default `= "numpy"` The for
Initialization
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
image_mode will be inferred from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other cases). 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 str paths to temporary files containing the images. To support animated GIFs in input, the `type` should be set to "filepath" or "pil". To support SVGs, the `type` should be set to "filepath". label: str | 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', 'fullscreen'] | Button] | None default `= None` A list of buttons to show in the top right corner of the component. Valid options are "download", "fullscreen", or a gr.Button() instance. The "download" button allows the user to download the image. The "fullscreen" button allows the user to view the image in fullscreen mode. Custom gr.Button() instances will appear in the toolbar w
Initialization
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
ce. The "download" button allows the user to download the image. The "fullscreen" button allows the user to view the image in fullscreen mode. 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, all of the built-in 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 `= T
Initialization
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
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. slider_position: float default `= 50` The position of the slider as a percentage of the width of the image, between 0 and 100. max_height: int default `= 500` The maximum height of the image.
Initialization
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
Shortcuts gradio.ImageSlider Interface String Shortcut `"imageslider"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
imageslider
Demos
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider 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 ImageSlider component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners ImageSlider.clear(fn, ···) This listener is triggered when the user clears the ImageSlider using the clear button for the component. ImageSlider.change(fn, ···) Triggered when the value of the ImageSlider 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. ImageSlider.stream(fn, ···) This listener is triggered when the user streams the ImageSlider. ImageSlider.select(fn, ···) Event listener for when the user selects or deselects the ImageSlider. Uses event data gradio.SelectData to carry `value` referring to the label of the ImageSlider, and `selected` to refer to state of the ImageSlider. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. ImageSlider.upload(fn, ···) This listener is triggered when the user uploads a file into the ImageSlider. ImageSlider.input(fn, ···) This listener is triggered when the user changes the value of the ImageSlider. 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 e
Event Listeners
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
red. 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[Component] | None default `= None` Comp
Event Listeners
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
e 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 functions that are currently running will be allow
Event Listeners
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
nt 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". time_limit: int | None def
Event Listeners
https://gradio.app/docs/gradio/imageslider
Gradio - Imageslider Docs
ts), 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/imageslider
Gradio - Imageslider Docs
Creates a chatbot that displays user-submitted messages and responses. Supports a subset of Markdown including bold, italics, code, tables. Also supports audio/video/image files, which are displayed in the Chatbot, and other kinds of files which are displayed as links. This component is usually used as an output component.
Description
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
The Chatbot component accepts a list of messages, where each message is a dictionary with `role` and `content` keys. This format is compatible with the message format expected by most LLM APIs (OpenAI, Claude, HuggingChat, etc.), making it easy to pipe model outputs directly into the component. The `role` key should be either `'user'` or `'assistant'`, and the `content` key can be a string (rendered as markdown/HTML) or a Gradio component (useful for displaying files, images, plots, and other media). As an example: import gradio as gr history = [ {"role": "assistant", "content": "I am happy to provide you that report and plot."}, {"role": "assistant", "content": gr.Plot(value=make_plot_from_file('quaterly_sales.txt'))} ] with gr.Blocks() as demo: gr.Chatbot(history) demo.launch() For convenience, you can use the `ChatMessage` dataclass so that your text editor can give you autocomplete hints and typechecks. import gradio as gr history = [ gr.ChatMessage(role="assistant", content="How can I help you?"), gr.ChatMessage(role="user", content="Can you make me a plot of quarterly sales?"), gr.ChatMessage(role="assistant", content="I am happy to provide you that report and plot.") ] with gr.Blocks() as demo: gr.Chatbot(history) demo.launch()
Behavior
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
Parameters ▼ value: list[MessageDict | Message] | Callable | None default `= None` Default list of messages to show in chatbot, where each message is of the format {"role": "user", "content": "Help me."}. Role can be one of "user", "assistant", or "system". Content should be either text, or media passed as a Gradio component, e.g. {"content": gr.Image("lion.jpg")}. 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
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
ide 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. autoscroll: bool default `= True` If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes. 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 hav
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
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. height: int | str | None default `= 400` The height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will scroll. resizable: bool default `= False` If True, the user of the Gradio app can resize the chatbot by dragging the bottom right corner. max_height: int | str | None default `= None` The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will scroll. If messages are shorter than the height, the component will shrink to fit the content. Will not have any effect if `height` is set and is smaller than `max_height`. min_height: int | str | None default `= None` The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will expand to fit the content. Will not have any effect if `height` is set and is larger than `min_height`. editable: Literal['user', 'all'] | None default `= None` Allows user to edit messages in the chatbot. If set to "user", allows editing of user messages. If set to "all", allows editing of assistant messages as well. latex_delimiters: list[dict[str, str | bool]] | None default `= None` A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
pen delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html). rtl: bool default `= False` If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right. buttons: list[Literal['share', 'copy', 'copy_all'] | Button] | None default `= None` A list of buttons to show in the top right corner of the component. Valid options are "share", "copy", "copy_all", or a gr.Button() instance. The "share" button allows the user to share outputs to Hugging Face Spaces Discussions. The "copy" button makes a copy button appear next to each individual chatbot message. The "copy_all" button appears at the component level and allows the user to copy all chatbot messages. 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, "share" and "copy_all" buttons are shown. watermark: str | None default `= None` If provided, this text will be appended to the end of messages copied from the chatbot, after a blank line. Useful for indicating that the message is generated by an AI model. avatar_images: tuple[str | Path | None, str | Path | None] | None default `= None` Tuple of two avatar image paths or URLs for user and bot (in that order). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL. sanitize_html: bool default `= True` If False, w
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
rder). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL. sanitize_html: bool default `= True` If False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities. render_markdown: bool default `= True` If False, will disable Markdown rendering for chatbot messages. feedback_options: list[str] | tuple[str, ...] | None default `= ('Like', 'Dislike')` A list of strings representing the feedback options that will be displayed to the user. The exact case-sensitive strings "Like" and "Dislike" will render as thumb icons, but any other choices will appear under a separate flag icon. feedback_value: list[str | None] | None default `= None` A list of strings representing the feedback state for entire chat. Only works when type="messages". Each entry in the list corresponds to that assistant message, in order, and the value is the feedback given (e.g. "Like", "Dislike", or any custom feedback option) or None if no feedback was given for that message. line_breaks: bool default `= True` If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies if `render_markdown` is True. layout: Literal['panel', 'bubble'] | None default `= None` If "panel", will display the chatbot in a llm style layout. If "bubble", will display the chatbot with message bubbles, with the user and bot messages on alterating sides. Will default to "bubble". placeholder: str | None default `= None` a placeholder message to display in the chatbot when it is empty. Centered vertically and horizontally in the Chatbot. Supports Markdown and HTML. If None, no placeholder is displayed. examples: list[ExampleMessage] | None default `= None` A list of ex
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
ered vertically and horizontally in the Chatbot. Supports Markdown and HTML. If None, no placeholder is displayed. examples: list[ExampleMessage] | None default `= None` A list of example messages to display in the chatbot before any user/assistant messages are shown. Each example should be a dictionary with an optional "text" key representing the message that should be populated in the Chatbot when clicked, an optional "files" key, whose value should be a list of files to populate in the Chatbot, an optional "icon" key, whose value should be a filepath or URL to an image to display in the example box, and an optional "display_text" key, whose value should be the text to display in the example box. If "display_text" is not provided, the value of "text" will be displayed. allow_file_downloads: <class 'inspect._empty'> default `= True` If True, will show a download button for chatbot messages that contain media. Defaults to True. group_consecutive_messages: bool default `= True` If True, will display consecutive messages from the same role in the same bubble. If False, will display each message in a separate bubble. Defaults to True. allow_tags: list[str] | bool default `= True` If a list of tags is provided, these tags will be preserved in the output chatbot messages, even if `sanitize_html` is `True`. For example, if this list is ["thinking"], the tags `<thinking>` and `</thinking>` will not be removed. If True, all custom tags (non-standard HTML tags) will be preserved. If False, no tags will be preserved. Default value is 'True'. reasoning_tags: list[tuple[str, str]] | None default `= None` If provided, a list of tuples of (open_tag, close_tag) strings. Any text between these tags will be extracted and displayed in a separate collapsible message with metadata={"title": "Reasoning"}. For example, [("<thinking>", "</thinking>")] will extract content between <thinking> and </thi
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
s will be extracted and displayed in a separate collapsible message with metadata={"title": "Reasoning"}. For example, [("<thinking>", "</thinking>")] will extract content between <thinking> and </thinking> tags. Each thinking block will be displayed as a separate collapsible message before the main response. If None (default), no automatic extraction is performed. like_user_message: bool default `= False` If True, will show like/dislike buttons for user messages as well. Defaults to False.
Initialization
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
Shortcuts gradio.Chatbot Interface String Shortcut `"chatbot"` Initialization Uses default values
Shortcuts
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
**Displaying Thoughts/Tool Usage** You can provide additional metadata regarding any tools used to generate the response. This is useful for displaying the thought process of LLM agents. For example, def generate_response(history): history.append( ChatMessage(role="assistant", content="The weather API says it is 20 degrees Celcius in New York.", metadata={"title": "🛠️ Used tool Weather API"}) ) return history Would be displayed as following: ![Gradio chatbot tool display](https://github.com/user- attachments/assets/c1514bc9-bc29-4af1-8c3f-cd4a7c2b217f) You can also specify metadata with a plain python dictionary, def generate_response(history): history.append( dict(role="assistant", content="The weather API says it is 20 degrees Celcius in New York.", metadata={"title": "🛠️ Used tool Weather API"}) ) return history **Using Gradio Components Inside`gr.Chatbot`** The `Chatbot` component supports using many of the core Gradio components (such as `gr.Image`, `gr.Plot`, `gr.Audio`, and `gr.HTML`) inside of the chatbot. Simply include one of these components as the `content` of a message. Here’s an example: import gradio as gr def load(): return [ {"role": "user", "content": "Can you show me some media?"}, {"role": "assistant", "content": "Here's an audio clip:"}, {"role": "assistant", "content": gr.Audio("https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/audio/audio_sample.wav")}, {"role": "assistant", "content": "And here's a video:"}, {"role": "assistant", "content": gr.Video("https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/videos/world.mp4")} ] with gr.Blocks() as demo: chatbot = gr.Chatbot() button = gr.Button("Load
Examples
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
deo("https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/videos/world.mp4")} ] with gr.Blocks() as demo: chatbot = gr.Chatbot() button = gr.Button("Load audio and video") button.click(load, None, chatbot) demo.launch()
Examples
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
chatbot_simplechatbot_streamingchatbot_with_toolschatbot_core_components
Demos
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot 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 Chatbot component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below. Listeners Chatbot.change(fn, ···) Triggered when the value of the Chatbot 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. Chatbot.select(fn, ···) Event listener for when the user selects or deselects the Chatbot. Uses event data gradio.SelectData to carry `value` referring to the label of the Chatbot, and `selected` to refer to state of the Chatbot. See <https://www.gradio.app/main/docs/gradio/eventdata> for more details. Chatbot.like(fn, ···) This listener is triggered when the user likes/dislikes from within the Chatbot. 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. Chatbot.retry(fn, ···) This listener is triggered when the user clicks the retry button in the chatbot message. Chatbot.undo(fn, ···) This listener is triggered when the user clicks the undo button in the chatbot message. Chatbot.example_select(fn, ···) This listener is triggered when the user clicks on an example from within the Chatbot. 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.
Event Listeners
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
s 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. Chatbot.option_select(fn, ···) This listener is triggered when the user clicks on an option from within the Chatbot. 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. Chatbot.clear(fn, ···) This listener is triggered when the user clears the Chatbot using the clear button for the component. Chatbot.copy(fn, ···) This listener is triggered when the user copies content from the Chatbot. Uses event data gradio.CopyData to carry information about the copied content. See EventData documentation on how to use this event data Chatbot.edit(fn, ···) This listener is triggered when the user edits the Chatbot (e.g. image) using the built-in editor. 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_
Event Listeners
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
ckContext] | 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 should process a batch of inputs, meaning that it should accept a list of input values for each parameter.
Event Listeners
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
f the gradio app. batch: bool default `= False` If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) preprocess: bool default `= True` If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component). postprocess: bool default `= True` If False, will not run postprocessing of component data before returning 'fn' output to the browser. cancels: dict[str, Any] | list[dict[str, Any]] | None default `= None` A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish. trigger_mode: Literal['once', 'multiple', 'always_last'] | None default `= None` If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete. js: str | Literal[True] | None default `= None` Optional frontend js method to run before running 'fn'. Input arguments for js metho
Event Listeners
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
d 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 executed first with queue=False, and only if it completes successfully will the main function be called. The valid
Event Listeners
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
lidation 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/chatbot
Gradio - Chatbot Docs
Helper Classes
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
gradio.ChatMessage(···) Description A dataclass that represents a message in the Chatbot component (with type="messages"). The only required field is `content`. The value of `gr.Chatbot` is a list of these dataclasses. Parameters ▼ content: MessageContent | list[MessageContent] The content of the message. Can be a string, a file dict, a gradio component, or a list of these types to group these messages together. role: Literal['user', 'assistant', 'system'] default `= "assistant"` The role of the message, which determines the alignment of the message in the chatbot. Can be "user", "assistant", or "system". Defaults to "assistant". metadata: MetadataDict default `= _HAS_DEFAULT_FACTORY_CLASS()` The metadata of the message, which is used to display intermediate thoughts / tool usage. Should be a dictionary with the following keys: "title" (required to display the thought), and optionally: "id" and "parent_id" (to nest thoughts), "duration" (to display the duration of the thought), "status" (to display the status of the thought). options: list[OptionDict] default `= _HAS_DEFAULT_FACTORY_CLASS()` The options of the message. A list of Option objects, which are dictionaries with the following keys: "label" (the text to display in the option), and optionally "value" (the value to return when the option is selected if different from the label).
ChatMessage
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
A typed dictionary to represent metadata for a message in the Chatbot component. An instance of this dictionary is used for the `metadata` field in a ChatMessage when the chat message should be displayed as a thought. Keys ▼ title: str The title of the 'thought' message. Only required field. id: int | str The ID of the message. Only used for nested thoughts. Nested thoughts can be nested by setting the parent_id to the id of the parent thought. parent_id: int | str The ID of the parent message. Only used for nested thoughts. log: str A string message to display next to the thought title in a subdued font. duration: float The duration of the message in seconds. Appears next to the thought title in a subdued font inside a parentheses. status: Literal['pending', 'done'] if set to `'pending'`, a spinner appears next to the thought title and the accordion is initialized open. If `status` is `'done'`, the thought accordion is initialized closed. If `status` is not provided, the thought accordion is initialized open and no spinner is displayed.
MetadataDict
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
A typed dictionary to represent an option in a ChatMessage. A list of these dictionaries is used for the `options` field in a ChatMessage. Keys ▼ value: str The value to return when the option is selected. label: str The text to display in the option, if different from the value. [Chatbot Specific Events](../../guides/chatbot-specific- events/)[Conversational Chatbot](../../guides/conversational- chatbot/)[Creating A Chatbot Fast](../../guides/creating-a-chatbot- fast/)[Creating A Custom Chatbot With Blocks](../../guides/creating-a-custom- chatbot-with-blocks/)[Agents And Tool Usage](../../guides/agents-and-tool- usage/)
OptionDict
https://gradio.app/docs/gradio/chatbot
Gradio - Chatbot Docs
Interface is Gradio's main high-level class, and allows you to create a web-based GUI / demo around a machine learning model (or any Python function) in a few lines of code. You must specify three parameters: (1) the function to create a GUI for (2) the desired input components and (3) the desired output components. Additional parameters can be used to control the appearance and behavior of the demo.
Description
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
import gradio as gr def image_classifier(inp): return {'cat': 0.3, 'dog': 0.7} demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label") demo.launch()
Example Usage
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
Parameters ▼ fn: Callable the function to wrap an interface around. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: str | Component | list[str | Component] | None a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of input components should match the number of parameters in fn. If set to None, then only the output components will be displayed. outputs: str | Component | list[str | Component] | None a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of output components should match the number of values returned by fn. If set to None, then only the input components will be displayed. examples: list[Any] | list[list[Any]] | str | None default `= None` sample inputs for the function; if provided, appear below the UI components and can be clicked to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided, but it should be within the directory with the python file running the gradio app. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs. cache_examples: bool | None default `= None` If True, caches examples in the server for fast runtime in examples. If "lazy", then examples are cached (for all users of the app) after their first use (by any user of the app). If None, will use
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
If True, caches examples in the server for fast runtime in examples. If "lazy", then examples are cached (for all users of the app) after their first use (by any user of the app). If None, will use the GRADIO_CACHE_EXAMPLES environment variable, which should be either "true" or "false". In HuggingFace Spaces, this parameter defaults to True (as long as `fn` and `outputs` are also provided). Note that examples are cached separately from Gradio's queue() so certain features, such as gr.Progress(), gr.Info(), gr.Warning(), etc. will not be displayed in Gradio's UI for cached examples. cache_mode: Literal['eager', 'lazy'] | None default `= None` if "lazy", examples are cached after their first use. If "eager", all examples are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment variable if defined, or default to "eager". In HuggingFace Spaces, this parameter defaults to "eager" except for ZeroGPU Spaces, in which case it defaults to "lazy". examples_per_page: int default `= 10` if examples are provided, how many to display per page. example_labels: list[str] | None default `= None` a list of labels for each example. If provided, the length of this list should be the same as the number of examples, and these labels will be used in the UI instead of rendering the example values. preload_example: int | Literal[False] default `= 0` If an integer is provided (and examples are being cached eagerly and none of the input components have a developer-provided `value`), the example at that index in the examples list will be preloaded when the Gradio app is first loaded. If False, no example will be preloaded. live: bool default `= False` whether the interface should automatically rerun if any of the inputs change. title: str | I18nData | None default `= None` a title for the interface; if provided, appears above the input and output components in larg
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
tically rerun if any of the inputs change. title: str | I18nData | None default `= None` a title for the interface; if provided, appears above the input and output components in large font. Also used as the tab title when opened in a browser window. description: str | None default `= None` a description for the interface; if provided, appears above the input and output components and beneath the title in regular font. Accepts Markdown and HTML content. article: str | None default `= None` an expanded article explaining the interface; if provided, appears below the input and output components in regular font. Accepts Markdown and HTML content. If it is an HTTP(S) link to a downloadable remote file, the content of this file is displayed. flagging_mode: Literal['never'] | Literal['auto'] | Literal['manual'] | None default `= None` one of "never", "auto", or "manual". If "never" or "auto", users will not see a button to flag an input and output. If "manual", users will see a button to flag. If "auto", every input the user submits will be automatically flagged, along with the generated output. If "manual", both the input and outputs are flagged when the user clicks flag button. This parameter can be set with environmental variable GRADIO_FLAGGING_MODE; otherwise defaults to "manual". flagging_options: list[str] | list[tuple[str, str]] | None default `= None` if provided, allows user to select from the list of options when flagging. Only applies if flagging_mode is "manual". Can either be a list of tuples of the form (label, value), where label is the string that will be displayed on the button and value is the string that will be stored in the flagging CSV; or it can be a list of strings ["X", "Y"], in which case the values will be the list of strings and the labels will ["Flag as X", "Flag as Y"], etc. flagging_dir: str default `= ".gradio/flagged"` path to the di
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
s ["X", "Y"], in which case the values will be the list of strings and the labels will ["Flag as X", "Flag as Y"], etc. flagging_dir: str default `= ".gradio/flagged"` path to the directory where flagged data is stored. If the directory does not exist, it will be created. flagging_callback: FlaggingCallback | None default `= None` either None or an instance of a subclass of FlaggingCallback which will be called when a sample is flagged. If set to None, an instance of gradio.flagging.CSVLogger will be created and logs will be saved to a local CSV file in flagging_dir. Default to None. analytics_enabled: bool | None default `= None` whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True. batch: bool default `= False` if True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: int default `= 4` the maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) api_visibility: Literal['public', 'private', 'undocumented'] default `= "public"` Controls the visibility of the prediction endpoint. Can be "public" (shown in API docs and callable), "private" (hidden from API docs and not callable), or "undocumented" (hidden from API docs but callable). api_name: str | None default `= None` defines how the prediction 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, the name of the function will be used.
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
ion 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, the name of the function will be used. api_description: str | None | Literal[False] default `= None` Description of the API endpoint. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given description. If None, the function's docstring will be used as the API endpoint description. If False, then no description will be displayed in the API docs. allow_duplication: bool default `= False` if True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces. concurrency_limit: int | None | Literal['default'] default `= "default"` if set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `.queue()`, which itself is 1 by default). additional_inputs: str | Component | list[str | Component] | None default `= None` a single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. These components will be rendered in an accordion below the main input components. By default, no additional input components will be displayed. additional_inputs_accordion: str | Accordion | None default `= None` if a string is provided, this is the label of the `gr.Accordion` to use to contain additional inputs. A `gr.Accordion` object can be provided as well to configure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This parameter is only used if `additional_inputs` is provide
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
gure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label="Additional Inputs", open=False)`. This parameter is only used if `additional_inputs` is provided. submit_btn: str | Button default `= "Submit"` the button to use for submitting inputs. Defaults to a `gr.Button("Submit", variant="primary")`. This parameter does not apply if the Interface is output- only, in which case the submit button always displays "Generate". Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization). stop_btn: str | Button default `= "Stop"` the button to use for stopping the interface. Defaults to a `gr.Button("Stop", variant="stop", visible=False)`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization). clear_btn: str | Button | None default `= "Clear"` the button to use for clearing the inputs. Defaults to a `gr.Button("Clear", variant="secondary")`. Can be set to a string (which becomes the button label) or a `gr.Button` object (which allows for more customization). Can be set to None, which hides the button. delete_cache: tuple[int, int] | None default `= None` a tuple corresponding [frequency, age] both expressed in number of seconds. Every `frequency` seconds, the temporary files created by this Blocks instance will be deleted if more than `age` seconds have passed since the file was created. For example, setting this to (86400, 86400) will delete temporary files every day. The cache will be deleted entirely when the server restarts. If None, no cache deletion will occur. show_progress: Literal['full', 'minimal', 'hidden'] default `= "full"` how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" o
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs
`= "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 fill_width: bool default `= False` whether to horizontally expand to fill container fully. If False, centers and constrains app to a maximum width. time_limit: int | None default `= 30` The time limit for the stream to run. Default is 30 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True". stream_every: float default `= 0.5` The latency (in seconds) at which stream chunks are sent to the backend. Defaults to 0.5 seconds. Parameter only used for streaming images or audio if the interface is live and the input components are set to "streaming=True". deep_link: str | DeepLinkButton | bool | None default `= None` a string or `gr.DeepLinkButton` object that creates a unique URL you can use to share your app and all components **as they currently are** with others. Automatically enabled on Hugging Face Spaces unless explicitly set to False. validator: Callable | None default `= None` a function that takes in the inputs and can optionally return a gr.validate() object for each input.
Initialization
https://gradio.app/docs/gradio/interface
Gradio - Interface Docs