Dockerized Streamlit app, creating image download links

Good day, Im enjoying a lot Streamlink, congratulations for such a great product.
My question is the following:

  • I created an app with streamlit and dockerized it, and deployed it on a server, all good.
  • The app makes segmentation of images and generates an output image which I display on screen as a jpeg with st.image. However I also need people to download a png version of the image (with transparency) and for that I want to create a button or a link. I know how to do that, it´s not a problem. The issue is that because it´s a dockerized app, the images that I´m writing with cv2.imwrite (opencv) are written inside the docker container and are also mapped to a folder in the server that is outside of the domain area. So I´m trying to understand how to get a download to the user of the browser from this dockerized app.
    Thank you for any tips, advice :slight_smile:

something I found now is that if I do:
st.image(image2, caption=‘Transformed Image…’, channels=‘RGB’, format=‘PNG’, use_column_width=True)

then I can download the PNG doing right click on the image, but the filename of the downloaded image is: 332466bfad00ed7b65c58dba759362487e25605697ec8ab15735ef7f.png

  • How can I control what the filename of the downloaded image will be?
  • and how can I get this url somehow to also create a button or link for people to download it (as many people won´t do right click over the image to download it)

thank you :slight_smile:

any suggestions about this?
thank you so much

Hi @javismiles -

To set the name of your file, you can set the download argument, as shown in this post:

As far as setting a button or similar, it’s a similar concept to here. If you have the HTML for a button, you can make it an f-string in Python, substituting in your values, then use st.markdown to render the button.

1 Like