File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ from azure .cognitiveservices .search .imagesearch import ImageSearchAPI
2+ from azure .cognitiveservices .search .imagesearch .models import ImageType , ImageAspect , ImageInsightModule
3+ from msrest .authentication import CognitiveServicesCredentials
4+
5+ subscription_key = "Enter your key here"
6+ search_term = "canadian rockies"
7+
8+ """
9+ This application will search images on the web and print out first image result
10+ """
11+ client = ImageSearchAPI (CognitiveServicesCredentials (subscription_key ))
12+
13+ try :
14+ image_results = client .images .search (query = "canadian rockies" )
15+ print ("Searching the web for images of \" canadian rockies\" " )
16+
17+ # Image results
18+ if image_results .value :
19+ first_image_result = image_results .value [0 ]
20+ print ("Total number of images returned: {}" .format (len (image_results .value )))
21+ print ("First image thumbnail url: {}" .format (first_image_result .thumbnail_url ))
22+ print ("First image content url: {}" .format (first_image_result .content_url ))
23+ else :
24+ print ("Couldn't find image results!" )
25+
26+ except Exception as err :
27+ print ("Encountered exception. {}" .format (err ))
You can’t perform that action at this time.
0 commit comments