Hi,
we are building an app where the user can upload an image and via API get a caption returned. Now the challenge is: that we would like to delete the uploader widget after the image is uploaded for an improved UI (see what we would like to delete in the
image below. We are currently hosting it locally.
Our code:
File uploader widget
uploaded_file = st.file_uploader(“Choose an image…”, type=[“jpg”, “jpeg”, “png”])
Check if a file is uploaded
if uploaded_file is not None:
# Display the uploaded image
st.image(uploaded_file, use_column_width=True)
To not show the uploader widget, you can create session variables to control it, and be sure to save the image as well.
import streamlit as st
from streamlit import session_state as ss
if 'show_uploader' not in ss:
ss['show_uploader'] = True
if 'image' not in ss:
ss['image'] = None
if ss['show_uploader']:
uploaded_file = st.file_uploader('Choose an image…', type=['jpg', 'jpeg', 'png'])
if uploaded_file is not None:
ss['image'] = uploaded_file # backup the file
ss['show_uploader'] = False
st.rerun()
if ss['image'] is not None:
st.image(ss['image'], use_column_width=True)