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

gr.ChatInterface(
    fn,
    multimodal=False,
    chatbot=None,
    textbox=None,
    additional_inputs=None,
    additional_inputs_accordion=None,
    additional_outputs=None,
    editable=False,
    examples=None,
    example_labels=None,
    example_icons=None,
    run_examples_on_click=True,
    cache_examples=None,
    cache_mode=None,
    title=None,
    description=None,
    flagging_mode=None,
    flagging_options=("Like", "Dislike"),
    flagging_dir=".gradio/flagged",
    analytics_enabled=None,
    autofocus=True,
    autoscroll=True,
    submit_btn=True,
    stop_btn=True,
    concurrency_limit="default",
    delete_cache=None,
    show_progress="minimal",
    fill_height=True,
    fill_width=False,
    api_name=None,
    api_description=None,
    api_visibility="public",
    save_history=False,
    validator=None
)

Parameters

fn
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.
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.
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.
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.
additional_inputs
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.
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.
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.
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.
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.
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.
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.
cache_examples
bool | None
default:"None"
If True, caches examples in the server for fast runtime in 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.
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"
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”].
flagging_dir
str
default:"'.gradio/flagged'"
Path to the directory where flagged data is stored.
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.
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.
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 stop button text.
concurrency_limit
int | None | Literal['default']
default:"'default'"
If set, this is the maximum number of chatbot submissions that can be running simultaneously.
delete_cache
tuple[int, int] | None
default:"None"
A tuple corresponding [frequency, age] both expressed in number of seconds.
show_progress
Literal['full', 'minimal', 'hidden']
default:"'minimal'"
How to show the progress animation while event is running.
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.
api_name
str | None
default:"None"
Defines how the chat endpoint appears in the API docs.
api_description
str | None | Literal[False]
default:"None"
Description of the API endpoint.
api_visibility
Literal['public', 'private', 'undocumented']
default:"'public'"
Controls the visibility of the chat endpoint.
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.

Example

import gradio as gr

def echo(message, history):
    return message

demo = gr.ChatInterface(
    fn=echo,
    examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
    title="Echo Bot"
)
demo.launch()

Build docs developers (and LLMs) love