Problem with file_uploader

Hi everyone! I’m trying to make a simple Streamlit App to help me with a labeling task for a ML project that I have,
The proccess is roughly like this:

  • An image gets uploaded
  • It goes through an OCR and returns an array of lines
  • Each line should be labeled separately

I wrote this to show each line with a selecbox with the possible labels

uploaded_file = st.file_uploader(label='Resumen de cuenta')

file_uploaded = False

lineas = []
labels = []


if uploaded_file is not None:
  bytes_data = uploaded_file.read()
  with open('/tmp/resumen', 'wb') as f:
      f.write(bytes_data)

st.image('/tmp/resumen')
lineas = toText('/tmp/resumen') 

for i in range(len(lineas)):
labels.append(st.selectbox(label=lineas[i],options=list(categories.keys()),key=i))

st.write(labels)

but the problem I’m having is that everytime I change a selectbox everything gets rerendered, and the image I uploaded give an error

The moment I upload the image my app looks like this:

But when I change a selectbox it gives the following error:

Is there a workaround for this?

Thanks in advance!