I am not sure, if I am using all the widgets correctly here, but in my code, but when I used the file_uploader within the form container, the image uploaded isn’t immediately saved to the session_state variable I set it to. Instead, when I upload two images, and click the form submission button, it sends me to the top of the screen and the session state is None where my images are supposed to be. When you click the submission button again, the session_state now contains the images. My app is on streamlit cloud here. Any recommendations or help would be appreciated!
I use file_uploader in the form like this:
form = st.form('fast-style-transfer-form') st.session_state.source_image_data = form.file_uploader( 'Choose a source image to recieve a style', type=['png', 'jpg', 'jpeg']) st.session_state.style_image_data = form.file_uploader( 'Choose an image to to get a style from', type=['png', 'jpg', 'jpeg'])
and I use the session state in my form_submit callback here:
if st.session_state.source_image_data is None: form.error('Please provide a valid Source Image') return if st.session_state.style_image_data is None: form.error('Please provide a valid Style Image') return with Image.open(st.session_state.source_image_data) as im: source_image = im.convert('RGB') with Image.open(st.session_state.style_image_data) as im: style_image = im.convert('RGB')