Clear Cache for file upload

I am trying to figure out how to clear cache when I upload a file to streamlit app. Even though I upload a different file , the app continues to use the previously uploaded file
Thanks for your feedback

Hey @dkamalakar,

Welcome to the Streamlit community! Can you add some of your code, or a minimal demo in of what you’re having trouble with?

In the mean time, are you uploading a different/edited file with the same name/path? If you are and you are using the @st.cache decorator when you run your script, it will not update. You will need to remove this to load an edited/new file with the same name.

However, this will mean that every time your app needs to re-run, the user will have to wait for the file to be reloaded.

Happy Streamlit-ing!
Marisa

Hi @Marisa_Smith,
I’m trying to clear cache (by using caching.clear_cache()) each time I click browse files button. However, I can’t manage to do so.

Clearing the cache every time the number of uploaded files changes will also work for me.

Do you know if it is possible?

Best,
Michal

Same thing happening with me, once i upload one file then after re run it is using the previous uploaded file from cache. i need to remove the file at the end of each run.

Same problem here with my voice activity detection (VAD) demo:
https://share.streamlit.io/pyannote/pyannote-audio-demo/main/app.py

Uploading a first audio file, you get the VAD for that file.
Uploading a second audio file, you still get the VAD for the first file.

This works fine if I first click on the closing “x” before uploading the second file.

Hey all!

Sorry for my slow reply, it has been busy over the holiday season! Could each of you link your github repo here? also, let me know where/what file your calling the @st.cache?

Once I can see how each of you are using the file_uploader, I will be able to start mocking up a possible minimum working example that will (hopefully) solve your problems!

@ me when you post your repo and I will work on a solution for you asap!
Cheers,
Marisa

@Marisa_Smith I posted a link to the Githup repo above.
For now, I will just ask my users not to forget to remove the file before uploading a new one. I am not using any caching in the current version.

1 Like

@hbredin Great thanks!

I will take a look at this, and get back to you soon!

Marisa

Hey @hbredin!
(also @Shivam_purbia, @MichalBZ and @dkamalakar this might help you as well)

First, thanks for sending your Github through, that has helped me understand what your working with here!

It seems that we have encountered this issue before, there is a github issue logged (I will attach the link below), where it outlines that the file_uploader data ends up being off by one upload- thus returning the previous upload.

Now, this seems to have been fixed in Streamlit version 0.73. If you upgrade your Streamlit version this should fix this

Please let me know what Streamlit version you’re currently using (so I can log that) that would be super helpful! If the upgrade doesn’t work let me know!

Happy Streamlit-ing!
Marisa
Github link: Single file upload replacements returning old data · Issue #2561 · streamlit/streamlit · GitHub

Is share.streamlit.io running 0.73? Because the problem is still there on the live demo (I’ll try locally later…)

Just checked locally with latest streamlit version (0.75), the problem is still there.

I am facing the same problem too.

Hey @hbredin and @Jake,

Thanks for flagging this with us, I wanted to let you know that I have seen your messages and I am sending this info back to our engineering team. It will probably be a few days before I get back to you as the team is entering a 2 day hackathon, so it will likely be Monday when they start to look at this!

In the meantime can you both tell me a bit about the systems your working with?

  • operating system and version
  • pip or conda environment
  • python version
  • @Jake your Streamlit version

Thanks guys,
Will get back to you soon!
Marisa

@Marisa_Smith pardon, i realised it might not be a streamlit problem from my side.

I managed to identify that the source of the error, i.e. was using AWS ECS to launch an instance of the app. When I launched in through a normal EC2 instance it is ok.

1 Like

@Marisa_Smith I guess you have full controll over the OS, version, etc since the problem occurs on Streamlit Share itself.

Hi Maria

I’m facing the same issue,when I’m trying to upload the new dataset…its still shows the previous uploaded file

Thanks

Hey @hbredin,

You said you checked locally using Streamlit version 0.75 and that it still id not work there. I was looking for that local machines info.

Marisa

@Marisa_Smith
I am facing the same error even on using the latest version(0.75). The previous file appear each time i upload a file so have to upload the file twice.

Hello everyone!

I wanted to add the link here, because we have just released a new update that patches this bug you are all experiencing! Checkout Streamlit 0.76 here:

Happy Streamlit-ing!
Marisa

Hi @Marisa_Smith, thanks for the update.

I just tried on share . streamlit . io and, now, there seems to be another problem that did not happen before.
Seems that as soon as part of the file is uploaded, the update is triggered – while it should wait for the whole file to be uploaded, shouldn’t it?

For instance, in my audio use case, when uploading a 30s audio file, I only see 6s of it.
That was not the case before the update.