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!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.