Load a png image to a Streamlit web app

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

  • Vitaliy
    Vitaliy Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 102 Dataiker
    edited July 17

    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 st
    import pandas as pd
    import numpy as np
    import altair as alt
    import dataiku
    import io
    
    st.title('Hello Streamlit!')
    
    folder_handle = dataiku.Folder("OZG8yjfI")  # replace ID with your managed folder
    myfile = "dataiku-logo.jpeg"  # replace with your file name and path in folder
    
    with 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 Image
    with 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

    Hi,

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

    Regards,

    Yazid

Setup Info
    Tags
      Help me…