How to Pass In an image?

Hello. I am having some difficulty trying to pass an image into this program to make sure I did this right. It is a burger detector - similar to the cat vs dog detector. I tried using the uploader discussed in the book. I even copied it line by line.

Here is my code…

!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()

from fastai.vision.all import *
path=untar_data(URLs.FOOD)/‘images’/‘hamburger’

path.ls()
files=get_image_files(path)
len (files)

files[0]

files[100]

files[0].name

dls = ImageDataLoaders.from_folder(path, valid_pct=0.2,item_tfms=Resize(224))
dls.valid_ds.items[:3]

dls.show_batch()

learn = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)

learn.predict(files[0])

learn.show_results()

uploader = widgets.FileUpload()
uploader

FileUpload(value={}, description=‘Upload’)

img = PILImage.create(uploader.data[0])
is_burger,_,probs = learn.predict(img)
print(f"Is this a hamburger?: {is_burger}.")
print(f"Probability it’s a hamburger: {probs[1].item():.6f}")

Maybe check your imports once…I think you need to import an ipy widget or something.

Well, I tried adding this:

from fastai.basics import *

Did not seem to help…but yes I agree, it looks like something is wrong with the import widget(s).
Anyone else have any idea?

Ok fixed. This works:

btn_upload = widgets.FileUpload()
btn_upload

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:

img.to_thumb(128,128)

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