{ "info": { "author": "Oliver Reid", "author_email": "reiol787@student.otago.ac.nz", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Microsoft Cognitive Services API for Machine Learning\nThis is a thin python wrapper for Microsoft's Microsoft Cognitive Services API focused on collecting image training data for use in machine learning. I have based this library off of another repoisitory created by __[tristantao](https://github.com/tristantao)__ called __[py-ms-cognitive](https://github.com/tristantao/py-ms-cognitive)__.\n\nIntroduction\n=====\nThis module requires that you sign up for Microsoft's Microsoft Cognitive Services and acquire an application key.\n\n#### Steps\n\n1. Visit __[Microsoft Cognitive Services Signup Page](https://azure.microsoft.com/en-us/try/cognitive-services/)__.\n2. Select the 'Search' tab.\n3. Click 'Get API Key' on 'Bing Search APIs v7' and agree to both checkboxes.\n4. Select 'Next' and register using one of the options.\n5. This will take you to a page where you need to copy either 'Key 1' or 'Key 2' at the bottom of the 'Endpoints' list.\n\nInstallation\n=====\nTo install py-ms-cognitive-ml I recommend using `virtualenv`.\n\n#### Quick instructions for Python 3.*\n\n```sh\npip3 install py-ms-cognitive-ml\n```\n\n#### Full instructions for Python 3.*\n\n1. Install Python 3: `sudo apt-get install python3-pip`\n2. Install Virtual Environments: `pip install virtualenv`\n3. Change to the directory that you want to create your project in and setup an output folder. For example `cd ~/Desktop/ && mkdir bing-api && cd bing-api && mkdir output`\n4. Create a Virtual Environment for your project: `virtualenv -p python3 bing-api-env`\n5. Install py-ms-cognitive-ml library: `pip3 install py-ms-cognitive-ml`\n\n* Note that py-ms-cognitive-ml requires the requests library.\n\nUsage\n=====\n\nRemember to set the `API_KEY` as your own.\n\n#### Getting Images\n\n```py\n# Imports\nimport requests\nimport os\nfrom py_ms_cognitive_ml import PyMsCognitiveImageSearch\n\n# Settings\nsearch_terms = [\"keys\", \"cats\", \"dogs\"]\nserach_quota_per_term = 5\nresults = []\ntotal_downloads = 0\n\nif not os.path.exists(\"output\"):\n os.mkdir(\"output\")\n\n# Main\nfor search_term in search_terms:\n \n # Make API call\n search_service = PyMsCognitiveImageSearch('API_KEY', search_term)\n result_list = search_service.search_all(quota=serach_quota_per_term)\n\n # Scrape images\n if not os.path.exists(\"output/\" + str(search_term)):\n os.mkdir(\"output/\" + str(search_term))\n\n print(\"\\nDownloading images for term: '\" + str(search_term) + \"'\")\n\n i = 0\n urls = []\n for i in range(0, len(result_list)):\n print (\"Downloading image from \" + str(result_list[i].name))\n\n # Download the image\n try:\n if result_list[i].url not in urls:\n\n image_file = requests.get(result_list[i].url, stream=True)\n\n if image_file.status_code == 200:\n with open(\"output/\" + search_term + \"/\" + str(i) + \".\" + result_list[i].extension, 'wb') as f:\n f.write(image_file.content)\n \n urls.append(result_list[i].url)\n else:\n raise requests.exceptions.RequestException\n\n else:\n print(\"Image already downloaded. Skipping image.\")\n\n except requests.exceptions.RequestException:\n print(\"Something went wrong with the request. Skipping image.\")\n\n i += 1\n\n results.append(str(len(urls)) + \" images downloaded for term '\" + str(search_term) + \"'.\")\n total_downloads += len(urls)\n\nprint(\"\\n\")\n\nfor result in results:\n print(result)\n\nprint(str(total_downloads) + \" images based on \" + str(len(search_terms)) + \" search term(s) downloaded.\")\n```", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/beardo01/py-ms-cognitive-ml", "keywords": "Microsoft,Cognitive Services,API,Search,Image Search,Machine Learning,Image Scraping", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "py-ms-cognitive-ml", "package_url": "https://pypi.org/project/py-ms-cognitive-ml/", "platform": "", "project_url": "https://pypi.org/project/py-ms-cognitive-ml/", "project_urls": { "Homepage": "https://github.com/beardo01/py-ms-cognitive-ml" }, "release_url": "https://pypi.org/project/py-ms-cognitive-ml/0.0.2/", "requires_dist": null, "requires_python": ">=3", "summary": "Light wrapper for Microsoft's Cognitive Services API to facilitate data gathering for machine learning.", "version": "0.0.2" }, "last_serial": 3389285, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "d456750c766f6e2504ed76beab07aa90", "sha256": "b0939811af3841c9105f44d8a36a07c326b323db9aff53c88a099e68fe42d864" }, "downloads": -1, "filename": "py-ms-cognitive-ml-0.0.2.tar.gz", "has_sig": false, "md5_digest": "d456750c766f6e2504ed76beab07aa90", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 6666, "upload_time": "2017-12-05T02:53:00", "url": "https://files.pythonhosted.org/packages/e4/3f/e04149086a677ebbf15b5b293584ac09312970adb8c0bf146995d7d6819d/py-ms-cognitive-ml-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d456750c766f6e2504ed76beab07aa90", "sha256": "b0939811af3841c9105f44d8a36a07c326b323db9aff53c88a099e68fe42d864" }, "downloads": -1, "filename": "py-ms-cognitive-ml-0.0.2.tar.gz", "has_sig": false, "md5_digest": "d456750c766f6e2504ed76beab07aa90", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 6666, "upload_time": "2017-12-05T02:53:00", "url": "https://files.pythonhosted.org/packages/e4/3f/e04149086a677ebbf15b5b293584ac09312970adb8c0bf146995d7d6819d/py-ms-cognitive-ml-0.0.2.tar.gz" } ] }