-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
33 lines (26 loc) · 843 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from logging import INFO
import boto3
from typing import Dict, Any
from tagger import Tagger
logger = logging.getLogger(__name__)
logger.setLevel(level=INFO)
logger.info('Downloading model from bucket')
s3 = boto3.resource('s3')
bucket_name = 'deep-lambda'
bucket = s3.Bucket('deep-lambda')
bucket.download_file('my_ner_tagger.pt', '/tmp/my_ner_tagger.pt')
logger.info('Successfully downloaded model from bucket')
tagger = Tagger('/tmp/my_ner_tagger.pt')
def lambda_handler(event: Dict[str, Any], _: Dict[str, str]) -> Dict[str, str]:
logger.info(f'Processing event: {event}')
text = event['body']
tag_result = tagger(text)
return {
'isBase64Encoded': False,
'statusCode': 200,
'headers': {
'content-type': 'application/json'
},
'body': tag_result
}