Last active
January 30, 2020 04:42
-
-
Save Jongbhin/61dfd35624ea16082e8cddc789c144be to your computer and use it in GitHub Desktop.
[get_score_handler_v2] #python #handler #pytorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetScoreHandler_v2(BaseHandler): | |
def __init__(self, *args, **kwargs): | |
super(GetScoreHandler_v2, self).__init__(*args, **kwargs) | |
self.model = CleanscoringModelV2API() | |
@gen.coroutine | |
def post(self, slug=None): | |
try: | |
request_json_data = json.loads(self.request.body) | |
results = yield self.get_score(request_json_data) | |
self.write(json.dumps(results)) | |
self.finish() | |
except Exception as ex: | |
self.handle_exception(ex) | |
@run_on_executor | |
def get_score(self, request_json_data): | |
try: | |
request_dict = self.model.daemon_utils.convert(request_json_data) | |
prod_no = request_dict.get('prod_no', None) | |
image_url = request_dict.get('image_url', None) | |
pil_image, img_size = self.model.daemon_utils.pil_image_load(image_url) | |
app_log.info(image_url) | |
cv2_image, _ = self.model.daemon_utils.image_load_and_resize(image_url, resize=False) | |
result = self.model.inference(pil_image, cv2_image) | |
app_log.info("image_url:" + request_dict['image_url'] + ", score:" + str(result)) | |
return self.model.daemon_utils.encode_result_to_json_v2_api([result, img_size, prod_no]) | |
except Exception as ex: | |
self.handle_exception(ex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment