Skip to main content
The Progress class provides a custom progress tracker that can be used in Gradio functions to display progress updates to users.

Constructor

gr.Progress(track_tqdm=False)

Parameters

track_tqdm
bool
default:"False"
If True, the Progress object will track any tqdm.tqdm iterations with the tqdm library in the function.

Methods

call

progress(progress, desc=None, total=None, unit="steps")
Updates progress tracker with progress and message text.
progress
float | tuple[int, int | None] | None
If float, should be between 0 and 1 representing completion. If tuple, first number represents steps completed, and second value represents total steps or None if unknown. If None, hides progress bar.
desc
str | None
default:"None"
Description to display.
total
int | float | None
default:"None"
Estimated total number of steps.
unit
str
default:"'steps'"
Unit of iterations.

tqdm

progress.tqdm(iterable, desc=None, total=None, unit="steps")
Attaches progress tracker to iterable, like tqdm.
iterable
Iterable | None
Iterable to attach progress tracker to.
desc
str | None
default:"None"
Description to display.
total
int | float | None
default:"None"
Estimated total number of steps.
unit
str
default:"'steps'"
Unit of iterations.

update

progress.update(n=1)
Increases latest iterable with specified number of steps.
n
int | float
default:"1"
Number of steps completed.

Examples

Basic Progress

import gradio as gr
import time

def my_function(x, progress=gr.Progress()):
    progress(0, desc="Starting...")
    time.sleep(1)
    for i in progress.tqdm(range(100)):
        time.sleep(0.1)
    return x

gr.Interface(my_function, gr.Textbox(), gr.Textbox()).launch()

Progress with Steps

import gradio as gr
import time

def process_data(data, progress=gr.Progress()):
    # Update with tuple (current, total)
    for i in range(10):
        progress((i, 10), desc=f"Processing step {i+1}/10")
        time.sleep(0.5)
    return "Done!"

with gr.Blocks() as demo:
    input_text = gr.Textbox()
    output_text = gr.Textbox()
    btn = gr.Button("Process")
    btn.click(process_data, input_text, output_text)

demo.launch()

Progress with tqdm

import gradio as gr
import time

def long_running_task(progress=gr.Progress(track_tqdm=True)):
    import tqdm
    results = []
    for i in tqdm.tqdm(range(100), desc="Processing"):
        time.sleep(0.1)
        results.append(i * 2)
    return sum(results)

with gr.Blocks() as demo:
    output = gr.Number()
    btn = gr.Button("Run")
    btn.click(long_running_task, None, output)

demo.launch()

Notes

  • To attach a Progress tracker to a function, add a parameter right after the input parameters that has a default value set to a gr.Progress() instance
  • The Progress tracker automatically appears in the Gradio UI when the function is running
  • You can use either the functional style (calling progress()) or the tqdm-like style (using progress.tqdm())
  • Progress updates are displayed in real-time to users

Build docs developers (and LLMs) love