Using search_images_bing in Kaggle notebook

I’m trying to do Exercise 8 from Chapter 2 of the book. How do I import search_images_bing?

Bing search was problematic and replaced with DuckDuckGo

For usage and example. See Practical Deep Learning for Coders - 1: Getting started
and search_images() in
Is it a bird? Creating a model from your own data | Kaggle

I went there as you suggested, but where is search_images defined?

Sorry. search_images is just a wrapper around ddg_images.

It was in the ‘Is it a bird?’ notebook, though the code section was collapsed under a “show hidden code” section.

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

Hi Allen! I am trying to replace the search_images_bing with search_images_dgg (notebook Chapter 2: 02_production). I am only able to retrieve arrays full of None.
Any suggestion?

It may be none of these, but let’s try a few common ones.

First guess. The request is blocked by host.

To rule out a notebook host service blocking the requests, try it on another service or local machine. Ie if on colab , try it from Kaggle or vice versa.

Second guess. Ddg is ignoring requests from an ip range, ip might be softbanned for period of time. Try again later.

Third guess. Old bug or install issue. Re/install with -U update

!pip install -Uqq fastai duckduckgo_search


Thank you, I figured it out.

For those encountering this very same problem, I suggest changing the for loop to use ddg in this way:

if not path.exists():
    for o in bear_types:
        dest = (path/o)
        results = search_images_ddg(f'{o} bear')
        download_images(urls=list(results), dest=dest)