def get_summary()

in src/lambda/meaningful-conversations-lex-lambda.py [0:0]


def get_summary(intent_request):
    # Declare variables and get handle to the S3 bucket containing the Textract output
    session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
    
    i = 0
    qty = 0
    
    for file in input_bucket.objects.all():
        i += 1
        selected_phrases = ""
        input_bucket_text_file = s3.Object(bucket, file.key)
        text_file_contents = str(input_bucket_text_file.get()['Body'].read().decode('utf-8'))
        
        #Comprehend Entity Detection
        detected_entities = comprehend.detect_entities(
        Text=text_file_contents,
        LanguageCode="en"
        )
        print(detected_entities)
        
        selected_entity_types = ["ORGANIZATION", "OTHER", "DATE", "QUANTITY", "LOCATION"]
        # Let's get the billing summary across invoices
        for x in detected_entities['Entities']:
            if x['Type'] == "OTHER" and x['EndOffset'] < 40:
                nr = x['Text']
            if x['Type'] == "QUANTITY" and x['EndOffset'] > 337 and x['EndOffset'] <= 350:
                qty = round((qty + float(x['Text'])), 2)
    return close(
        session_attributes,
        'Fulfilled',
        {
            'contentType': 'PlainText',
            'content': 'I reviewed your input documents and found {} invoices with invoice numbers {} totaling ${}. I can get you invoice details or invoice notes. Simply type your request'.format(i, nr, str(qty))
        }
    )