Hi all!
It’s my first post here, I just started trying to run the cells by myself on the course and I’m already having trouble in the beginning, when we’re supposed to download the bird image from duckduckgo. That’s the code:
from duckduckgo_search import ddg_images
from fastcore.all import *
def search_images(term, max_images=200): return L(ddg_images(term,max_results=max_images)).itemgot('image')
urls = search_images('bird photos', max_images=1)
urls[0]
error:
IndexError Traceback (most recent call last)
<ipython-input-35-aa080084010c> in <cell line: 3>()
1 # urls = search_images('bird photos', max_images=1)
2 urls = search_images('bird photos', max_images=1)
----> 3 urls[0]
1 frames
/usr/local/lib/python3.10/dist-packages/fastcore/foundation.py in __getitem__(self, idx)
110 def _xtra(self): return None
111 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
--> 112 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
113 def copy(self): return self._new(self.items.copy())
114
/usr/local/lib/python3.10/dist-packages/fastcore/foundation.py in _get(self, i)
114
115 def _get(self, i):
--> 116 if is_indexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i]
117 i = mask2idxs(i)
118 return (self.items.iloc[list(i)] if hasattr(self.items,'iloc')
IndexError: list index out of range
it seems like the search isn’t returning any results
print(urls)
[]
urls is an empty array. ive basically just copy and pasted the code from the 00-is-it-a-bird-creating-a-model-from-your-own-data.ipynb notebook on colab to my personal studying colab. Actually on both the function runs fine only once but if I try to run the cell again it won’t let me.
I tried to use only the ddg_images function according to duckduckgo-search · PyPI
result = ddg_images('bird photo')
print(result)
None
I searched in the forum and saw some suggestions to see the underlying code and rewrite it but I don’t understand why it works once and then it stops working and also the doc on DDG seems pretty straightforward. So if anyone has some input about it would be great because I am not sure how to go about rewriting the underlying function.
I guess I can always go and download an image myself but I since recommendation number 1 is to try to run the notebooks myself and be active in the forums I guess it’s worth the try.
Appreciate the time and look forward to interact in the forums over the next weeks