Fix: logging file name for AI service

This commit is contained in:
TannedCung 2024-06-06 14:08:10 +07:00
parent 4c075aea69
commit 25245aa770

View File

@ -4,6 +4,7 @@ import urllib
import random import random
import numpy as np import numpy as np
from pathlib import Path from pathlib import Path
import urllib.parse
import uuid import uuid
from copy import deepcopy from copy import deepcopy
import sys, os import sys, os
@ -33,10 +34,13 @@ def sbt_predict(image_url, engine, metadata={}) -> None:
img = cv2.imdecode(arr, -1) img = cv2.imdecode(arr, -1)
save_dir = "./tmp_results" save_dir = "./tmp_results"
parsed_url = urllib.parse.urlparse(image_url)
query_params = urllib.parse.parse_qs(parsed_url.query)
file_name = query_params['file_name'][0]
os.makedirs(save_dir, exist_ok=True) os.makedirs(save_dir, exist_ok=True)
# image_path = os.path.join(save_dir, f"{image_url}.jpg") # image_path = os.path.join(save_dir, f"{image_url}.jpg")
os.makedirs(save_dir, exist_ok = True) os.makedirs(save_dir, exist_ok = True)
tmp_image_path = os.path.join(save_dir, f"{uuid.uuid4()}.jpg") tmp_image_path = os.path.join(save_dir, file_name)
cv2.imwrite(tmp_image_path, img) cv2.imwrite(tmp_image_path, img)
extra_params = {'sub': metadata.get("subsidiary", None)} # example of 'AU' extra_params = {'sub': metadata.get("subsidiary", None)} # example of 'AU'
outputs = process_img(img=tmp_image_path, outputs = process_img(img=tmp_image_path,