import boto3
import os

region = os.environ['REGION']
endpoint = os.environ['ENDPOINT']
threshold = os.environ['THRESHOLD']

comprehend_client = boto3.client(service_name='comprehend', region_name=region, use_ssl=True)

#getting comprehend tag
def classify_document(content):
    try:
        response = comprehend_client.classify_document(Text=content,EndpointArn=endpoint)
        p = response['Classes'][0]['Name']
        score = response['Classes'][0]['Score']
        print(f"Message:{content}, Score:{score}, Prediction:{p}")
        response = {}
        response['utterance']=content
        response['prediction']=p
        response['score'] = score
        category = ''
        if float(score) > float(threshold):
            category = p
        else:
            category = 'OTHERS'
        return category
    except Exception as e: 
        print("Exception")
        print(e)