Sub topic 8
Titles, example prompts, and themes
This chapter assumes you can already build a gr.ChatInterface with a respond(message, history) function and launch it locally. It covers the options that change how the app looks and what a first-time visitor sees. None of them change how your function is called.
Title and description
gr.ChatInterface takes a title and a description. The title appears above the chat window and the description appears below it. The description accepts Markdown, so you can add links or short usage notes.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Echo Bot",
description="A tiny demo. Type anything and the bot repeats it.",
)
if __name__ == "__main__":
demo.launch()Example prompts
Examples are clickable suggestions shown under the empty chat. Clicking one fills the textbox and sends it, so a visitor sees a working conversation without typing anything. Pass a list of strings to examples.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Echo Bot",
examples=["Hello!", "What can you do?", "Tell me a joke"],
cache_examples=False,
)
if __name__ == "__main__":
demo.launch()cache_examples=False is set on purpose. When caching is on, Gradio runs your function for every example at startup and stores the results. For an LLM backend that means API calls (and cost) before anyone has used the app. Leave caching off unless your function is fast, free, and deterministic.
If your app has additional_inputs, each example must supply a value for every extra input. Use a list per example, with the message first.
examples=[
["Explain recursion", "You are a patient tutor.", 0.3],
["Write a haiku", "You are a poet.", 0.9],
]Themes
A theme controls colors, fonts, and spacing. Pass one to theme. Gradio ships several built-in themes.
| Theme | Look |
|---|---|
| `gr.themes.Default()` | Orange accents, the standard look |
| `gr.themes.Soft()` | Rounded corners, softer colors |
| `gr.themes.Monochrome()` | Black and white |
| `gr.themes.Ocean()` | Blue and green tones |
You can adjust a theme with constructor arguments such as primary_hue and font.
import gradio as gr
def respond(message, history):
return f"You said: {message}"
theme = gr.themes.Soft(primary_hue="indigo", neutral_hue="slate")
demo = gr.ChatInterface(
fn=respond,
type="messages",
title="Echo Bot",
theme=theme,
)
if __name__ == "__main__":
demo.launch()How the pieces fit
Common errors
- Examples with extra inputs: a plain string list fails or leaves inputs empty when
additional_inputsis set. Use nested lists. - Unexpected API calls at launch: caching is turned on for examples. Set
cache_examples=False. - Theme not applied: the theme must be passed to the interface, not assigned to a variable and forgotten.
- Markdown not rendering: keep descriptions short and valid Markdown. Long HTML-heavy text is better placed in a
gr.Blockslayout.
Exercise
Your chat app calls a paid LLM API and has a system prompt textbox as an additional input. How do you add example prompts without spending money at startup, and what shape must each example have?
Show answer
Pass examples with cache_examples=False so Gradio does not run the function for each example at launch. Because there is an additional input, each example must be a list that starts with the message and then gives a value for the system prompt, for example ["Explain recursion", "You are a patient tutor."].