Summary
@st.cache_data and @st.cache_resource is not working.
getting error as âMediaFileHandler: Missing file 91eb56392aff5f049d3a2e04520d48df656709f5ba77728596b18199.pngâ in few instances.
Steps to reproduce
Code snippet:
@st.cache_data
def KMEANS_Distortion(X, Name):
"""
Visualization of Distortion to select the optimal clusters
"""
from yellowbrick.cluster import kelbow_visualizer
from sklearn.cluster import KMeans
from matplotlib import pyplot
a = kelbow_visualizer(KMeans(),X, k = (4,30) )
try:
os.mkdir("Output")
except OSError:
pass
pyplot.savefig(f'Output/{Name}.png')
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
At the first time when the code is running the image is generated and saved in the local folder and it is cached. And when below menus or buttons are presses without rerunning same image have to be populated.
Actual behavior:
When below widgets are used every time when the page gets refreshed KMEANS_Distortion function runs again and producing different output.
Debug info
- Streamlit version: (get it with
$ streamlit version
) - Python version: (get it with
$ python --version
) - Using Conda? PipEnv? PyEnv? Pex?
- OS version:
- Browser version:
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
- Link to your GitHub repo:
- Link to your deployed app:
Additional information
P.S. I have the same piece code without any changes in the different directory saved as previous versions which works as expected, unable to understand what is wrong but none of the cache is working in the current version. Please advise what is that i am doing wrong.