Skip to content

Commit

Permalink
fix: logging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeepsingh25 committed Jul 15, 2024
1 parent fc0437d commit ca4f1a6
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion preprocessors/autour/autour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions preprocessors/collage-detector/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import time

app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)


@app.route('/preprocessor', methods=['POST'])
Expand Down
1 change: 1 addition & 0 deletions preprocessors/content-categoriser/categoriser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import base64

app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)


class Net(pl.LightningModule):
Expand Down
1 change: 1 addition & 0 deletions preprocessors/depth-map-gen/depth-map-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from lib.multi_depth_model_woauxi import RelDepthModel

app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)


def parse_args():
Expand Down
1 change: 1 addition & 0 deletions preprocessors/graphic-tagger/azure_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions preprocessors/grouping/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)


def calculate_diagonal(x1, y1, x2, y2):
Expand Down
1 change: 1 addition & 0 deletions preprocessors/ner/ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_'
Expand Down
38 changes: 20 additions & 18 deletions preprocessors/object-depth-calculator/object-depth-calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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()),
Expand All @@ -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"]
Expand All @@ -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])
Expand All @@ -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"],
Expand All @@ -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,
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions preprocessors/object-detection-azure/objdetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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') \
Expand Down
1 change: 1 addition & 0 deletions preprocessors/ocr/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)

app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)


@app.route('/preprocessor', methods=['POST', 'GET'])
Expand Down
1 change: 1 addition & 0 deletions preprocessors/sorting/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)

# this function determines the size of bounding box

Expand Down
1 change: 1 addition & 0 deletions preprocessors/yolov8/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)

c_thres = 0.75

Expand Down

0 comments on commit ca4f1a6

Please sign in to comment.