widgets.FileUpload() not working

When executing course 4’s “01_intro.ipynb” notebook , code :
uploader = widgets.FileUpload()
Result is : “FileUpload(value={}, description=‘Upload’)
I have imported that fastai using
conda install -c fastai -c pytorch fastai
conda install graphviz
conda install -c conda-forge/label/gcc7 python-utils

This is running on Windows 10 on my PC.
But file upload widget is not working. Any suggestions? Thanks…

1 Like

It worked for me with following.

!pip install ipywidgets

from ipywidgets import *

This is unfortunately also not working for me. I can see in the upload widget it increments to a higher number, however, there is no data inside it that I can see.

I am using a fresh google AI notebook server

This is returned for:
FileUpload(value={}, description=‘Upload’)

This is returned for:

IndexError Traceback (most recent call last)
----> 1 uploader.data[0]

IndexError: list index out of range

Any help would be greatly helpful. I can manually upload images to my folders, but seemingly unable to access the uploader widget variable.

1 Like

Also, I did try the above to install ipwidgets and tried to import as well

Hi, This does not work in Jupyterlab, it works in Jupter Notebook. It worked for me. This is the simplest solution rather than getting stuck in the under the hood code of the notebooks. Best of luck. Inayat

1 Like

It works for me wit datacrunch.io but it doesn’t work for google ai notebooks which is what I would prefer.

I also tried it via classic notebook mode vs JupyterLab and it still does not work.

Facing the same issue with a Jupyter lab notebook on gcp. Has anyone found a solution here?

According to installation instructions in ipywidgets docs you need to have node.js installed and install the labextension:

jupyter labextension install @jupyter-widgets/jupyterlab-manager@2.0

2.0 in the end is for jupyterlab version 2.x
This worked for me on a local machine, may be it helps on gcp

Were you able to resolve this. It was working perfectly in paperspace/gradient. I then switched to GCP and uploader just doesn’t work.

Nope. I used paperspace for the first two lessons.

Thanks. I’ll do the same. I actually came to GCP from Paperspace because it was getting impossible to connect to Paperspace on to free GPUs when their servers get busy. .

Hi Inayat, how do you get to Jupyter Notebook from GCP’s AI Notebook GUI? Thanks so much.

This doesn’t work for me. I tried this:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
and that doesn’t work either. I got the above from the ipywidgets documentation page https://ipywidgets.readthedocs.io/en/stable/user_install.html

Is anyone else running into this too?

1 Like

Also didn’t work for me.

1 Like

I am running my Juypter Notebooks directly on my server and not GCP.

I couldn’t find an answer to this on this forum, but an easy work-around is to upload your image(s) to the notebook’s /images dir, and then edit the code in cell #21, uploader = SimpleNamespace(data = ['images/your-filename-here'). Hope this helps.

1 Like

Yeah, I’m running into lots of problems in FastAI so far. This is just one of them. The FileUpload() widget isn’t working for me either.

The Upload button shows up. I can click on it. I can browse for a file. I can select a file. The number in the Upload button increments. Then … nothing. It just does nothing. I can check the images directory through the terminal, and my file never gets uploaded. If I click the button again, it just makes me browse for another file and the counter increments. If I hit Shift Enter it just resets the counter. But no matter what I try, it never actually uploads anything.

I’m on Paperspace/Gradient, if that’s relevant.

I also tried
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install @jupyter-widgets/jupyterlab-manager@2.0
to no effect.

I guess I’ll try some other clunky workaround to get a file into that image folder…

Hey @Alexander77, if the counter is increasing, its actually uploading the files. The code provided by Jeremy in the next section shows you how to interact with the uploaded files.

Try this

btn_upload = widgets.FileUpload()

upload a file, then run:

img = PILImage.create(btn_upload.data[-1])

The above code will get the last uploaded image, hence the indexing -1 and create a PIL image from it.
Then run:


to see if the image is displayed. Does this sequence of code work?

I was confused when using Colab at first but found that it did work. I assumed wrongly I would see my uploaded picture. You don’t, you need to go directly and run the prediction code.
If you do want to see your uploaded picture

replace the cell with:
\ For the book, we can’t actually click an upload button, so we fake it
uploader = SimpleNamespace(data = [‘images/chapter1_cat_example.jpg’])

img = PILImage.create(uploader.data[0])

When the image is uploaded it will display.

To go faster I also used this code which loads the images from Google drive (does not use upload button):

\ comment the first two lines after first run
from google.colab import drive
%cd /content/drive/My\ Drive/
uploader = SimpleNamespace(data = [‘your_img_folder/img_to_test.jpg’])
img = PILImage.create(uploader.data[0])

The upload button also does not work for me, I followed the instruction as mentioned by jimmiemunyi above and Jeremy in notebook, and when pressing the button, I can see that my image seems loaded and the upload button is incremented by 1, but still the image does not show with img.to_thumb(128,128). I can manually type the image file as mentioned by another user, but it defeat the purpose of making it user friendly to upload new images, so I would like to resolve this problem.

I am using Jupiter notebook on JupyterLab on GCP, and Safari if this is useful info.

Appreciate any help!