How to use st.progress to show progress of function

Is something like this what you’re looking for?

from dataclasses import dataclass
from time import sleep

import streamlit as st


@dataclass
class Program:
    progress: int = 0

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


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

p = Program()

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