Lesson 2 official topic

I see, so perhaps @schottyd was blogging about setting up a local env vs just getting kaggle to work. That makes sense. What I still don’t understand is why kaggle just returned a blank notebook when I tried to import lesson2. But I don’t really and truly need an answer since I am moving forward w/colab for now. Anecdotally, importing Lesson1 and (I checked) Lesson3, in kaggle, seem to work just fine. So maybe something weird w/Lesson2.

Thank you again for your quick replies!

Oh, I have no idea why it just shows blank screen. Kaggle is such a mess in my opinion when using fastai. It doens’t support auto completion with tab either with fastai stuff. Maybe there is a work around, but I couldn’t figure out.

1 Like

Good to know. I’m relatively new to using notebooks and so knowing that “it’s not just me” is reassuring.

1 Like

Hi @tech15cool - yes I was blogging about setting up a local environment and I’m working on a Debian Intel machine - sorry for not being clear - I’ve updated the post. In Kaggle, as far as I understand (and I’ve not looked into it much), you’re running in a Docker container and you can use pip to install things from within a cell (!pip install <packagename>). I wouldn’t start out trying to use Miniforge for sure. All that said, I would assume it’s nothing to do with your Mac because everything about your environment should be running on Kaggle’s container by default.

I’ve barely used Kaggle either but I tried importing the chapter 2 notebook in Kaggle from github and also got a blank screen like you described, but when I imported an identical copy of the notebook (that I had previously cloned to my local machine) from my local machine, it was fine in Kaggle so I guess there’s something kooky going on in Kaggle with the github import that’s not worth spending time on.

1 Like

Hi @schottyd - thank you for the clarifications - and thanks for testing out the Lesson 2 import! I’m moving forward on Lesson 2 in Colab and I think for the time being, I will proceed there until I get stuck again. There are other reasons why I might need conda or mamba at some point, but knowing that I can go through the fast.ai course without needing to config a local env is very reassuring. I almost feel like I want Jeremy to hop online and say something like - hey guys, the world is significantly different since v5 of this course dropped in 2022, so here’s some things you need to know as you go through this course.… bc so much is different in < 2 years! Anyway, thanks again!

Yep, this works. Here’s everything I used and had luck for, this as app.py:

import gradio as gr
from fastai.vision.all import *
import skimage

learn = load_learner('model.pkl')
labels = learn.dls.vocab

categories = ('diffenbachia', 'spider', 'monstera')

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))}

title = "Plant Classifier Classifier"
description = "A plant classifier I made with with fastai. Created as a demo for Gradio and HuggingFace Spaces."
examples = [
article="<p style='text-align: center'><a href='https://lucasgelfond.substack.com/p/fastai-lesson-2-deployment' target='_blank'>Blog post</a></p>"

iface = gr.Interface(fn=predict, inputs="image", outputs="label")

and this as requirements.txt:


Most credit to @ilovescience for the tutorial :slight_smile:

Also my experience. All of the single page apps in tinypets are broken, as far as I can tell, and similarly (as a dev who is primarily focused on frontend!) couldn’t manage to wrangle the gradio JS client; doesn’t look like it’s particularly well-documented or maintained (yet!)

Let me know if you figure something out, thinking I’m going to hold off for the moment! Imagining deploying to HuggingFace eventually is less than ideal / there are more advanced deployment options as we go forward :slight_smile:

1 Like

Problems with ImageClassifierCleaner

Hello all!

I’ve been having the hardest time getting the ImageClassifierCleaner to work properly. I spent like two hours trying to get it to work on my locally hosted jupyter session and I kept getting:

Which if I go to the console looks like:

I tried a bunch of fixes for this I found online including switching to different versions of the ipywidgets and running on jupyterlabs but nothing fixed the error.

So I decided I would try Paperspace and running the lesson 2 notebook in the Paperspace + Fast.AI template, the widget shows up but the images are displayed vertically and the selection options horizontally at the bottom:

I’m also getting a js error:

The widget kind of works on kaggle, except you can’t scroll to see all of the options.

Please let me know if anyone has any suggestions :slight_smile:

Paperspace gradient solution

I decided to start watching lesson 3 where Jeremy talks about paperspace gradient. He mentioned that you can switch into jupyter labs from paperspace.

I was able to get the widget to work on paperspace gradient by switching to the jupyter lab version.

Thank You. :grinning:

I am having some issues getting the jupyter notebook to work. Wherever the text refers to a previous section, the reference only shows up as <>. Why is this happening and how can I fix it? I attached a picture example, see the first sentence of the paragraph.

Hi All,

As like first chapter I am running into dependencies, deprecated modules, no methods available warnings! Wish there was a CI/CD to maintain the dependencies better. Anyways, after browsing through the help here I was somehow able to run the notebook locally but not able to run the code on HF. Below is the code which I am trying to run on the HF:

import fastai 
from fastai.vision.all import *
import gradio as gr

def is_cat(x): return x[0].isupper()

learn = load_learner('model.pkl')

categories = ('Dog', 'Cat')

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(categories, map(float,probs)))

