ValueError: The truth value of an array with more than one element is ambiguous

My app is running locally, and I’m trying to pass in a numpy array as an argument into a callback for a button. For context:

uploaded_img = np.asarray(

and so when I do something like:

st.button(UPLOAD_CHOICE_STR, on_click=_predict, args=uploaded_img)

it throws the aforementioned error. I’m not doing anything with the array inside the callback, for ex nothing of the sort: β€œif uploaded_img == 4” so I’m not exactly sure what the issue is and would appreciate any help.


I fixed it, and the solution is pretty simple. Wrap the args in a tuple and convert to a list as below:

st.button(UPLOAD_CHOICE_STR, on_click=_predict, args=(list(uploaded_img)))
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.