From ca4f1a613103baa0c8a2888c13e9722b4e90c510 Mon Sep 17 00:00:00 2001 From: jaydeepsingh25 Date: Sun, 14 Jul 2024 19:51:47 -0700 Subject: [PATCH] fix: logging fixes --- preprocessors/autour/autour.py | 2 +- preprocessors/collage-detector/detect.py | 1 + .../content-categoriser/categoriser.py | 1 + .../depth-map-gen/depth-map-generator.py | 1 + preprocessors/graphic-tagger/azure_api.py | 1 + preprocessors/grouping/grouping.py | 1 + preprocessors/ner/ner.py | 1 + .../object-depth-calculator.py | 38 ++++++++++--------- .../object-detection-azure/objdetect.py | 1 + preprocessors/ocr/ocr.py | 1 + preprocessors/sorting/sorting.py | 1 + preprocessors/yolov8/detect.py | 1 + 12 files changed, 31 insertions(+), 19 deletions(-) diff --git a/preprocessors/autour/autour.py b/preprocessors/autour/autour.py index 698ff9894..24201cc83 100644 --- a/preprocessors/autour/autour.py +++ b/preprocessors/autour/autour.py @@ -23,7 +23,7 @@ from flask import Flask, request, jsonify app = Flask(__name__) - +logging.basicConfig(level=logging.DEBUG) @app.route('/preprocessor', methods=['POST', 'GET']) def get_map_data(): diff --git a/preprocessors/collage-detector/detect.py b/preprocessors/collage-detector/detect.py index 3b24fbe9c..eb3303f3d 100644 --- a/preprocessors/collage-detector/detect.py +++ b/preprocessors/collage-detector/detect.py @@ -25,6 +25,7 @@ import time app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) @app.route('/preprocessor', methods=['POST']) diff --git a/preprocessors/content-categoriser/categoriser.py b/preprocessors/content-categoriser/categoriser.py index aadc6f5bc..99b428ad2 100644 --- a/preprocessors/content-categoriser/categoriser.py +++ b/preprocessors/content-categoriser/categoriser.py @@ -27,6 +27,7 @@ import base64 app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) class Net(pl.LightningModule): diff --git a/preprocessors/depth-map-gen/depth-map-generator.py b/preprocessors/depth-map-gen/depth-map-generator.py index 674267fda..c6426b864 100644 --- a/preprocessors/depth-map-gen/depth-map-generator.py +++ b/preprocessors/depth-map-gen/depth-map-generator.py @@ -32,6 +32,7 @@ from lib.multi_depth_model_woauxi import RelDepthModel app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) def parse_args(): diff --git a/preprocessors/graphic-tagger/azure_api.py b/preprocessors/graphic-tagger/azure_api.py index 7752c0920..e987628be 100644 --- a/preprocessors/graphic-tagger/azure_api.py +++ b/preprocessors/graphic-tagger/azure_api.py @@ -28,6 +28,7 @@ from flask import Flask, request, jsonify app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) # extract the required results from the API returned values diff --git a/preprocessors/grouping/grouping.py b/preprocessors/grouping/grouping.py index 5c9188c4e..19607311d 100644 --- a/preprocessors/grouping/grouping.py +++ b/preprocessors/grouping/grouping.py @@ -25,6 +25,7 @@ app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) def calculate_diagonal(x1, y1, x2, y2): diff --git a/preprocessors/ner/ner.py b/preprocessors/ner/ner.py index 38fab298d..3683b4614 100644 --- a/preprocessors/ner/ner.py +++ b/preprocessors/ner/ner.py @@ -33,6 +33,7 @@ nltk.download('punkt') app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) # using python's tmp file to store the image and context json dir_prefix = 'ner_' diff --git a/preprocessors/object-depth-calculator/object-depth-calculator.py b/preprocessors/object-depth-calculator/object-depth-calculator.py index 682154504..947f1db5e 100644 --- a/preprocessors/object-depth-calculator/object-depth-calculator.py +++ b/preprocessors/object-depth-calculator/object-depth-calculator.py @@ -21,13 +21,15 @@ import time import jsonschema import base64 +import logging app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) @app.route("/preprocessor", methods=['POST', ]) def objectdepth(): - app.logger.debug("Received request") + logging.debug("Received request") # load the schema with open('./schemas/preprocessors/object-depth-calculator.schema.json') \ as jsonfile: @@ -53,19 +55,19 @@ def objectdepth(): validator = jsonschema.Draft7Validator(first_schema, resolver=resolver) validator.validate(content) except jsonschema.exceptions.ValidationError as e: - app.logger.error(e) + logging.error(e) return jsonify("Invalid Preprocessor JSON format"), 400 # check for depth-map if ("ca.mcgill.a11y.image.preprocessor.depth-map-gen" not in content["preprocessors"]): - app.logger.info("Request does not contain a depth-map. Skipping...") + logging.info("Request does not contain a depth-map. Skipping...") return "", 204 # No content - app.logger.debug("passed depth-map check") + logging.debug("passed depth-map check") if ("ca.mcgill.a11y.image.preprocessor.objectDetection" not in content["preprocessors"]): - app.logger.info("Request does not contain objects. Skipping...") + logging.info("Request does not contain objects. Skipping...") return "", 204 # No content - app.logger.debug("passed objects check") + logging.debug("passed objects check") if "dimensions" in content: # If an existing graphic exists, often it is @@ -74,7 +76,7 @@ def objectdepth(): # developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Positions dimensions = content["dimensions"] else: - app.logger.debug("Dimensions are not defined") + logging.debug("Dimensions are not defined") response = { "request_uuid": content["request_uuid"], "timestamp": int(time.time()), @@ -85,9 +87,9 @@ def objectdepth(): schema, resolver=resolver) validator.validate(response) except jsonschema.exceptions.ValidationError as error: - app.logger.error(error) + logging.error(error) return jsonify("Invalid Preprocessor JSON format"), 500 - app.logger.debug("Sending response") + logging.debug("Sending response") return response request_uuid = content["request_uuid"] @@ -111,7 +113,7 @@ def objectdepth(): print(dimensions[0], dimensions[1]) obj_depth = [] - app.logger.debug("number of objects") + logging.debug("number of objects") if (len(objects) > 0): for i in range(len(objects)): x1 = int(objects[i]['dimensions'][0] * dimensions[0]) @@ -123,11 +125,11 @@ def objectdepth(): depth = np.nanmedian(depthcomp) if np.isnan(depth): - app.logger.error("NAN depth value") - app.logger.debug("Ojbect #") - app.logger.debug(str(i)) - app.logger.debug(str(x1)) - app.logger.debug(str(x2)) + logging.error("NAN depth value") + logging.debug("Ojbect #") + logging.debug(str(i)) + logging.debug(str(x1)) + logging.debug(str(x2)) depth = 1 dictionary = {"ID": objects[i]["ID"], @@ -140,7 +142,7 @@ def objectdepth(): validator = jsonschema.Draft7Validator(data_schema) validator.validate(obj_depth_output) except jsonschema.exceptions.ValidationError as e: - app.logger.error(e) + logging.error(e) return jsonify("Invalid Preprocessor JSON format"), 500 response = { "request_uuid": request_uuid, @@ -152,9 +154,9 @@ def objectdepth(): validator = jsonschema.Draft7Validator(schema, resolver=resolver) validator.validate(response) except jsonschema.exceptions.ValidationError as e: - app.logger.error(e) + logging.error(e) return jsonify("Invalid Preprocessor JSON format"), 500 - app.logger.debug("Sending response") + logging.debug("Sending response") return response diff --git a/preprocessors/object-detection-azure/objdetect.py b/preprocessors/object-detection-azure/objdetect.py index e842aec41..19894d837 100644 --- a/preprocessors/object-detection-azure/objdetect.py +++ b/preprocessors/object-detection-azure/objdetect.py @@ -25,6 +25,7 @@ from flask import Flask, request, jsonify app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) # load the schema with open('./schemas/preprocessors/object-detection.schema.json') \ diff --git a/preprocessors/ocr/ocr.py b/preprocessors/ocr/ocr.py index d856d7dd3..f477acbe8 100644 --- a/preprocessors/ocr/ocr.py +++ b/preprocessors/ocr/ocr.py @@ -33,6 +33,7 @@ ) app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) @app.route('/preprocessor', methods=['POST', 'GET']) diff --git a/preprocessors/sorting/sorting.py b/preprocessors/sorting/sorting.py index 59aa7ac3c..0ff97e9fa 100644 --- a/preprocessors/sorting/sorting.py +++ b/preprocessors/sorting/sorting.py @@ -23,6 +23,7 @@ app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) # this function determines the size of bounding box diff --git a/preprocessors/yolov8/detect.py b/preprocessors/yolov8/detect.py index fee9e15fd..62a491dee 100644 --- a/preprocessors/yolov8/detect.py +++ b/preprocessors/yolov8/detect.py @@ -36,6 +36,7 @@ os.environ['KMP_DUPLICATE_LIB_OK'] = 'True' app = Flask(__name__) +logging.basicConfig(level=logging.DEBUG) c_thres = 0.75