Skip to content

Commit dc1dadb

Browse files
committed
fixed image search samples
1 parent 81b6423 commit dc1dadb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ ENV/
9999

100100
# mypy
101101
.mypy_cache/
102+
103+
# idea
104+
.idea/

samples/search/image_search_samples.py

Lines changed: 17 additions & 5 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

@@ -9,7 +9,10 @@ def image_search(subscription_key):
99
1010
This will search images for (canadian rockies) then verify number of results and print out first image result, pivot suggestion, and query expansion.
1111
"""
12-
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
12+
client = ImageSearchClient(
13+
endpoint="https://api.cognitive.microsoft.com/bing/v7.0",
14+
credentials=CognitiveServicesCredentials(subscription_key)
15+
)
1316

1417
try:
1518
image_results = client.images.search(query="canadian rockies")
@@ -62,7 +65,10 @@ def image_search_with_filters(subscription_key):
6265
6366
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.
6467
"""
65-
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
68+
client = ImageSearchClient(
69+
endpoint="https://api.cognitive.microsoft.com/bing/v7.0",
70+
credentials=CognitiveServicesCredentials(subscription_key)
71+
)
6672

6773
try:
6874
image_results = client.images.search(
@@ -90,7 +96,10 @@ def image_trending(subscription_key):
9096
9197
This will search for trending images then verify categories and tiles.
9298
"""
93-
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
99+
client = ImageSearchClient(
100+
endpoint="https://api.cognitive.microsoft.com/bing/v7.0",
101+
credentials=CognitiveServicesCredentials(subscription_key)
102+
)
94103

95104
try:
96105
trending_result = client.images.trending()
@@ -120,7 +129,10 @@ def image_detail(subscription_key):
120129
121130
This will search images for (degas) and then search for image details of the first image.
122131
"""
123-
client = ImageSearchAPI(CognitiveServicesCredentials(subscription_key))
132+
client = ImageSearchClient(
133+
endpoint="https://api.cognitive.microsoft.com/bing/v7.0",
134+
credentials=CognitiveServicesCredentials(subscription_key)
135+
)
124136

125137
try:
126138
image_results = client.images.search(query="degas")

0 commit comments

Comments
 (0)