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:message: The user’s current message (string)history: List of previous messages in OpenAI format
- A string response, or
- A Gradio component (like an image), or
- A complete message dict
Message history format
Thehistory parameter is a list of OpenAI-style message dictionaries:
Streaming responses
For real-time streaming, make your function a generator:Multimodal chat
Enable file uploads withmultimodal=True:
multimodal=True, the input message becomes a dictionary:
Examples
Provide example prompts to help users get started: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
Flagging and feedback
Enable users to flag messages or provide feedback: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
- Interface - General-purpose interface builder
- Blocks - For more complex layouts
- Chatbot Component - The underlying chat display component
- Events - Event system reference