Images not loading when deploying streamlit app on GCP

Viewed 168

I created a streamlit app for data science. The user uploads an image and gets an output with an image displayed, but after deploying the app I'm getting zero rather than an image.

import streamlit as st

@st.cache(allow_output_mutation=True)
def load_image(out):
    if out=='yes':
        im = PIL.Image.open("images/yes.jpg")
        return im

dis = load_image(output)
st.image(dis, channels="RGB)

but after deploying I get:

enter image description here

1 Answers

Solved by transforming the image (OpenCV, pillow ...) into bytes

import base64
import cv2
import streamlit as st
retval, buffer = cv2.imencode('.jpg', img )
binf = base64.b64encode(buffer).decode()
st.image("data:image/png;base64,%s"%binf, channels="BGR", use_column_width=True)
Related