How to use st.progress to show progress of function

First, let me apologize that I can’t share all my code due to proprietary and legal considerations. I will be as descriptive as I can.

So, I created an app for an object detection model I trained. I want to use the progress bar to show and track the progress as it processes images. I created the bar using the provided Streamlit example below:

import streamlit as st
import time

progress_text = "Operation in progress. Please wait."
my_bar = st.progress(0, text=progress_text)

for percent_complete in range(100):
    my_bar.progress(percent_complete + 1, text=progress_text)

What I can’t figure out is how to link it (sorry if my terminology is wrong) to the object detection function (again… terminology). I tried using a for loop and while loop but still get an error.

Once again, I apologize for the ambiguity.

What kind of link do you want? Is there a concept of progress in your object detection function?

You can pass a callback to update the progress bar to your model inference method. You can find an example in this repo:


1 Like

Is something like this what you’re looking for?

from dataclasses import dataclass
from time import sleep

import streamlit as st

class Program:
    progress: int = 0

    def increment(self):
        self.progress += 1

my_bar = st.progress(0, text="Operation in progress. Please wait...")

p = Program()

while p.progress < 100:
    my_bar.progress(p.progress, text=f"Progress: {p.progress}%")