Load a png image to a Streamlit web app

Options
yazidsaissi
yazidsaissi Registered Posts: 6

Hi,

I'm using Streamlit to create a web app and I want to load a png image from a managed folder into my app (without using PIL module)

Does anyone have an idea about how to do it ?

Thanks

Answers

  • VitaliyD
    VitaliyD Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 102 Dataiker
    Options

    Hi,

    If the goal is to display an image located in the managed folder in the streamlit webapp, then you can use Dataiku Managed Folders API and BytesIO. Please refer to the example below:

    import streamlit as stimport pandas as pdimport numpy as npimport altair as altimport dataikuimport iost.title('Hello Streamlit!')folder_handle = dataiku.Folder("OZG8yjfI") # replace ID with your managed foldermyfile = "dataiku-logo.jpeg" # replace with your file name and path in folderwith folder_handle.get_download_stream(myfile) as io_stream:img = io.BytesIO(io_stream.data)st.image(img, channels="RGB")

    Result:

    Screenshot 2023-07-08 at 12.01.46.png

    but it is similar to using the PIL.

    from PIL import Imagewith folder_handle.get_download_stream(myfile) as io_stream:image = Image.open(io_stream)st.image(image, channels="RGB")

    You still need some library to read from the "download_stream", so I'm not sure I fully understood the issue and the goal.

    If the above is not what you were looking for, please provide more details on what is the issue and what is the goal.

    Best,

    Vitaliy

  • yazidsaissi
    yazidsaissi Registered Posts: 6
    Options

    Hi,

    Thank you for the response, that's exactly what i needed.

    Regards,

    Yazid

Setup Info
    Tags
      Help me…