SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 0 Java
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Amazon Lookout for Vision project code examples for using projects.
Examples are used in the service documentation:
https://docs.aws.amazon.com/lookout-for-vision/latest/developer-guide/.
2021-05-04 13:49:38 -07:00
Shows how to create and delete a project. Also, how to get information
about your projects.
"""
import logging
from botocore.exceptions import ClientError
from models import Models
logger = logging.getLogger(__name__)
# snippet-start:[python.example_code.lookoutvision.Projects]
class Projects:
# snippet-end:[python.example_code.lookoutvision.Projects]
"""
Provides example functions for creating, listing, and deleting Lookout for Vision
projects
"""
# snippet-start:[python.example_code.lookoutvision.CreateProject]
@staticmethod
def create_project(lookoutvision_client, project_name):
"""
Creates a new Lookout for Vision project.
:param lookoutvision_client: A Boto3 Lookout for Vision client.
:param project_name: The name for the new project.
:return project_arn: The ARN of the new project.
"""
try:
logger.info("Creating project: %s", project_name)
response = lookoutvision_client.create_project(ProjectName=project_name)
project_arn = response["ProjectMetadata"]["ProjectArn"]
logger.info("project ARN: %s", project_arn)
except ClientError:
logger.exception("Couldn't create project %s.", project_name)
raise
else:
return project_arn
# snippet-end:[python.example_code.lookoutvision.CreateProject]
# snippet-start:[python.example_code.lookoutvision.DeleteProject]
@staticmethod
def delete_project(lookoutvision_client, project_name):
"""
Deletes a Lookout for Vision Model
:param lookoutvision_client: A Boto3 Lookout for Vision client.
:param project_name: The name of the project that you want to delete.
"""
try:
logger.info("Deleting project: %s", project_name)
response = lookoutvision_client.delete_project(ProjectName=project_name)
logger.info("Deleted project ARN: %s ", response["ProjectArn"])
except ClientError as err:
logger.exception("Couldn't delete project %s.", project_name)
raise
# snippet-end:[python.example_code.lookoutvision.DeleteProject]
# snippet-start:[python.example_code.lookoutvision.ListProjects]
@staticmethod
def list_projects(lookoutvision_client):
"""
2022-04-05 17:25:32 -07:00
Lists information about the projects that are in in your AWS account
and in the current AWS Region.
:param lookoutvision_client: A Boto3 Lookout for Vision client.
"""
try:
response = lookoutvision_client.list_projects()
for project in response["Projects"]:
print("Project: " + project["ProjectName"])
print("\tARN: " + project["ProjectArn"])
print("\tCreated: " + str(["CreationTimestamp"]))
print("Datasets")
project_description = lookoutvision_client.describe_project(
ProjectName=project["ProjectName"]
)
2021-05-04 13:49:38 -07:00
if not project_description["ProjectDescription"]["Datasets"]:
print("\tNo datasets")
else:
for dataset in project_description["ProjectDescription"][
"Datasets"
]:
2021-05-04 13:49:38 -07:00
print(f"\ttype: {dataset['DatasetType']}")
print(f"\tStatus: {dataset['StatusMessage']}")
print("Models")
response_models = lookoutvision_client.list_models(
ProjectName=project["ProjectName"]
)
2021-05-04 13:49:38 -07:00
if not response_models["Models"]:
print("\tNo models")
else:
for model in response_models["Models"]:
Models.describe_model(
lookoutvision_client,
project["ProjectName"],
model["ModelVersion"],
)
print("------------------------------------------------------------\n")
print("Done!")
except ClientError:
logger.exception("Problem listing projects.")
raise
# snippet-end:[python.example_code.lookoutvision.ListProjects]