Search_images function help

url=search_images(‘search photos’, max_images=1)

In ‘Is it a bird? Creating a model from your own data’ kaggle notebook it returns url,
but its not working in jupyter notebook.

do need to create this function ? to get urls

Hey Anurag,

Yes the function search_images needs to be defined.
The code for it is in the first cell of “Step 1: Download images of birds and non-birds”:

from duckduckgo_search import ddg_images
from fastcore.all import *

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return L(ddg_images(term, max_results=max_images)).itemgot('image')

This cell seems to be hidden by default on Kaggle, you have to press “Show hidden code” :wink:

1 Like

hi there, how are we specifying specific pictures from duckduckgo website?

thanks

Hi, if you observe closely, the search_images function needs to be provided 2 inputs, term and max_images

def search_images(term, max_images=30):
    print(f"Searching for '{term}'")
    return L(ddg_images(term, max_results=max_images)).itemgot('image')

The specific “thing” that you want to be searched must be put in term.

For example:

urls = search_images('cheese', max_images=5)

This will search for cheese images, a total of 5.

Hooe that helps!

1 Like

yes it helps. thank you.

1 Like