You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
778 B
Python
27 lines
778 B
Python
import json
|
|
import base64
|
|
from PIL import Image
|
|
import io
|
|
from model_handler import ModelHandler
|
|
|
|
def init_context(context):
|
|
context.logger.info("Init context... 0%")
|
|
|
|
model = ModelHandler()
|
|
setattr(context.user_data, 'model', model)
|
|
|
|
context.logger.info("Init context...100%")
|
|
|
|
def handler(context, event):
|
|
context.logger.info("call handler")
|
|
data = event.body
|
|
points = data["pos_points"]
|
|
buf = io.BytesIO(base64.b64decode(data["image"].encode('utf-8')))
|
|
image = Image.open(buf)
|
|
|
|
polygon = context.user_data.model.handle(image, points)
|
|
return context.Response(body=json.dumps(polygon),
|
|
headers={},
|
|
content_type='application/json',
|
|
status_code=200)
|