How to prevent uploading the same set of files many times when changing an action or refreshing the page

Hi Team,

I’m new to Streamlit but I really love the tool. Currently, I want to be able to upload multiple files ( do some long running process, …, then save them to disk). However, I’m still struggling to make the behaviors work as I expected. Let’s say I want to upload 6 image files for processing and then saving those files to disk (either using random generated names or their original name). As I understand, every change or refresh the page, streamlit will run the code entirely from top to botom. So what will I do, if these situations below happen? My goal is only upload each file once if it is the same.

  • Situations #1: User refreshes page while uploading and processing files not done (i.e just done file #1, #2, it also means streamlit will stop uploading/ processing the other 4 files) , then the code will be run again for the second time with the same set of files( file #1 and #2 will be uploaded and processed twice). And so on if we keep refreshing.

  • Situation #2: Like the situation #1 but this time users clicking a button or changing something on page while the uploading and prcocessing files still running, then duplicated uploading on file can happen.

Do you have any suggestions on how to make the best user experience on this task and also guarantee every file in the set of files will be processed and saved to disk once?

Also, is it possible to streamlit to run a long running process/ function and also still let users doing other things on the page while waiting for that process?

If anyone can point me in the right direction it will be nice. And thank you for reading my long question!