Displaying a Generated Animated GIF

In my Conway’s Game of Life daisi, an animated GIF is generated, given the user inputs. Streamlit converts this image to a non-animated PNG when using Image.open/st.image to display it. Do you have another way on your system to display images directly, without having to push them through Streamlit? Currently, the user must download the generated animated GIF to access it. This is clunky compared with just displaying the animated image on the app page. I’d prefer to keep it all on the Daisi platform and not push it out to S3 or a similar platform.

Thanks,
Wade

Hi @wkoteras

Based on this : How to show local gif image? - #3 by kan - Using Streamlit - Streamlit it seems that you can render a GIF in a streamlit app with st.markdown:

import streamlit as st
import base64

"""### gif from local file"""
file_ = open("/home/rzwitch/Desktop/giphy.gif", "rb")
contents = file_.read()
data_url = base64.b64encode(contents).decode("utf-8")
file_.close()

st.markdown(
    f'<img src="data:image/gif;base64,{data_url}" alt="cat gif">',
    unsafe_allow_html=True,
)

Looking at the code of your Daisi, since you already write a tmp file, your could simply reload it and pass the content to st.markdown()

1 Like

Thanks, Jean-Marie. That did it!

-Wade

2 Likes