Sub topic 8
Titles, example prompts, and themes
This chapter covers the cosmetic and onboarding options of gr.ChatInterface: the title and description, clickable example prompts, and themes. It assumes you have a working gr.ChatInterface with a respond(message, history) function and understand the messages-style history from earlier chapters. It also assumes you can run a Python script and open http://127.0.0.1:7860 in a browser. The examples use Gradio 5.x. Theme and CSS arguments have moved between constructor and launch() in some major versions, so check the docs for your installed version if a argument is rejected.
Why presentation options matter
A chat box with no context leaves a first-time visitor guessing what to type. Three options help with that:
- A title and description say what the app is and what it can't do.
- Example prompts are clickable suggestions that show how to use the app.
- A theme sets colors, fonts, and spacing, so the app matches your product or team.
All three are keyword arguments on the gr.ChatInterface constructor. They change nothing about how your function is called.
Title and description
title is shown as the page heading. description is shown under it and accepts Markdown, so you can add bold text, links, and short lists.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Recipe Helper",
description=(
"Ask for **recipe ideas** from ingredients you already have. "
"This demo only echoes your message; it does not call a model yet."
),
)
if __name__ == "__main__":
demo.launch()Keep the description short. Two sentences are enough: what the app does and one limit, such as "answers may be wrong" or "conversations are not saved". Long text pushes the chat area down the page.
Example prompts
examples takes a list. Each entry becomes a clickable item under the input box. Clicking one fills the textbox with that text and, by default, sends it.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Recipe Helper",
examples=[
"What can I cook with eggs, spinach, and rice?",
"Give me a 15-minute vegetarian dinner.",
"Suggest a substitute for buttermilk.",
],
)
if __name__ == "__main__":
demo.launch()Good examples are short, realistic, and varied. Cover the main tasks your app does, and avoid ten near-duplicates. Three to six is a practical range.
Examples with additional inputs
If you added additional_inputs (such as a system prompt and a temperature slider), each example must supply a value for every input. Each example becomes a list whose first item is the message, followed by one value per additional input in the same order.
import gradio as gr
def respond(message, history, system_prompt, temperature):
return f"[{system_prompt} | T={temperature}] You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
additional_inputs=[
gr.Textbox("You are a helpful assistant.", label="System prompt"),
gr.Slider(0, 1, value=0.7, label="Temperature"),
],
examples=[
["Explain recursion.", "You are a patient teacher.", 0.3],
["Write a limerick about Python.", "You are a playful poet.", 0.9],
],
)
if __name__ == "__main__":
demo.launch()If the number of values in an example doesn't match the number of inputs, Gradio raises an error when the app starts. That makes the mistake easy to catch, but read the message closely, because it can look unrelated to examples.
Cached examples
cache_examples=True runs your function on every example when the app starts and stores the output. Clicking an example then shows the stored reply without calling the function again.
This is useful for a slow or expensive backend, because visitors see instant, predictable answers. It also has costs:
- Startup makes one backend call per example, which costs time and, with a paid API, money.
- A cached reply is fixed. It will not reflect later changes to the system prompt or model.
- Streaming and history are not replayed in the way a live conversation is.
For a first version, leave caching off (this is the default unless your environment enables it) and add it only when startup cost is acceptable.
Examples for multimodal apps
If you set multimodal=True so users can attach files, text-only strings are not enough for examples that include files. Each example is then a dictionary with a "text" key and, optionally, a "files" list of paths. Plain strings still work for text-only examples. The multimodal chapter covers this in detail.
Themes
A theme is an object that sets the colors, fonts, sizes, and spacing of every component. Pass one with the theme argument.
Gradio ships several built-in themes:
| Theme | Character |
|---|---|
| `gr.themes.Default()` | The standard orange-and-gray look |
| `gr.themes.Soft()` | Rounded corners, softer colors |
| `gr.themes.Glass()` | Translucent, blue-tinted look |
| `gr.themes.Monochrome()` | Black and white, serif-like feel |
| `gr.themes.Base()` | A minimal starting point for your own theme |
Each constructor accepts the same main arguments:
primary_hue,secondary_hue,neutral_hue: a color family such as"indigo"or"slate".fontandfont_mono: a list of fonts, tried in order.radius_size,spacing_size,text_size: size presets such asgr.themes.sizes.radius_lg.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
theme = gr.themes.Soft(
primary_hue="indigo",
neutral_hue="slate",
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "sans-serif"],
)
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Recipe Helper",
theme=theme,
)
if __name__ == "__main__":
demo.launch()gr.themes.GoogleFont loads the font from Google's servers in the visitor's browser. The fallbacks in the list ("ui-sans-serif", "sans-serif") are used if the download fails. If your deployment must work offline or avoid third-party requests, use only system fonts.
Fine-tuning with `.set()`
Every theme has many named variables, such as button colors and backgrounds. The .set() method overrides individual ones. A value starting with * refers to another theme variable, so your changes stay consistent with the hue you chose.
import gradio as gr
theme = gr.themes.Soft(primary_hue="indigo").set(
button_primary_background_fill="*primary_600",
button_primary_background_fill_hover="*primary_700",
)To browse the available variables and preview changes live, run gr.themes.builder() from a Python session. It opens a theme editor in the browser and can export the result as code.
Custom CSS
When a theme can't do what you need, css accepts a string of CSS. This example narrows the page and centers it:
import gradio as gr
def respond(message, history):
return f"You said: {message}"
css = """
.gradio-container { max-width: 800px !important; margin: auto; }
"""
demo = gr.ChatInterface(fn=respond, type="messages", css=css)
if __name__ == "__main__":
demo.launch()Class names inside Gradio's generated HTML can change between releases. Prefer theme variables when one exists, and use CSS for layout tweaks only.
Customizing the chat area itself
The message area and input box are separate components. You can replace them by passing your own gr.Chatbot and gr.Textbox to chatbot and textbox.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
chatbot=gr.Chatbot(
type="messages",
height=450,
placeholder="Ask me anything about cooking.",
),
textbox=gr.Textbox(placeholder="Type a question and press Enter", container=False, scale=7),
fill_height=False,
)
if __name__ == "__main__":
demo.launch()The placeholder on the chatbot is shown while the conversation is empty. It supports Markdown and is a good place for a short welcome message. Note that type="messages" is repeated on the gr.Chatbot. The chatbot and the interface must agree on the history format, or messages will not render correctly.
Common mistakes
- Example arity mismatch. With
additional_inputs, every example needs a value for each input, in order. - Surprise API bills.
cache_examples=Truewith a paid model calls the API once per example at every startup. - Mismatched history types. A custom
gr.Chatbotwithouttype="messages"while the interface uses it, or the reverse. - Font loading. A Google font fails silently on a restricted network, so always list fallbacks.
- Overlong description. The text sits above the chat. Link to documentation instead of pasting it.
Exercise
You add additional_inputs=[gr.Textbox(label="System prompt"), gr.Slider(0, 1, value=0.5, label="Temperature")] to a ChatInterface and set examples=["Hello", "Tell me a joke"]. The app fails to start with an error about the examples. What is wrong, and what is the corrected examples value if you want both prompts to use the system prompt "Be brief." and a temperature of 0.2?
Show answer
Each example must supply one value per additional input, in order, after the message. Plain strings provide only the message, so the two inputs have no values. The corrected value is examples=[["Hello", "Be brief.", 0.2], ["Tell me a joke", "Be brief.", 0.2]].
Exercise
Name two reasons you might leave cache_examples off for an app that calls a paid LLM API, and one reason you might turn it on.
Show answer
Off: every startup makes one paid API call per example, and cached replies don't change when you edit the system prompt or model. On: visitors get instant, consistent answers to the examples, which helps when the backend is slow or when you want a predictable demo.