Skip to main content
ChatInterface is Gradio’s high-level abstraction specifically designed for creating chatbot UIs. It provides a simple way to wrap chat functions and automatically handles message history, user interactions, and streaming responses.

What is ChatInterface?

ChatInterface is similar to Interface but specialized for conversational AI applications. It automatically provides:
  • A chat display with message history
  • An input textbox (or multimodal input)
  • Submit, retry, undo, and clear buttons
  • Example prompts
  • Streaming support for real-time responses

Basic usage

The simplest chatbot requires just a function that takes a message and history:
Your function receives:
  • message: The user’s current message (string)
  • history: List of previous messages in OpenAI format
And should return:
  • A string response, or
  • A Gradio component (like an image), or
  • A complete message dict

Message history format

The history parameter is a list of OpenAI-style message dictionaries:
You can use this history to maintain context across multiple turns:

Streaming responses

For real-time streaming, make your function a generator:
ChatInterface automatically detects generator functions and displays responses as they stream.

Multimodal chat

Enable file uploads with multimodal=True:
When multimodal=True, the input message becomes a dictionary:

Examples

Provide example prompts to help users get started:
For multimodal examples, include files:

Additional inputs

Add configuration parameters that appear in a collapsible section:
Additional input values are passed as extra arguments to your function after message and history.

Additional outputs

Display extra information alongside the chat:

Customization options

Title and description

Custom chatbot component

Provide your own configured Chatbot component:

Custom textbox

Customize the input textbox:

Button labels

Editable messages

Allow users to edit their previous messages:

Retry and undo

ChatInterface automatically provides retry and undo buttons:
  • Retry: Regenerates the last assistant response
  • Undo: Removes the last user message and assistant response
These are built-in and require no additional code.

Flagging and feedback

Enable users to flag messages or provide feedback:
Like/Dislike options appear as thumbs up/down icons next to messages.

Caching examples

Cache example responses for instant loading:

API configuration

Control API endpoint visibility:

Advanced: Returning components

Return Gradio components directly from your function:

Performance options

Complete example

Here’s a fully-featured chatbot:

See also