Array download in format .jpeg - cloud

I have array, need to download it in format .jpeg. In cloud.

i do -

img  = tensorflow.keras.utils.array_to_img(array)

(Image.fromarray don`t work )

if i do -

st.image(img)

i can to see picture in browser .

But

st.download_button(label='download',data=img,file_name = 'O.jpg')

don`t work

On local computer work:

img =  Image.fromarray(array)
img.save('image_file.jpg')

in Streamlit cloud it don`t work ((((

I made it !!! ))))

            pred_ar_int = pred_ar.astype(np.uint8)
            im = Image.fromarray(pred_ar_int)
            with io.BytesIO() as f:
                im.save(f, format='JPEG')
                data = f.getvalue()
            st.download_button(label='Скачать',data=data,file_name='change_bg.jpg')