Exemple #1
0
# ----------------------------------------------------------------------

option_parser = argparse.ArgumentParser(add_help=False)

option_parser.add_argument('path', help='path or url to image')

args = option_parser.parse_args()

# ----------------------------------------------------------------------

SERVICE = "Computer Vision"
KEY_FILE = os.path.join(os.getcwd(), "private.txt")

# Request subscription key and endpoint from user.

subscription_key, endpoint = azkey(KEY_FILE, SERVICE, verbose=False)

# Set credentials.

credentials = CognitiveServicesCredentials(subscription_key)

# Create client.

client = ComputerVisionClient(endpoint, credentials)

# Check the URL supplied or path exists and is an image.

# Send provided image (url or path) to azure to extract text.

# ----------------------------------------------------------------------
# URL or path
Exemple #2
0
    help='keep original text in output')

args = option_parser.parse_args()

lang = args.lang
fr   = args.source
to   = args.to if args.to != None else 'latn'

# ----------------------------------------------------------------------
# Request subscription key and endpoint from user.
# ----------------------------------------------------------------------

SERVICE = "Text Translator"
KEY_FILE  = os.path.join(os.getcwd(), "private.txt")

key, endpoint = azkey(KEY_FILE, SERVICE, verbose=False, baseurl=True)

# ----------------------------------------------------------------------
# Build the REST API URLs.
# ----------------------------------------------------------------------

path     = '/transliterate?api-version=3.0'
url = endpoint + path

headers  = {
    'Ocp-Apim-Subscription-Key': key,
    'Content-type': 'application/json',
    'X-ClientTraceId': str(uuid.uuid4())
}  

# ------------------------------------------------------------------------
Exemple #3
0
from textwrap import fill

# Constants.

SERVICE = "Anomaly Detector"
KEY_FILE = os.path.join(os.getcwd(), "private.txt")
DATA_FILE = "request.json"

# URLs for anomaly detection with the Anomaly Detector API.

BATCH_URL = "anomalydetector/v1.0/timeseries/entire/detect"
LATEST_URL = "anomalydetector/v1.0/timeseries/last/detect"

# Request subscription key and endpoint from user.

subscription_key, endpoint = azkey(KEY_FILE, SERVICE)

mlask()

# Read data from a json time series from file.

file_handler = open(DATA_FILE)
data = json.load(file_handler)
series = data['series']
sensitivity = data['sensitivity']

mlcat("Sample Data",
      """\
The dataset contains {} {} observations recording the number of requests
received for a particular service. It is quite a small dataset used to 
illustrate the concepts. Below we see sample observations from the dataset.
Exemple #4
0
parser = argparse.ArgumentParser(prog='detect',
                                 parents=[option_parser],
                                 description='Detect faces in an image.')

parser.add_argument('path',
                    type=str,
                    help='path or URL of a photo where faces will be detected')

args = parser.parse_args()

# ----------------------------------------------------------------------
# Setup
# ----------------------------------------------------------------------

img_url = args.path if is_url(args.path) else get_abspath(args.path)
face_attrs = ['age', 'gender', 'glasses', 'emotion', 'occlusion']
subscription_key, endpoint = args.key, args.endpoint

# ----------------------------------------------------------------------
# Call face API to detect and describe faces
# ----------------------------------------------------------------------

if not subscription_key or not endpoint:  # Request subscription key and endpoint from user.
    subscription_key, endpoint = get_face_api_key_endpoint(
        *azkey(args.key_file, SERVICE, verbose=False))

credentials = CognitiveServicesCredentials(subscription_key)  # Set credentials
client = FaceClient(endpoint, credentials)  # Setup Azure face API client
faces = azface_detect(client, img_url, return_face_attributes=face_attrs)
print_detection_results(faces)
Exemple #5
0
    azface_detect,
    azface_similar,
    get_face_api_key_endpoint,
    list_files,
    show_detection_results,
    show_similar_results,
)

# ----------------------------------------------------------------------
# Setup
# ----------------------------------------------------------------------

# Request subscription key and endpoint from user.

subscription_key, endpoint = get_face_api_key_endpoint(
    *azkey(KEY_FILE, SERVICE))

# Set credentials.

credentials = CognitiveServicesCredentials(subscription_key)

# Create client.

client = FaceClient(endpoint, credentials)  # Setup Azure face API client

# ----------------------------------------------------------------------
# Face detection
# ----------------------------------------------------------------------

# Setup
Exemple #6
0
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision import VERSION as azver
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.computervision.models import TextRecognitionMode
from azure.cognitiveservices.vision.computervision.models import TextOperationStatusCodes

# ----------------------------------------------------------------------
# Request subscription key and endpoint from user.
# ----------------------------------------------------------------------

SERVICE   = "Computer Vision"
KEY_FILE  = os.path.join(os.getcwd(), "private.txt")

key, endpoint = azkey(KEY_FILE, SERVICE)

mlask()

# Set credentials.

credentials = CognitiveServicesCredentials(key)

# Create client.

client = ComputerVisionClient(endpoint, credentials)

url0 = "https://upload.wikimedia.org/"
url1 = "wikipedia/commons/thumb/1/12/Broadway_and_Times_Square_by_night.jpg/"
url2 = "450px-Broadway_and_Times_Square_by_night.jpg"
url  = url0 + url1 + url2