diff --git a/README.md b/README.md index 6b41a9b..d51f0e4 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This project framework provides examples for the following services: * Using the **Bing Autosuggest SDK** [azure-cognitiveservices-search-customsearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-autosuggest) for the [Autosuggest API](https://azure.microsoft.com/services/cognitive-services/autosuggest/) * Using the **Bing Custom Search SDK** [azure-cognitiveservices-search-customsearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-customsearch) for the [Custom Search API](https://azure.microsoft.com/services/cognitive-services/bing-custom-search/) +* Using the **Bing Custom Image Search SDK** [azure-cognitiveservices-search-customimagesearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-customimagesearch) for the [Custom Image Search API](https://azure.microsoft.com/services/cognitive-services/bing-custom-search/) * Using the **Bing Entity Search SDK** [azure-cognitiveservices-search-entitysearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-entitysearch) for the [Entity Search API](https://azure.microsoft.com/services/cognitive-services/bing-entity-search-api/) * Using the **Bing Image Search SDK** [azure-cognitiveservices-search-imagesearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-imagesearch) for the [Image Search API](https://azure.microsoft.com/services/cognitive-services/bing-image-search-api/) * Using the **Bing News Search SDK** [azure-cognitiveservices-search-newssearch](http://pypi.python.org/pypi/azure-cognitiveservices-search-newssearch) for the [News Search API](https://azure.microsoft.com/services/cognitive-services/bing-news-search-api/) @@ -85,6 +86,7 @@ We provide several meta-packages to help you install several packages at a time. 4. Set up the environment variable `TEXTANALYTICS_SUBSCRIPTION_KEY` with your key if you want to execute TextAnalytics tests. You might override too `TEXTANALYTICS_LOCATION` (westcentralus by default). 3. Set up the environment variable `AUTOSUGGEST_SUBSCRIPTION_KEY` with your key if you want to execute Autosuggest tests. 3. Set up the environment variable `CUSTOMSEARCH_SUBSCRIPTION_KEY` with your key if you want to execute CustomSearch tests. +3. Set up the environment variable `CUSTOMIMAGESEARCH_SUBSCRIPTION_KEY` with your key if you want to execute CustomImageSearch tests. 3. Set up the environment variable `ENTITYSEARCH_SUBSCRIPTION_KEY` with your key if you want to execute EntitySearch tests. 4. Set up the environment variable `IMAGESEARCH_SUBSCRIPTION_KEY` with your key if you want to execute ImageSearch tests. 4. Set up the environment variable `NEWSSEARCH_SUBSCRIPTION_KEY` with your key if you want to execute NewsSearch tests. diff --git a/requirements.txt b/requirements.txt index 44eafd5..625ef7c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ azure-cognitiveservices-language-luis azure-cognitiveservices-language-spellcheck azure-cognitiveservices-language-textanalytics azure-cognitiveservices-search-autosuggest +azure-cognitiveservices-search-customimagesearch azure-cognitiveservices-search-customsearch>=0.2.0 # sample won't work with previous versions azure-cognitiveservices-search-entitysearch azure-cognitiveservices-search-imagesearch diff --git a/samples/search/custom_image_search_samples.py b/samples/search/custom_image_search_samples.py new file mode 100644 index 0000000..bd948d2 --- /dev/null +++ b/samples/search/custom_image_search_samples.py @@ -0,0 +1,40 @@ +from azure.cognitiveservices.search.customimagesearch import CustomImageSearchAPI +from msrest.authentication import CognitiveServicesCredentials + +SUBSCRIPTION_KEY_ENV_NAME = "CUSTOMIMAGESEARCH_SUBSCRIPTION_KEY" + + +def custom_image_search_result_lookup(subscription_key): + """CustomImageSearchResultLookup. + + This will look up a single query (Xbox) and print out number of results, insights token, thumbnail url, content url for the first image result + """ + + client = CustomImageSearchAPI(credentials=CognitiveServicesCredentials(subscription_key)) + try: + image_results = client.custom_instance.image_search(query="Xbox", custom_config=1) + print("Searched for Query \" Xbox \"") + + # WebPages + if image_results.value: + # find the first web page + first_image_result = image_results.value[0] + + if first_image_result: + print("Image result count: {}".format(len(image_results.value))) + print("First image insights token: {}".format(first_image_result.image_insights_token)) + print("First image thumbnail url: {}".format(first_image_result.thumbnail_url)) + print("First image content url: {}".format(first_image_result.content_url)) + else: + print("Couldn't find image results!") + else: + print("Couldn't find image results!") + except Exception as e: + print("encountered exception. " + str(e)) + + +if __name__ == "__main__": + import sys, os.path + sys.path.append(os.path.abspath(os.path.join(__file__, "..", ".."))) + from tools import execute_samples + execute_samples(globals(), SUBSCRIPTION_KEY_ENV_NAME) \ No newline at end of file