Lesson 2 official topic

Hi everybody,

gr.inputs and gr.outputs was giving me an error. The following worked for me. May help someone.

image = gr.Image(width=192, height=192)
label = gr.Label()
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
2 Likes

Hi @jithesh82 ,
Thanks for sharing.

Absolutely! @CraigRichards

Gradio have been changed recently on the newest version 5.3.0
it changes things in the app.py file like

gr.Interface(fn=predict,
             inputs=gr.Image(height=512, width=512),
             outputs=gr.Label(num_top_classes=3),
             title=title,
             description=description,
             examples=examples).launch()

please update it
I was also following your blog and did had issues so i fixed :slight_smile:
references

3 Likes

Thank you. You saved my time!

1 Like

I want everyone to check this post about update recent updates in Deployment of Model using Gradio I updated Tanishq Tutorial code little bit. Feel free to give comments

1 Like

The Azure key generation and access to its image search api, has become a bit problematic. I didn’t get access to the api, in spite of registering my credit card and all the details. So, I resorted to duckduckgo, as taught in the last lecture for bird search. Feel free to refer here (https://www.kaggle.com/code/drazz3r/fastai-course-chapter2)

1 Like

That was the recommendation Claude gave me. Your link is not working but I would love to see your workaround using DDG.

!pip install -U duckduckgo_search
from fastcore.all import *
from duckduckgo_search import DDGS #DuckDuckGo has changed the api so we need to update 
from fastai.vision.all import *
from fastdownload import download_url





def search_images(keywords, max_images=200): 
    return L(DDGS().images(keywords, max_results=max_images)).itemgot('image')
import time, json

bear_types = 'grizzly','black','teddy'
path = Path('bears')
if not path.exists():
    path.mkdir() # make directory if not already exist
    for o in bear_types:
        dest = (path/o) # go direc: girzzly , black , teddy
        dest.mkdir(exist_ok=True) # if already exist dont make new one 
        download_images(dest, urls=search_images(f'{o} bear'))

fns = get_image_files(path)
failed = verify_images(fns)

Run This code in Kaggle notebook it will work.

1 Like

Forgot to make the notebook public, before sharing :sweat_smile:
I have done something similar to Hussain (above)

link to my notebook (fastai_course_chapter2 | Kaggle)

Hello, I’m in the part of deploying to Hugging Face
My app.py file is like this :

all = [‘load_learner’,‘learn_inf’, ‘classify_image’, ‘categories’, ‘image’, ‘label’, ‘intf’]

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

learn = load_learner(‘export.pkl’)

categories = (‘grizzly’,‘black’,‘teddy’)

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

image = “image”
label = “label”
examples = [‘grizzly.jpg’, ‘black.jpg’, ‘teddy.jpg’]

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)

I keep getting error :

Traceback (most recent call last):
File “/home/user/app/app.py”, line 6, in
learn = load_learner(‘export.pkl’)
NameError: name ‘load_learner’ is not defined
Traceback (most recent call last):
File “/home/user/app/app.py”, line 6, in
learn = load_learner(‘export.pkl’)
NameError: name ‘load_learner’ is not defined

What am I missing here?

My files :
image

replace from fastai.vision.widgets import * with from fastai.vision.all import *

learn = load_learner(‘export.pkl’) with learn = load_learner(‘model.pkl’)

if you want to see deployment details check my notebook here

Thanks!

1 Like

Were you ever able to get the hugging face part working? I messed around for a big but I could never get it to run.

Everything should work for me but I also have a similar issue. My pkl file is shown as unsafe and therefore HF won’t run my build.

Hi everyone - sorry in advance if this is the wrong place to post, but I had a small issue with getting a working Gradio link. I trained my model on Kaggle, downloaded it, and tested it out with images through Jupyter Notebook, and it seems to work well. However, when I run this line of code on Jupyter Notebook (updated from the Lesson 2 video to take into account the new Gradio update):

image = gr.Image()
label = gr.Label()

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
intf.launch(inline=False, share=True)

Then I get a huge error message that starts with “ERROR: Exception in ASGI application” and ends with “TypeError: argument of type ‘bool’ is not iterable”. Additionally, even though I do actually get a Gradio link (Running on local URL: …), when I click on the link it says ‘Internal Service Error.’

My guess is that something with the way I’m calling Gradio is not working, but I’m not sure, and so far ChatGPT hasn’t been super helpful, so I’d love to hear from anyone who has come across this issue or has any ideas :slight_smile: Many thanks in advance!

Ended up fixing this issue by downloading an older version of Gradio by running “pip3 download Gradio==3.50” in my shell ^^^^ for future reference anyone who is having this problem

loading pkl file was resulting in warnings for me on huggingface space . An example of how to load weights
https://96jhasuraj.github.io/catsvsdogs/

Hi , see if my comment helps :slight_smile: APP | catsvsdogs

Thank you so much i was facing the same issue