1- from azure .cognitiveservices .search .imagesearch import ImageSearchAPI
1+ from azure .cognitiveservices .search .imagesearch import ImageSearchClient
22from azure .cognitiveservices .search .imagesearch .models import ImageType , ImageAspect , ImageInsightModule
33from msrest .authentication import CognitiveServicesCredentials
44
@@ -10,7 +10,10 @@ def image_search(subscription_key):
1010
1111 This will search images for (canadian rockies) then verify number of results and print out first image result, pivot suggestion, and query expansion.
1212 """
13- client = ImageSearchAPI (CognitiveServicesCredentials (subscription_key ))
13+ client = ImageSearchClient (
14+ endpoint = "https://api.cognitive.microsoft.com" ,
15+ credentials = CognitiveServicesCredentials (subscription_key )
16+ )
1417
1518 try :
1619 image_results = client .images .search (query = "canadian rockies" )
@@ -73,7 +76,10 @@ def image_search_with_filters(subscription_key):
7376
7477 This will search images for (studio ghibli), filtered for animated gifs and wide aspect, then verify number of results and print out insightsToken, thumbnail url and web url of first result.
7578 """
76- client = ImageSearchAPI (CognitiveServicesCredentials (subscription_key ))
79+ client = ImageSearchClient (
80+ endpoint = "https://api.cognitive.microsoft.com" ,
81+ credentials = CognitiveServicesCredentials (subscription_key )
82+ )
7783
7884 try :
7985 image_results = client .images .search (
@@ -104,7 +110,10 @@ def image_trending(subscription_key):
104110
105111 This will search for trending images then verify categories and tiles.
106112 """
107- client = ImageSearchAPI (CognitiveServicesCredentials (subscription_key ))
113+ client = ImageSearchClient (
114+ endpoint = "https://api.cognitive.microsoft.com" ,
115+ credentials = CognitiveServicesCredentials (subscription_key )
116+ )
108117
109118 try :
110119 trending_result = client .images .trending ()
@@ -136,7 +145,10 @@ def image_detail(subscription_key):
136145
137146 This will search images for (degas) and then search for image details of the first image.
138147 """
139- client = ImageSearchAPI (CognitiveServicesCredentials (subscription_key ))
148+ client = ImageSearchClient (
149+ endpoint = "https://api.cognitive.microsoft.com" ,
150+ credentials = CognitiveServicesCredentials (subscription_key )
151+ )
140152
141153 try :
142154 image_results = client .images .search (query = "degas" )
@@ -227,8 +239,7 @@ def image_detail(subscription_key):
227239
228240
229241if __name__ == "__main__" :
230- import sys
231- import os .path
232- sys .path .append (os .path .abspath (os .path .join (__file__ , ".." , ".." )))
233- from tools import execute_samples
242+ import sys , os .path
243+ sys .path .append (os .path .abspath (os .path .join (__file__ , ".." , ".." )))
244+ from samples .tools import execute_samples
234245 execute_samples (globals (), SUBSCRIPTION_KEY_ENV_NAME )
0 commit comments