Exemple #1
0
def get_models(event, context):
    try:
        res = aih_client.list_models()
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        # Create a JSON string
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)
Exemple #2
0
def polly_speak(event, context):
    try:
        text = json.loads(event["body"])["text"]
        res = aih_client.speak(text=text)
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)
Exemple #3
0
def stop_training(event, context):
    try:
        model_id = event["pathParameters"]["modelId"]
        res = aih_client.stop_training(model_id=model_id)
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)
Exemple #4
0
def detect_face(event, context):
    try:
        body = json.loads(event["body"])
        file = body["file"]
        binary_data_file = base64.b64decode(file)
        res = aih_client.detect_face(file_binary=binary_data_file)
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)
Exemple #5
0
def start_training(event, context):
    try:
        body = json.loads(event["body"]) if event["body"] else {}
        instance_type = body[
            "instance_type"] if 'instance_type' in body else None
        res = aih_client.train_model(instance_type=instance_type)
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        # Create a JSON string
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)
Exemple #6
0
def upload_faces(event, context):
    try:
        body = json.loads(event["body"])
        fullname = body["fullname"]
        files = body["files"]
        images = []
        for file in files:
            images.append(base64.b64decode(file))
        res = aih_client.upload_images(fullname=fullname, images=images)
        return aih.response(res)
    except Exception as e:
        exception_type = e.__class__.__name__
        exception_message = str(e)
        api_exception_obj = {
            "isError": True,
            "type": exception_type,
            "message": exception_message
        }
        # Create a JSON string
        api_exception_json = json.dumps(api_exception_obj)
        raise aih.LambdaException(api_exception_json)