interface = gr.Interface(


And below is the warning I get from HF about fastai;

===== Application Startup at 2024-02-01 01:10:32 =====

Traceback (most recent call last):
  File "/home/user/app/app.py", line 12, in <module>
    import fastai
ModuleNotFoundError: No module named 'fastai'

Some of the problems I am still facing the mitigations are given below. (Note I use MacOS M1)

  1. Not able to use NBDEV extensions - Just living with it.
  2. Not able to push the changes via git CLI or git in VSCode. First VSCode used to ask me password. I was not aware about need to enter the tokens. But after 2-3 tries it gave up and didnt ask me about tokens. I am using GitHub desktop
  3. Not exactly sure which python, jupyter notebook and nbdev versions I use and how do I install. Conda/PIP/Mamba - Currently living with system Python for Mac which 3.09.

So I added requirements.txt file on HF and now able to run the model on the HF !! Phew…

I cloned the fastsetup repo and ran ./setup_conda.sh and restarted terminal, but I didnt get any utility called mamba and I am stuck now as I dont want to use system python on my Mac. Can someone please help!

1 Like

This might seem like a silly question, but I can’t find the answer anywhere. Were are we getting the cats and dogs images from in the Google/Kaggle notebook?

What is URLs.PETS and where is that defined?

URLs is defined in the docs here and its source code is here (where you can see more explicitly how it’s defined). It’s a set of pre-defined url strings for commonly used deep learning datasets.

URLs.PETS is a string:

You need to use Microsoft Azure to download images with Bing Image Search. But even for a free account they ask for a credit card.
So, I decided to use PIXABAY. See the code below:

import requests
def search_photos_pixabay(api_key, query, num_images=200):
    base_url = "https://pixabay.com/api/"
    params = {
        "key": api_key,
        "q": query,
        "image_type": "photo",  # Filter by image type (photo, illustration, vector)
        "per_page": num_images,  # Adjust num_images as needed
    response = requests.get(base_url, params=params)
    data = response.json()
    # Extract image URLs
    image_urls = [hit["largeImageURL"] for hit in data.get("hits", [])]
    return image_urls
# Your Pixabay API key
pixabay_api_key = "XXX"
# Search for grizzly bear images (fetching 200 images this time)
grizzly_bear_images = search_photos_pixabay(pixabay_api_key, "grizzly bear", num_images=200)
# Print the number of images found
print(f"Found {len(grizzly_bear_images)} grizzly bear images.")
# Now you can download or use these image URLs as needed!

Hugging Face Gradio Issue
Not able to execute code to publish Gradio

I tried updating the code with

intf = gr.Interface(
inputs=gr.Image(shape=(192, 192)),
examples = [“Cat.jpg”,“Fox.jpg”,“Dog.jpeg”])

but still I am facing the same issue.

Check with the gradio documentation for the current syntax. Quickstart

Thanks, it’s working now.
Can’t explain how much happy I am. Thanks again.

With help from this excellent forum and linked blogs, I’m mostly sorted with updating the deprecated calls on third party libraries from the book and 2022 course for this lesson/chapter, and the jupyter notebooks appear to be running well locally under WSL.
However but I’ve hit a dead end with my attempts to try to run my bear classifier locally with calls to the model on HF via the API. I figured the whole point is the portability of this approach but the Gradio API information now seems wholly dependent on having installed clients via npm - yet another set of dependencies.

(I’m not really a front-end javascript person so this client dependency might be much more robust and self contained than I think!)
Jeremy’s example showed what appeared to be a much simpler API methodology without being reliant on installed clients. He appears to be using simple vanilla javascript so that as he says at about 1:10:32 in the video, he doesn’t “need any software installed…to use a javascript app”
Am I missing something or is Gradio now not a very portable, flexible approach that allows someone to simply “double click on an html file in explorer” these days? An end user does need dependencies installed…or can they be packaged internally in the HTML file?