Skip to content

Commit b1e571f

Browse files
committed
debug
1 parent 9bb4ec3 commit b1e571f

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

modules/api/api.py

+18-22
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def decode_base64_to_image(encoding):
133133
user_input_data = {}
134134

135135

136-
def set_img_exif_dict():
136+
def set_img_exif_dict(image_id="img_id_1"):
137137
print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& set_img_exif_dict Writing exif")
138138
title = "AIRI"
139139
date_taken = "2001:01:01 01:01:01"
@@ -146,10 +146,12 @@ def set_img_exif_dict():
146146
user_id = "AIRI tester"
147147
if "user_id" in user_input_data:
148148
user_id = user_input_data['user_id']
149-
keywords = "Generated in AIRI platform. https://airilab.com"
150-
description = "An image processed by the AIRI platform."
149+
generation_id = "gen_id_1"
150+
if "generation_id" in user_input_data:
151+
generation_id = user_input_data['generation_id']
152+
keywords = "Generated in AIRI platform. https://airilab.com . Generation ID: {generation_id}, Image ID: {image_id}"
153+
description = f"An image processed by the AIRI platform. Generation ID: {generation_id}, Image ID: {image_id}"
151154
software = "AIRI Platform v1.0"
152-
# imageid = "imageid?"
153155
# imagenum = "imagenum?"
154156
# seed = "seed?"
155157
exif_dict = {
@@ -231,12 +233,12 @@ def encode_pil_to_base64(image):
231233
# })
232234

233235
# Convert dict to bytes
234-
exif_bytes = piexif.dump(set_img_exif_dict())
236+
exif_bytes = piexif.dump(set_img_exif_dict()) # Doesn't work here even though the exif is confirmed to have been added here
235237

236238
if opts.samples_format.lower() in ("jpg", "jpeg"):
237239
image.save(output_bytes, format="JPEG", exif=exif_bytes, quality=opts.jpeg_quality)
238-
print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& encode_pil_to_base64")
239-
print(Image.open(output_bytes).getexif()) # Print the EXIF data
240+
# print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& encode_pil_to_base64")
241+
# print(Image.open(output_bytes).getexif()) # Print the EXIF data
240242
else:
241243
image.save(output_bytes, format="WEBP", exif=exif_bytes, quality=opts.jpeg_quality)
242244

@@ -948,30 +950,24 @@ def post_invocations(self, b64images, quality):
948950
key = key[ : -1]
949951
images = []
950952
for b64image in b64images:
953+
image_id = datetime.datetime.now().strftime(f"%Y%m%d%H%M%S-{uuid.uuid4()}")
954+
suffix = opts.samples_format.lower()
951955
img = decode_to_image(b64image)
952-
if opts.samples_format.lower() in ("jpg", "jpeg", "webp"):
953-
print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_before")
954-
# Create a file-like object from the image object
955-
# image_file = BytesIO(img.tobytes())
956-
# image = Image.open(image_file)
957-
# print(image.getexif()) # Print the EXIF data
958-
print(img.getexif()) # Print the EXIF data
956+
if opts.samples_format.lower() in ("jpg", "jpeg"):
957+
# print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_before")
958+
# print(img.getexif()) # Print the EXIF data
959959

960960
# Save the image with the EXIF data
961-
exif_bytes = piexif.dump(set_img_exif_dict())
962-
# image.save(img, format="JPEG", exif=exif_bytes, quality=opts.jpeg_quality)
961+
exif_bytes = piexif.dump(set_img_exif_dict(image_id=image_id))
963962
with io.BytesIO() as output_bytes:
964963
img.save(output_bytes, format="JPEG", exif=exif_bytes, quality=opts.jpeg_quality)
965964
output_bytes.seek(0) # Go back to the start of the BytesIO object
966-
img_after = Image.open(output_bytes)
967-
print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_after")
968-
print(img_after.getexif()) # Print the EXIF data
965+
# img_after = Image.open(output_bytes)
966+
# print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& post_invocations_after")
967+
# print(img_after.getexif()) # Print the EXIF data
969968

970969
bytes_data = export_pil_to_bytes(img, quality)
971970
# bytes_data = export_pil_to_bytes(decode_to_image(b64image), quality)
972-
973-
image_id = datetime.datetime.now().strftime(f"%Y%m%d%H%M%S-{uuid.uuid4()}")
974-
suffix = opts.samples_format.lower()
975971
shared.s3_client.put_object(
976972
Body=bytes_data,
977973
Bucket=bucket,

0 commit comments

Comments
 (0)