I have been struggling to upload images into my Jupyter notebook using ipywidgets.FileUpload(), it works ok with text files but with binary files the content is always corrupted. Particularly with images, those are always stored as "data" so keras.preprocessing.image.load_img() is unable to use them. The code I am using is:
import ipywidgets as widgets
uploader = widgets.FileUpload()
uploader
for name, file_info in uploader.value.items():
with open(name, 'wb') as fp:
fp.write(file_info['content'])
I have tried multiple solutions but nothing is working with binary files, any hint or help is well received. My environment is GCP AI Platform Notebooks (JupyterLabs 1.2.16, ipywidgets 7.5.1) and the references I have been using are:
- Extracting text from MS Word Document uploaded through FileUpload from ipyWidgets in Jupyter Notebook
- https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#File-Upload
- Access the content from multiple uploaded files from ipywidgets FileUpload
- https://github.com/jupyter-widgets/ipywidgets/pull/2258