Skip to main content
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.

Constructor

Parameters

Callable
required
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 representing the chat history. The function should return/yield a str (for a simple message), a supported Gradio component, a dict (for a complete openai-style message response), or a list of such messages.
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.
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.
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.
str | Component | list[str | Component] | None
default:"None"
An instance or list of instances of gradio components to use as additional inputs to the chatbot. The values of these components will be passed into fn as arguments in order after the chat history.
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.
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.
bool
default:"False"
If True, users can edit past messages to regenerate responses.
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.
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.
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.
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.
bool | None
default:"None"
If True, caches examples in the server for fast runtime in examples.
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.
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.
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.
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.
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”].
str
default:"'.gradio/flagged'"
Path to the directory where flagged data is stored.
bool | None
default:"None"
Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True.
bool
default:"True"
If True, autofocuses to the textbox when the page loads.
bool
default:"True"
If True, will automatically scroll to the bottom of the chatbot when a new message appears.
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.
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 stop button text.
int | None | Literal['default']
default:"'default'"
If set, this is the maximum number of chatbot submissions that can be running simultaneously.
tuple[int, int] | None
default:"None"
A tuple corresponding [frequency, age] both expressed in number of seconds.
Literal['full', 'minimal', 'hidden']
default:"'minimal'"
How to show the progress animation while event is running.
bool
default:"True"
If True, the chat interface will expand to the height of window.
bool
default:"False"
Whether to horizontally expand to fill container fully.
str | None
default:"None"
Defines how the chat endpoint appears in the API docs.
str | None | Literal[False]
default:"None"
Description of the API endpoint.
Literal['public', 'private', 'undocumented']
default:"'public'"
Controls the visibility of the chat endpoint.
bool
default:"False"
If True, will save the chat history to the browser’s local storage and display previous conversations in a side panel.
Callable | None
default:"None"
A function that takes in the inputs and can optionally return a gr.validate() object for each input.

Example