Introducing Gradio Clients
WatchIntroducing Gradio Clients
WatchNew to Gradio? Start here: Getting Started
See the Release History
gradio.ChatInterface(fn, Β·Β·Β·)
Basic Example: A chatbot that echoes back the usersβs message
import gradio as gr
def echo(message, history):
return message
demo = gr.ChatInterface(fn=echo, examples=["hello", "hola", "merhaba"], title="Echo Bot")
demo.launch()
Custom Chatbot: A gr.ChatInterface
with a custom gr.Chatbot
that includes a placeholder as well as upvote/downvote buttons. The upvote/downvote buttons are automatically added when a .like()
event is attached to a gr.Chatbot
. In order to attach event listeners to your custom chatbot, wrap the gr.Chatbot
as well as the gr.ChatInterface
inside of a gr.Blocks
like this:
import gradio as gr
def yes(message, history):
return "yes"
def vote(data: gr.LikeData):
if data.liked:
print("You upvoted this response: " + data.value["value"])
else:
print("You downvoted this response: " + data.value["value"])
with gr.Blocks() as demo:
chatbot = gr.Chatbot(placeholder="<strong>Your Personal Yes-Man</strong><br>Ask Me Anything")
chatbot.like(vote, None, None)
gr.ChatInterface(fn=yes, chatbot=chatbot)
demo.launch()
import gradio as gr
def echo(message, history):
return message["text"]
demo = gr.ChatInterface(
fn=echo,
examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
title="Echo Bot",
multimodal=True,
)
demo.launch()