如何在加载图像后隐藏 streamlit 中的 file_uploader?

How does one hide the the file_uploader in streamlit after the image is loaded?

我正在使用 streamlit,我想做的是在一个有 2 列的容器中显示 2 个图像。

代码如下:

    col1, col2 = st.columns(2)

with st.container():
    with col1:
        st.header('Top Glass Image')
        top_image = st.file_uploader('Choose Bottom Glass Image', type='jpg', key=1)
        if top_image is not None:
            # st.write(top_image)
            # st.write({'filename': top_image.name, 'file_type': top_image.type, 'filesize': top_image.size})
            st.image(load_image(top_image), width=200)
    with col2:
        st.header('Bottom Glass Image')
        bottom_image = st.file_uploader('Choose Bottom Glass Image', type='jpg', key=2)
        if bottom_image is not None:
            st.image(load_image(bottom_image), width=200)

屏幕如下所示:

理想情况下,我希望看到 2 个 file_uploader,一旦它们被选择并显示,只显示图像。

关于如何做到这一点有什么想法吗?

创建一个空容器作为支架。
参考:https://docs.streamlit.io/library/api-reference/layout/st.empty

with col2:
    st.header('Bottom Glass Image')

    holder = st.empty()
    bottom_image = holder.file_uploader('Choose Bottom Glass Image', type='jpg', key=2)
    # bottom_image = st.file_uploader('Choose Bottom Glass Image', type='jpg', key=2)

    if bottom_image is not None:
        st.image(load_image(bottom_image), width=200)
        holder.empty()