@@ -133,7 +133,8 @@ def decode_base64_to_image(encoding):
133
133
user_input_data = {}
134
134
135
135
136
- def set_img_exif_dict ():
136
+ def set_img_exif_dict (image_id = "img_id_1" ):
137
+ # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& set_img_exif_dict Writing exif")
137
138
title = "AIRI"
138
139
date_taken = "2001:01:01 01:01:01"
139
140
global user_input_data
@@ -145,10 +146,12 @@ def set_img_exif_dict():
145
146
user_id = "AIRI tester"
146
147
if "user_id" in user_input_data :
147
148
user_id = user_input_data ['user_id' ]
148
- keywords = "Generated in AIRI platform. https://airilab.com"
149
- 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 = f"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 } "
150
154
software = "AIRI Platform v1.0"
151
- # imageid = "imageid?"
152
155
# imagenum = "imagenum?"
153
156
# seed = "seed?"
154
157
exif_dict = {
@@ -193,6 +196,16 @@ def set_img_exif_dict():
193
196
piexif .ExifIFD .UserComment : description .encode ('utf-8' ),
194
197
}
195
198
}
199
+
200
+ # def print_nested_dict(nested_dict, indent=0):
201
+ # for key, value in nested_dict.items():
202
+ # print('\t' * indent + str(key))
203
+ # if isinstance(value, dict):
204
+ # print_nested_dict(value, indent + 1)
205
+ # else:
206
+ # print('\t' * (indent + 1) + str(value))
207
+
208
+ # print_nested_dict(exif_dict)
196
209
return exif_dict
197
210
198
211
@@ -220,9 +233,11 @@ def encode_pil_to_base64(image):
220
233
exif_bytes = piexif .dump (set_img_exif_dict ())
221
234
222
235
if opts .samples_format .lower () in ("jpg" , "jpeg" ):
223
- image .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = opts .jpeg_quality )
236
+ image .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = opts .jpeg_quality )
237
+ # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ***&&& encode_pil_to_base64")
238
+ # print(Image.open(output_bytes).getexif()) # Print the EXIF data
224
239
else :
225
- image .save (output_bytes , format = "WEBP" , exif = exif_bytes , quality = opts .jpeg_quality )
240
+ image .save (output_bytes , format = "WEBP" , exif = exif_bytes , quality = opts .jpeg_quality )
226
241
227
242
else :
228
243
raise HTTPException (status_code = 500 , detail = "Invalid image format" )
@@ -231,7 +246,7 @@ def encode_pil_to_base64(image):
231
246
232
247
return base64 .b64encode (bytes_data )
233
248
234
- def export_pil_to_bytes (image , quality ):
249
+ def export_pil_to_bytes (image , quality , image_id = "" ):
235
250
with io .BytesIO () as output_bytes :
236
251
237
252
if opts .samples_format .lower () == 'png' :
@@ -244,10 +259,13 @@ def export_pil_to_bytes(image, quality):
244
259
image .save (output_bytes , format = "PNG" , pnginfo = (metadata if use_metadata else None ), quality = quality if quality else opts .jpeg_quality )
245
260
246
261
elif opts .samples_format .lower () in ("jpg" , "jpeg" , "webp" ):
247
- parameters = image .info .get ('parameters' , None )
248
- exif_bytes = piexif .dump ({
249
- "Exif" : { piexif .ExifIFD .UserComment : piexif .helper .UserComment .dump (parameters or "" , encoding = "unicode" ) }
250
- })
262
+ # parameters = image.info.get('parameters', None)
263
+ # exif_bytes = piexif.dump({
264
+ # "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(parameters or "", encoding="unicode") }
265
+ # })
266
+ # Convert dict to bytes
267
+ exif_bytes = piexif .dump (set_img_exif_dict (image_id = image_id ))
268
+
251
269
if opts .samples_format .lower () in ("jpg" , "jpeg" ):
252
270
image .save (output_bytes , format = "JPEG" , exif = exif_bytes , quality = quality if quality else opts .jpeg_quality )
253
271
else :
@@ -932,9 +950,13 @@ def post_invocations(self, b64images, quality):
932
950
key = key [ : - 1 ]
933
951
images = []
934
952
for b64image in b64images :
935
- bytes_data = export_pil_to_bytes (decode_to_image (b64image ), quality )
953
+ # bytes_data = export_pil_to_bytes(decode_to_image(b64image), quality)
936
954
image_id = datetime .datetime .now ().strftime (f"%Y%m%d%H%M%S-{ uuid .uuid4 ()} " )
937
955
suffix = opts .samples_format .lower ()
956
+ bytes_data = export_pil_to_bytes (decode_to_image (b64image ), quality , image_id = image_id )
957
+
958
+ print (f"log@{ datetime .datetime .now ().strftime (f'%Y%m%d%H%M%S' )} GenID@{ user_input_data ['generation_id' ]} image_id@{ image_id } " )
959
+
938
960
shared .s3_client .put_object (
939
961
Body = bytes_data ,
940
962
Bucket = bucket ,
@@ -973,12 +995,12 @@ def req_logging(self, obj, indent=1):
973
995
974
996
def invocations (self , req : models .InvocationsRequest ):
975
997
with self .invocations_lock :
976
- print ("\n ----------------------------invocation--------------------------- " )
977
- try :
978
- print ("" )
979
- self .req_logging (req )
980
- except Exception as e :
981
- print ("console Log ran into issue: " , e )
998
+ print (f "\n ----------------------------invocation log@ { datetime . datetime . now (). strftime ( f'%Y%m%d%H%M%S' ) } --------------------------- " )
999
+ # try:
1000
+ # print("")
1001
+ # self.req_logging(req)
1002
+ # except Exception as e:
1003
+ # print("console Log ran into issue: ", e)
982
1004
# print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} req in invocations: {req}")
983
1005
global user_input_data
984
1006
user_input_data = {}
@@ -988,8 +1010,27 @@ def invocations(self, req: models.InvocationsRequest):
988
1010
# req.alwayson_scripts.pop("user_input")
989
1011
if req .user_input != None :
990
1012
user_input_data = req .user_input
1013
+ print (f"\n -----<<<<<<< UserID@{ user_input_data ['user_id' ]} >>>>>>>----- " )
1014
+ print (f"\n -----<<<<<<< GenID@{ user_input_data ['generation_id' ]} >>>>>>>----- " )
1015
+ print (f"\n -----<<<<<<< WFID@{ user_input_data ['workflow' ]} >>>>>>>----- " )
1016
+ print (f"\n Received user_input_data:\n "
1017
+ f"user_id={ user_input_data ['user_id' ]} ,\n "
1018
+ f"date_taken={ user_input_data ['date_taken' ]} ,\n "
1019
+ f"project_id={ user_input_data ['project_id' ]} ,\n "
1020
+ f"generation_id={ user_input_data ['generation_id' ]} ,\n "
1021
+ f"workflow={ user_input_data ['workflow' ]} ,\n "
1022
+ f"design_library_style={ user_input_data ['design_library_style' ]} ,\n "
1023
+ f"camera={ user_input_data ['camera' ]} ,\n "
1024
+ f"fidelity_level={ user_input_data ['fidelity_level' ]} ,\n "
1025
+ f"additional_prompt={ user_input_data ['additional_prompt' ]} ,\n "
1026
+ f"atmosphere={ user_input_data ['atmosphere' ]} ,\n "
1027
+ f"img_width={ user_input_data ['img_width' ]} ,\n "
1028
+ f"img_height={ user_input_data ['img_height' ]} \n "
1029
+ )
991
1030
# print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} user_input processed in invocations")
992
1031
# req.pop('user_input', None)
1032
+ else :
1033
+ print (f"\n !!!!!ERROR user_input_data missing!!!!!" )
993
1034
994
1035
try :
995
1036
if req .vae != None :
@@ -1021,7 +1062,7 @@ def invocations(self, req: models.InvocationsRequest):
1021
1062
if req .task == 'text-to-image' :
1022
1063
if embeddings_s3uri != '' :
1023
1064
response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1024
- print ('Controlnet models: ' , response .text )
1065
+ # print('Controlnet models: ', response.text)
1025
1066
1026
1067
shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
1027
1068
sd_hijack .model_hijack .embedding_db .load_textual_inversion_embeddings ()
@@ -1039,7 +1080,7 @@ def invocations(self, req: models.InvocationsRequest):
1039
1080
return response
1040
1081
elif req .task == 'image-to-image' :
1041
1082
response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1042
- print ('Controlnet models: ' , response .text )
1083
+ # print('Controlnet models: ', response.text)
1043
1084
1044
1085
if embeddings_s3uri != '' :
1045
1086
shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
@@ -1059,7 +1100,7 @@ def invocations(self, req: models.InvocationsRequest):
1059
1100
elif req .task == 'upscale_from_feed' :
1060
1101
# only get the one image (in base64)
1061
1102
intermediate_image = self .img2imgapi (req .img2img_payload ).images
1062
- print ('finished intermediate img2img' )
1103
+ # print('finished intermediate img2img')
1063
1104
try :
1064
1105
# update the base64 image # note might need to change to req.extras_single_payload['image'] if this does not work
1065
1106
req .extras_single_payload .image = intermediate_image [0 ]
0 commit comments