Beginner: Creating a dataset, and using Gradio / Spaces ✅

Not sure if this is going to post in the right place, but I had a question about paperspace. After you click on the Jupyter lab view is there a way to get back to the paperspace view so you can shut down the gradient server when you exit? Thanks and excited to work on the material provided by what seems like a great community!

Here you go!

1 Like

Gradio error: Unexpected token ‘<’, " <!DOCTYPE "… is not valid JSON

I am using kaggle to build a classifier. The model correctly outputs predictions when I test this function on an image downloaded with DuckDuckGo:

labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

I then use gradio to create an interface to upload test images via:

import gradio as gr
iface = gr.Interface(fn=predict, 
             inputs=gr.Image(shape=(192, 192)), 
             outputs=gr.Label(num_top_classes=len(colors)),
             title='Lego piece classification',
             description='Upload a picture of a Lego piece to classify its color.',
             live=True  # Set live=True to update predictions as you upload images
                    )
iface.launch(share=True)

But whenever I input an image, the gradio interface returns the error

Unexpected token ‘<’, " <!DOCTYPE "… is not valid JSON

and the kernel restarts. Has anyone else encountered this error before? What might be going on?

my first question would be, have you installed gradio? secondly in the inputs=gr.Image i think the shape attribute is not used anymore. try inputs=gr.Image(type=“pil”), this should solve your problem. let me know.

Thanks for the reply! I did pip install gradio. I still encounter the same issue with inputs=gr.Image(type=“pil”). Do you have any other suggestion? Or do you have a kaggle notebook with a working gradio interface you could share?

Hmm it should be working… although I had a slightly different approach for one of my first Gradio classification projects which I did a while ago. You can take a look at mine here. Hope this helps!

I’m having persistent and changing issues with the ImageClassifierCleaner (i’m working in Kaggle). The first time it the cell was running for 20 minutes with no output (it took 7 minutes in total to run everything prior). I restarted my computer and tried again. This time it worked but when I change labels, the images don’t refresh. I tried again, this time it only gave me the option boxes (labels & datasets) but no images. I tried again and it just gave me a vertical list of all the images and the images were different sizes. I tried again and the same thing happened a few times. I tried again a few days later and it loaded and changed from Grizzly to Teddy but when I changed the label to ‘Black’ or ‘Grizzly’ the images didn’t refresh. I also tried to run the following code to delete the Teddy images I had been able to mark for deletion but this cell was just running for 10 minutes without any changes and the ImageClassifierCleaner GUI had still not refreshed to be a Grizzly.