Streaming Chatbot

Runnable examples for the frozen Gradio Lite 5.45.0 browser runtime.

Yield partial chat responses from a Python generator.

This coding playground streams an echo one character at a time. Click Run, send a message, and watch the generator update the response incrementally.

Code
import time
import gradio as gr

def slow_echo(message, history):
    for i in range(len(message)):
        time.sleep(0.05)
        yield "You typed: " + message[: i + 1]

demo = gr.ChatInterface(
    slow_echo,
    type="messages",
    flagging_mode="manual",
    flagging_options=["Like", "Spam", "Inappropriate", "Other"],
    save_history=True,
)

demo.launch()
import time import gradio as gr def slow_echo(message, history): for i in range(len(message)): time.sleep(0.05) yield "You typed: " + message[: i + 1] demo = gr.ChatInterface( slow_echo, type="messages", flagging_mode="manual", flagging_options=["Like", "Spam", "Inappropriate", "Other"], save_history=True, ) demo.launch()