From ad249a8c19e70d1444859d1241c1f938784f8f83 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 29 Dec 2023 14:24:52 +0700 Subject: [PATCH] Update: more logging for model performance --- .../fwd_api/celery_worker/process_result_tasks.py | 13 ++++++------- cope2n-api/fwd_api/models/SubscriptionRequest.py | 2 +- cope2n-api/fwd_api/utils/process.py | 2 +- deploy_images.py | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cope2n-api/fwd_api/celery_worker/process_result_tasks.py b/cope2n-api/fwd_api/celery_worker/process_result_tasks.py index 946ad81..9277961 100755 --- a/cope2n-api/fwd_api/celery_worker/process_result_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_result_tasks.py @@ -20,12 +20,12 @@ def aggregate_result(results): doc_types = [] for index, result in results.items(): index = int(index) - doc_type = result["metadata"]["doc_type"] + doc_type = result.get("metadata", {}).get("doc_type", "all") doc_types.append(doc_type) sorted_results[index] = ((doc_type, result)) des_result = deepcopy(list(results.values()))[0] - des_result.pop("metadata") + des_result.pop("metadata", None) des_result["content"]["total_pages"] = 0 des_result["content"]["ocr_num_pages"] = 0 des_result["content"]["document"][0]["end_page"] = 0 @@ -162,15 +162,14 @@ def process_invoice_sbt_result(rq_id, result, metadata): ai_inference_profile = {} doc_type_string = "" for idx, result in results.items(): - ai_inference_profile["{doc_type}_{idx}".format(doc_type=result["metadata"]["doc_type"], idx=result["metadata"]["index_in_request"])] = result["metadata"]["ai_inference_profile"] - doc_type_string += "{},".format(result["metadata"]["doc_type"]) + ai_inference_profile["{doc_type}_{idx}".format(doc_type=result.get("metadata", {}).get("doc_type", "all"), idx=result.get("metadata", {}).get("index_in_request", 0))] = result.get("metadata", {}).get("ai_inference_profile", {}) + doc_type_string += "{},".format(result.get("metadata", {}).get("doc_type", "all")) doc_type_string = doc_type_string[:-1] rq.ai_inference_profile = ai_inference_profile rq.doc_type = doc_type_string - rq.ai_inference_start_time = result["metadata"]["ai_inference_start_time"] # advancing the last result - rq.preprocessing_time = result["metadata"]["preprocessing_time"] # advancing the last result + rq.ai_inference_start_time = result.get("metadata", {}).get("ai_inference_start_time", -1) # advancing the last result + rq.preprocessing_time = result.get("metadata", {}).get("preprocessing_time", 0) # advancing the last result rq.ai_inference_time = time.time() - rq.ai_inference_start_time - rq.save() else: diff --git a/cope2n-api/fwd_api/models/SubscriptionRequest.py b/cope2n-api/fwd_api/models/SubscriptionRequest.py index a6c90a8..a852104 100755 --- a/cope2n-api/fwd_api/models/SubscriptionRequest.py +++ b/cope2n-api/fwd_api/models/SubscriptionRequest.py @@ -21,7 +21,7 @@ class SubscriptionRequest(models.Model): is_test_request = models.BooleanField(default=False) S3_uploaded = models.BooleanField(default=False) - ai_inference_profile=models.JSONField(null=True) + ai_inference_profile = models.JSONField(null=True) preprocessing_time = models.FloatField(default=-1) ai_inference_start_time = models.FloatField(default=0) ai_inference_time = models.FloatField(default=0) diff --git a/cope2n-api/fwd_api/utils/process.py b/cope2n-api/fwd_api/utils/process.py index 20f9bb7..6b6e43b 100644 --- a/cope2n-api/fwd_api/utils/process.py +++ b/cope2n-api/fwd_api/utils/process.py @@ -307,7 +307,7 @@ def token_value(token_type): return 1 # Basic OCR -def send_to_queue2(rq_id, sub_id, file_url, user_id, typez, metadata): +def send_to_queue2(rq_id, sub_id, file_url, user_id, typez, metadata={}): try: if typez == ProcessType.ID_CARD.value: c_connector.process_id( diff --git a/deploy_images.py b/deploy_images.py index 242016e..bf99177 100644 --- a/deploy_images.py +++ b/deploy_images.py @@ -79,7 +79,7 @@ def deploy(): # Define the variable tag = str(random_hash()[:8]) now = datetime.now() - tag = tag + "_" + str(now.strftime("%d%m%y%H%M%S")) + tag = str(now.strftime("%Y%m%d%H%M%S")) + "_" + tag # tag = "4cae5134_261223123256" print(tag)