RustyWhitePaper/HelloNeural
0
1{2 "cells": [3 {4 "cell_type": "code",5 "execution_count": 1,6 "metadata": {},7 "outputs": [],8 "source": [9 "import fastai\n",10 "from fastai.vision.all import *\n",11 "from duckduckgo_search import DDGS\n",12 "import duckduckgo_search as ddgz\n",13 "from fastcore.all import *\n",14 "from itertools import islice\n",15 "\n",16 "\n",17 "def search_images(query, max_images=30):\n",18 " ddgs = DDGS()\n",19 " ddgs_images = ddgs.images(keywords=query)\n",20 " limited_images = list(islice(ddgs_images, max_images))\n",21 " return L(limited_images).itemgot('image')\n"22 ]23 },24 {25 "cell_type": "code",26 "execution_count": 3,27 "metadata": {},28 "outputs": [29 {30 "ename": "",31 "evalue": "",32 "output_type": "error",33 "traceback": [34 "\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."35 ]36 }37 ],38 "source": [39 "# Search for images\n",40 "dogs = search_images('dog')\n",41 "cats = search_images('cat')\n",42 "path = Path('images')\n",43 "len(dogs)\n",44 "for index, url in enumerate(dogs):\n",45 " dest = path / 'dogs'\n",46 " dest.mkdir(exist_ok=True, parents=True)\n",47 " download_images(dest=dest, urls=dogs, max_pics=30)"48 ]49 }50 ],51 "metadata": {52 "kernelspec": {53 "display_name": "Python 3",54 "language": "python",55 "name": "python3"56 },57 "language_info": {58 "codemirror_mode": {59 "name": "ipython",60 "version": 361 },62 "file_extension": ".py",63 "mimetype": "text/x-python",64 "name": "python",65 "nbconvert_exporter": "python",66 "pygments_lexer": "ipython3",67 "version": "3.11.7"68 }69 },70 "nbformat": 4,71 "nbformat_minor": 272}73 