Add: Try for filename exrtaction

This commit is contained in:
TannedCung 2024-06-06 14:10:38 +07:00
parent 25245aa770
commit e4b3d1079f

View File

@ -34,9 +34,14 @@ 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) try:
query_params = urllib.parse.parse_qs(parsed_url.query)
file_name = query_params['file_name'][0] parsed_url = urllib.parse.urlparse(image_url)
query_params = urllib.parse.parse_qs(parsed_url.query)
file_name = query_params['file_name'][0]
except Exception as e:
print(f"[ERROR]: Error extracting file name from url: {image_url}")
file_name = f"{uuid.uuid4()}.jpg"
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)