Skip to content

Commit a32001c

Browse files
authored
Merge pull request #33 from iscai-msft/image_search
updated image search samples
2 parents 705f0db + e874fff commit a32001c

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,3 @@ ENV/
103103
# idea
104104
.idea/
105105

106-
#DS store
107-
.DS_Store

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ azure-cognitiveservices-language-spellcheck
44
azure-cognitiveservices-language-textanalytics>=0.2.0 # sample won't work with previous versions
55
azure-cognitiveservices-search-autosuggest
66
azure-cognitiveservices-search-customsearch
7-
azure-cognitiveservices-search-entitysearch>=1.0
8-
azure-cognitiveservices-search-customimagesearch
9-
azure-cognitiveservices-search-imagesearch
7+
azure-cognitiveservices-search-entitysearch
8+
azure-cognitiveservices-search-imagesearch>=1.0
109
azure-cognitiveservices-search-newssearch
1110
azure-cognitiveservices-search-videosearch
1211
azure-cognitiveservices-search-visualsearch>=0.2.0 # sample won't work with previous versions

samples/search/image_search_samples.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
1+
from azure.cognitiveservices.search.imagesearch import ImageSearchClient
22
from azure.cognitiveservices.search.imagesearch.models import ImageType, ImageAspect, ImageInsightModule
33
from 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

229241
if __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

Comments
 (0)