Update handler.py
Browse files- handler.py +1 -11
handler.py
CHANGED
|
@@ -102,35 +102,25 @@ def check_safety(x_image):
|
|
| 102 |
|
| 103 |
def upload_image(image_base64):
|
| 104 |
try:
|
| 105 |
-
decode_time = TimeMesurer()
|
| 106 |
-
|
| 107 |
image_bytes = base64.b64decode(image_base64)
|
| 108 |
pil_image = Image.open(BytesIO(image_bytes))
|
| 109 |
|
| 110 |
-
decode_time.log_time_end('decode_time');
|
| 111 |
-
|
| 112 |
-
check_safety_time = TimeMesurer()
|
| 113 |
# check safety of the image
|
| 114 |
is_nsfw = check_safety(pil_image)
|
| 115 |
-
check_safety_time.log_time_end('check_safety_time');
|
| 116 |
|
| 117 |
postfix = ''
|
| 118 |
if is_nsfw:
|
| 119 |
postfix = '_nsfw'
|
| 120 |
|
| 121 |
-
webp_time = TimeMesurer()
|
| 122 |
webp_image = BytesIO()
|
| 123 |
pil_image.save(webp_image, format="WebP", lossless=convert_is_lossless, quality=convert_quality, method=convert_method)
|
| 124 |
webp_image.seek(0) # reset the BytesIO object to the beginning
|
| 125 |
-
webp_time.log_time_end('webp_time');
|
| 126 |
|
| 127 |
image_name = f'generated/{uuid.uuid4()}{postfix}.webp'
|
| 128 |
blob = bucket.blob(image_name)
|
| 129 |
|
| 130 |
-
upload_time = TimeMesurer()
|
| 131 |
blob.upload_from_file(webp_image, content_type='image/webp')
|
| 132 |
blob.make_public()
|
| 133 |
-
upload_time.log_time_end('total_upload_time');
|
| 134 |
|
| 135 |
return f'{images_base_url}/{image_name}'
|
| 136 |
except Exception as e:
|
|
@@ -202,7 +192,7 @@ def handler(event):
|
|
| 202 |
if images_field in result:
|
| 203 |
update_progress_status(job_id=job_id, progress_status="UPLOADING_IMAGES")
|
| 204 |
result[images_field] = upload_images_in_parallel(result[images_field])
|
| 205 |
-
upload_time.log_time_end("
|
| 206 |
|
| 207 |
if image_field in result:
|
| 208 |
update_progress_status(job_id=job_id, progress_status="UPLOADING_IMAGES")
|
|
|
|
| 102 |
|
| 103 |
def upload_image(image_base64):
|
| 104 |
try:
|
|
|
|
|
|
|
| 105 |
image_bytes = base64.b64decode(image_base64)
|
| 106 |
pil_image = Image.open(BytesIO(image_bytes))
|
| 107 |
|
|
|
|
|
|
|
|
|
|
| 108 |
# check safety of the image
|
| 109 |
is_nsfw = check_safety(pil_image)
|
|
|
|
| 110 |
|
| 111 |
postfix = ''
|
| 112 |
if is_nsfw:
|
| 113 |
postfix = '_nsfw'
|
| 114 |
|
|
|
|
| 115 |
webp_image = BytesIO()
|
| 116 |
pil_image.save(webp_image, format="WebP", lossless=convert_is_lossless, quality=convert_quality, method=convert_method)
|
| 117 |
webp_image.seek(0) # reset the BytesIO object to the beginning
|
|
|
|
| 118 |
|
| 119 |
image_name = f'generated/{uuid.uuid4()}{postfix}.webp'
|
| 120 |
blob = bucket.blob(image_name)
|
| 121 |
|
|
|
|
| 122 |
blob.upload_from_file(webp_image, content_type='image/webp')
|
| 123 |
blob.make_public()
|
|
|
|
| 124 |
|
| 125 |
return f'{images_base_url}/{image_name}'
|
| 126 |
except Exception as e:
|
|
|
|
| 192 |
if images_field in result:
|
| 193 |
update_progress_status(job_id=job_id, progress_status="UPLOADING_IMAGES")
|
| 194 |
result[images_field] = upload_images_in_parallel(result[images_field])
|
| 195 |
+
upload_time.log_time_end("total_upload_time")
|
| 196 |
|
| 197 |
if image_field in result:
|
| 198 |
update_progress_status(job_id=job_id, progress_status="UPLOADING_IMAGES")
|