Skip to main content
Gradio interfaces can automatically refresh or continuously stream data, making them perfect for real-time applications.

Live interfaces

Make your interface automatically recalculate whenever user input changes by setting live=True:
import gradio as gr

def calculator(num1, operation, num2):
    if operation == "add":
        return num1 + num2
    elif operation == "subtract":
        return num1 - num2
    elif operation == "multiply":
        return num1 * num2
    elif operation == "divide":
        return num1 / num2

demo = gr.Interface(
    calculator,
    inputs=[
        "number",
        gr.Radio(["add", "subtract", "multiply", "divide"]),
        "number"
    ],
    outputs="number",
    live=True,
)

demo.launch()
Notice there’s no submit button - the interface resubmits automatically on change.

How live mode works

When live=True:
  1. The interface listens for changes on all input components
  2. When any input changes, the function automatically runs
  3. Outputs update immediately without clicking a button
  4. The submit button is hidden
This is ideal for:
  • Real-time calculators and converters
  • Interactive data visualizations
  • Live image/audio filters
  • Instant feedback applications

Streaming components

Some components support a “streaming” mode that continuously sends data to the backend:
  • Audio component in microphone mode
  • Image component in webcam mode
Streaming means data is sent continuously and the Interface function keeps running.

Streaming vs live mode

There’s an important difference between regular and streaming components in live mode:
# Submits when user STOPS recording
gr.Interface(
    fn=transcribe_audio,
    inputs=gr.Audio(sources=["microphone"]),
    outputs="text",
    live=True
)
With streaming=True, the function runs continuously during recording, not just when recording stops.

Streaming webcam input

Here’s an example of streaming images from the webcam:
import gradio as gr
import numpy as np

def flip(im):
    return np.flipud(im)

demo = gr.Interface(
    flip,
    inputs=gr.Image(sources=["webcam"], streaming=True),
    outputs="image",
    live=True,
)

demo.launch()
This continuously:
  1. Captures frames from the webcam
  2. Sends them to the flip function
  3. Displays the flipped output in real-time

Streaming output

Streaming can also be used in output components. A gr.Audio(streaming=True) output can take a stream of audio data yielded piece-wise by a generator function:
import gradio as gr
import numpy as np

def generate_audio_stream():
    # Generator function that yields audio chunks
    for i in range(10):
        # Generate audio chunk
        audio_chunk = np.random.randn(8000)  # 1 second at 8kHz
        yield (8000, audio_chunk)

demo = gr.Interface(
    fn=generate_audio_stream,
    inputs=None,
    outputs=gr.Audio(streaming=True),
)

demo.launch()
The output component combines all yielded chunks into a single audio file.

Stream configuration

You can configure streaming behavior with these Interface parameters:
Maximum time (in seconds) for streaming to run:
gr.Interface(
    fn=stream_function,
    inputs=gr.Image(sources=["webcam"], streaming=True),
    outputs="image",
    live=True,
    time_limit=30  # Stop streaming after 30 seconds
)
Default is 30 seconds.
Latency (in seconds) between stream chunks sent to backend:
gr.Interface(
    fn=stream_function,
    inputs=gr.Image(sources=["webcam"], streaming=True),
    outputs="image",
    live=True,
    stream_every=0.5  # Send chunks every 0.5 seconds
)
Default is 0.5 seconds.
These parameters only apply when:
  • The interface is in live mode (live=True)
  • Input components have streaming=True

Use cases

Real-time speech recognition

Stream audio from microphone and transcribe in real-time

Live video filters

Apply filters to webcam feed with immediate preview

Interactive calculators

Show results as users type or adjust sliders

Audio synthesis

Generate and stream audio output progressively

Performance considerations

Streaming and live interfaces can be resource-intensive:
  • Functions run frequently, consuming more compute
  • Network bandwidth increases with continuous data transfer
  • Consider rate limiting for production deployments
  • Use stream_every to control update frequency

When not to use live mode

Avoid live mode when:
  • Your function is computationally expensive
  • You want users to review inputs before submitting
  • Processing takes significant time
  • You need to batch requests for efficiency
For these cases, use standard mode with a submit button.

Advanced streaming examples

For detailed examples of streaming in action, see:

Next steps

Interface class

Learn more about the Interface class

Interface types

Explore the 4 different types of interfaces