-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding new Bing Image Search quickstart sample (Azure-Samples#16)
* adding new Bing Image Search quickstart sample * updating sample
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI | ||
from msrest.authentication import CognitiveServicesCredentials | ||
|
||
subscription_key = "Enter your key here" | ||
search_term = "canadian rockies" | ||
|
||
""" | ||
This application will search images on the web with the Bing Image Search API and print out first image result. | ||
""" | ||
#create the image search client | ||
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key)) | ||
# send a search query to the Bing Image Search API | ||
image_results = client.images.search(query=search_term) | ||
print("Searching the web for images of: {}".format(search_term)) | ||
|
||
# Image results | ||
if image_results.value: | ||
first_image_result = image_results.value[0] | ||
print("Total number of images returned: {}".format(len(image_results.value))) | ||
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!") |