Skip to content

Commit

Permalink
update to remove key
Browse files Browse the repository at this point in the history
  • Loading branch information
sdgilley committed Aug 22, 2024
1 parent 1ad1e2a commit cea6fce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
7 changes: 1 addition & 6 deletions auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,5 @@ def get_auth_response(repo_name):
print("Please set COMPUTER_VISION_ENDPOINT environment variable")
sys.exit()

try:
subscription_key = os.environ["COMPUTER_VISION_SUBSCRIPTION_KEY"]
except:
print("Please set COMPUTER_VISION_SUBSCRIPTION_KEY environment variable")
sys.exit()
# *** End of Authenticate - you're now ready to run the script.
return (endpoint, subscription_key, repo)
return (endpoint, repo)
16 changes: 8 additions & 8 deletions search-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

# *** PUT YOUR DETAILS HERE *****
# what to search for - can be one or more terms
find_text = ["Open project in VS Code"] # Text to find in the images.
find_text = ["Data Factory"] # Text to find in the images.
case_sensitive = True # True or False
csv_fn = "open-project.csv" # Put results in this file
csv_fn = "fabric-switcher.csv" # Put results in this file
# where to search
repo_name = "MicrosoftDocs/azure-docs" # repo to search
branch = "main"
media_path = "articles/ai-studio/media" # point to the media dir you want to search
# or here's fabric:
# repo_name = "MicrosoftDocs/fabric-docs"
# repo_name = "MicrosoftDocs/azure-docs" # repo to search
# branch = "main"
# media_path = 'docs/data-science/media'
# media_path = "articles/machine-learning/v1/media" # point to the media dir you want to search
# or here's fabric:
repo_name = "MicrosoftDocs/fabric-docs"
branch = "main"
media_path = 'docs/data-science/media'

# *** END OF SEARCH DETAILS ***

Expand Down
31 changes: 26 additions & 5 deletions search_for_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def search_for_images(find_text, case_sensitive, csv_fn, repo_name, branch, medi

from azure.ai.vision.imageanalysis import ImageAnalysisClient
from azure.ai.vision.imageanalysis.models import VisualFeatures
from azure.core.credentials import AzureKeyCredential
from azure.identity import DefaultAzureCredential
import os
import re

Expand All @@ -36,10 +36,11 @@ def search_for_images(find_text, case_sensitive, csv_fn, repo_name, branch, medi
from auth import get_auth_response

# get vision tokens and the repo
endpoint, key, repo = get_auth_response(repo_name)

endpoint, repo = get_auth_response(repo_name)
cred = DefaultAzureCredential(exclude_interactive_browser_credential=False)
# Create an Image Analysis client
client = ImageAnalysisClient(endpoint=endpoint, credential=AzureKeyCredential(key))
client = ImageAnalysisClient(endpoint=endpoint, credential=cred)


# open csv file to store results
import csv
Expand Down Expand Up @@ -145,4 +146,24 @@ def search_for_images(find_text, case_sensitive, csv_fn, repo_name, branch, medi
print(f" See results in {csv_fn} and {md_fn}")
print(f" Execution time: {elapsed} minutes")

# results are saved in the csv and md files
# results are saved in the csv and md file
# test the function
if __name__ == "__main__":
# *** PUT YOUR DETAILS HERE *****
# what to search for - can be one or more terms
find_text = ["Data Factory"] # Text to find in the images.
case_sensitive = True # True or False
csv_fn = "fabric-switcher.csv" # Put results in this file
# where to search
# repo_name = "MicrosoftDocs/azure-docs" # repo to search
# branch = "main"
# media_path = "articles/machine-learning/v1/media" # point to the media dir you want to search
# or here's fabric:
repo_name = "MicrosoftDocs/fabric-docs"
branch = "main"
media_path = 'docs/data-science/media'

# *** END OF SEARCH DETAILS ***

# search for the images and create csv and md files with the results
search_for_images(find_text, case_sensitive, csv_fn, repo_name, branch, media_path)
12 changes: 9 additions & 3 deletions test/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
print("Missing environment variable 'VISION_ENDPOINT' or 'VISION_KEY'")
print("Set them before running this sample.")
exit()
print(endpoint)
cred = AzureKeyCredential(key)

# # this DOES work...
# from azure.identity import InteractiveBrowserCredential
# cred = InteractiveBrowserCredential()
from azure.identity import DefaultAzureCredential
cred = DefaultAzureCredential(exclude_interactive_browser_credential=False)
# Create an Image Analysis client
client = ImageAnalysisClient(endpoint=endpoint, credential=AzureKeyCredential(key))
client = ImageAnalysisClient(endpoint=endpoint, credential=cred)

# Get a text for this image. This will be a synchronously (blocking) call.
result = client.analyze(
result = client.analyze_from_url(
image_url="https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png",
visual_features=[VisualFeatures.READ],
)
print(result)
print("Image analysis results:")

# Print text (OCR) analysis results to the console
Expand Down

0 comments on commit cea6fce

Please sign in to comment.