St.file_uploader() Client-sde?

I am working on building a client-side ML app for image classification for a project. I have a pretrained model in Pytorch and would ideally be predicting the label of every image uploaded purely client-side, meaning no data from the image is sent to the backend. Just started using streamlit for this but I’m still not sure if the solution is completely client-side? When I inspect the ‘Network’ tab of the dev console upon the call to st.file_uploader(), I see an ‘Img’ and ‘Media’ attributes get populated, which would perhaps not happen if the flow was totally client-side.

Wondering if anyone has thoughts? FYI: I implemented a custom component image uploader and it seems to not store data anywhere, the only issue I’m having is with accessing the image uploaded outside of the custom component for further streamlit manipulation…

Hi @asoin29, welcome to the Streamlit community!

How would the Pytorch model get the data to predict if you don’t pass the data to the Python backend?

Glad to be here @randyzwitch. Thoroughly enjoying using Streamlit!

I’m trying to put something together that runs computation/inference solely on the browser (kind of like tensorflow.js). Is this possible with any kind of streamlit configuration, or custom components?

Hey @asoin29,

I think it should be doable with a custom component wrapped around ONNX.js, you can load your pytorch model using it on client side and then do the inference on client side.

As part of the component, you’d have to write your own file_uploader component as well, since st.file_uploader sends the data to the Python backend. At that point, not sure Streamlit is providing a whole lot of value once you write that much JavaScript.

1 Like

Completely agreed!