Hi,
Question: Is there any way to cache videos/gifs in streamlit. In my case, I have some gifs which i am showing in a streamlit ui page. But whenever i open the page, It is consuming my internet. Upon researching, I found out that st.cache_data caches data on server side. So is there any way to load/cache gifs without requesting streamlit server everytime i open/load the page.
Code which i used:
show_gif
- helper function.
def show_gif(file_name: str) -> Any:
"""Convert .gif content into base64 encoded format.
Parameters
----------
file_name: str
file_name - Location of the gif.
Returns
-------
Return base64 encoded string format of the gif provided to the function.
"""
file = open(file_name, "rb")
contents = file.read()
data_url = base64.b64encode(contents).decode("utf-8-sig")
file.close()
return data_url
Displaying the GIF
:
st.markdown(
f'<img src="data:image/gif;base64,{show_gif("./assets/gifs/local_gif.gif")}" width="750" height="444">',
unsafe_allow_html=True,
)