I’ve deployed a Streamlit app on Google Cloud Run and I’m having issues with displaying an image. The image is loaded using Image.open() and displayed using st.image() . Initially, the image was displayed correctly, but after a day or two, part of the image becomes a black box as shown below:
Has anyone experienced a similar issue or have any suggestions for how to resolve it? Here are some details about the image and deployment environment:
The image is a PNG file with dimensions 740x740 pixels.
The app is deployed on Google Cloud Run using a Docker container.
I’d appreciate any help or guidance on how to resolve this issue. Thank you in advance!
Is the path to the image “DATA/image/logo.png”? If so, I would pass it as title_image = Image.open("DATA/images/logo.png") rather than title_image = Image.open(DATA / "images/logo.png")
My guess is that the Image is never closed, so each time the app is rerun, a new pointer is created without properly handling the previous open action. Do you get the same issue using a context manager?
import streamlit as st
from PIL import Image
from pathlib import Path
DATA = Path(".")
with Image.open(DATA/"logo.jpeg") as title_image:
st.image(title_image)
Just curious, is there a particular reason to not pass the path to st.image directly?
Thank you so much for your advice! I have now passed the image path as a string to st.image. I’ll come back and select your answer as the solution if the issue goes away!