switch logger & only return 1 value in process_request()
This commit is contained in:
parent
734f530231
commit
41d4934cc1
28
src/serve.py
28
src/serve.py
@ -2,6 +2,7 @@ import gzip
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from image_prediction.config import Config
|
||||
from image_prediction.locations import CONFIG_FILE
|
||||
@ -15,9 +16,21 @@ from pyinfra.storage.storage import get_storage
|
||||
PYINFRA_CONFIG = config.get_config()
|
||||
IMAGE_CONFIG = Config(CONFIG_FILE)
|
||||
|
||||
logging.getLogger().addHandler(logging.StreamHandler())
|
||||
logger = logging.getLogger("main")
|
||||
logger.setLevel(PYINFRA_CONFIG.logging_level_root)
|
||||
# logging.getLogger().addHandler(logging.StreamHandler())
|
||||
# logger = logging.getLogger("main")
|
||||
# logger.setLevel(PYINFRA_CONFIG.logging_level_root)
|
||||
|
||||
LOG_FORMAT = "%(asctime)s [%(levelname)s] - [%(filename)s -> %(funcName)s() -> %(lineno)s] : %(message)s"
|
||||
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel("DEBUG")
|
||||
|
||||
stream_handler = logging.StreamHandler(sys.stdout)
|
||||
stream_handler_format = logging.Formatter(LOG_FORMAT, datefmt=DATE_FORMAT)
|
||||
stream_handler.setFormatter(stream_handler_format)
|
||||
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
|
||||
# A component of the callback (probably tensorflow) does not release allocated memory (see RED-4206).
|
||||
@ -39,7 +52,7 @@ def process_request(request_message):
|
||||
pipeline = load_pipeline(verbose=IMAGE_CONFIG.service.verbose, batch_size=IMAGE_CONFIG.service.batch_size)
|
||||
|
||||
if storage.exists(bucket, target_file_name):
|
||||
should_publish_result = True
|
||||
# should_publish_result = True
|
||||
object_bytes = storage.get_object(bucket, target_file_name)
|
||||
object_bytes = gzip.decompress(object_bytes)
|
||||
classifications = list(pipeline(pdf=object_bytes))
|
||||
@ -55,10 +68,11 @@ def process_request(request_message):
|
||||
result = {**request_message, "data": classifications, "dataCV": classifications_cv}
|
||||
storage_bytes = gzip.compress(json.dumps(result).encode("utf-8"))
|
||||
storage.put_object(bucket, response_file_name, storage_bytes)
|
||||
else:
|
||||
should_publish_result = False
|
||||
|
||||
return should_publish_result, {"dossierId": dossier_id, "fileId": file_id}
|
||||
return {"dossierId": dossier_id, "fileId": file_id}
|
||||
# else:
|
||||
# should_publish_result = False
|
||||
# return None
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user