@@ -992,41 +992,79 @@ def invocations(self, req: models.InvocationsRequest):
992
992
# req.pop('user_input', None)
993
993
994
994
try :
995
- if req .vae != None :
996
- shared .opts .data ['sd_vae' ] = req .vae
997
- refresh_vae_list ()
998
-
999
- if req .model != None :
1000
- sd_model_checkpoint = shared .opts .sd_model_checkpoint
1001
- shared .opts .sd_model_checkpoint = req .model
1002
- with self .queue_lock :
1003
- reload_model_weights ()
1004
- if sd_model_checkpoint == shared .opts .sd_model_checkpoint :
1005
- reload_vae_weights ()
1006
-
1007
- quality = req .quality
1008
-
1009
- embeddings_s3uri = shared .cmd_opts .embeddings_s3uri
1010
- hypernetwork_s3uri = shared .cmd_opts .hypernetwork_s3uri
1011
-
1012
- if hypernetwork_s3uri != '' :
1013
- shared .s3_download (hypernetwork_s3uri , shared .cmd_opts .hypernetwork_dir )
1014
- shared .reload_hypernetworks ()
1015
-
1016
- if req .options != None :
1017
- options = json .loads (req .options )
1018
- for key in options :
1019
- shared .opts .data [key ] = options [key ]
1020
-
1021
- if req .task == 'text-to-image' :
1022
- if embeddings_s3uri != '' :
1023
- response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1024
- print ('Controlnet models: ' , response .text )
1025
-
1026
- shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
1027
- sd_hijack .model_hijack .embedding_db .load_textual_inversion_embeddings ()
1028
- response = self .text2imgapi (req .txt2img_payload )
1029
- response .images = self .post_invocations (response .images , quality )
995
+ if req .vae != None :
996
+ shared .opts .data ['sd_vae' ] = req .vae
997
+ refresh_vae_list ()
998
+
999
+ if req .model != None :
1000
+ sd_model_checkpoint = shared .opts .sd_model_checkpoint
1001
+ shared .opts .sd_model_checkpoint = req .model
1002
+ with self .queue_lock :
1003
+ reload_model_weights ()
1004
+ if sd_model_checkpoint == shared .opts .sd_model_checkpoint :
1005
+ reload_vae_weights ()
1006
+
1007
+ quality = req .quality
1008
+
1009
+ embeddings_s3uri = shared .cmd_opts .embeddings_s3uri
1010
+ hypernetwork_s3uri = shared .cmd_opts .hypernetwork_s3uri
1011
+
1012
+ if hypernetwork_s3uri != '' :
1013
+ shared .s3_download (hypernetwork_s3uri , shared .cmd_opts .hypernetwork_dir )
1014
+ shared .reload_hypernetworks ()
1015
+
1016
+ if req .options != None :
1017
+ options = json .loads (req .options )
1018
+ for key in options :
1019
+ shared .opts .data [key ] = options [key ]
1020
+
1021
+ if req .task == 'text-to-image' :
1022
+ if embeddings_s3uri != '' :
1023
+ response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1024
+ print ('Controlnet models: ' , response .text )
1025
+
1026
+ shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
1027
+ sd_hijack .model_hijack .embedding_db .load_textual_inversion_embeddings ()
1028
+ response = self .text2imgapi (req .txt2img_payload )
1029
+ response .images = self .post_invocations (response .images , quality )
1030
+ response .parameters .clear ()
1031
+ oldinfo = json .loads (response .info )
1032
+ if "all_prompts" in oldinfo :
1033
+ oldinfo .pop ("all_prompts" , None )
1034
+ if "all_negative_prompts" in oldinfo :
1035
+ oldinfo .pop ("all_negative_prompts" , None )
1036
+ if "infotexts" in oldinfo :
1037
+ oldinfo .pop ("infotexts" , None )
1038
+ response .info = json .dumps (oldinfo )
1039
+ return response
1040
+ elif req .task == 'image-to-image' :
1041
+ response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1042
+ print ('Controlnet models: ' , response .text )
1043
+
1044
+ if embeddings_s3uri != '' :
1045
+ shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
1046
+ sd_hijack .model_hijack .embedding_db .load_textual_inversion_embeddings ()
1047
+ response = self .img2imgapi (req .img2img_payload )
1048
+ response .images = self .post_invocations (response .images , quality )
1049
+ response .parameters .clear ()
1050
+ oldinfo = json .loads (response .info )
1051
+ if "all_prompts" in oldinfo :
1052
+ oldinfo .pop ("all_prompts" , None )
1053
+ if "all_negative_prompts" in oldinfo :
1054
+ oldinfo .pop ("all_negative_prompts" , None )
1055
+ if "infotexts" in oldinfo :
1056
+ oldinfo .pop ("infotexts" , None )
1057
+ response .info = json .dumps (oldinfo )
1058
+ return response
1059
+ elif req .task == 'upscale_from_feed' :
1060
+ # only get the one image (in base64)
1061
+ intermediate_image = self .img2imgapi (req .img2img_payload ).images
1062
+ print ('finished intermediate img2img' )
1063
+ try :
1064
+ # update the base64 image # note might need to change to req.extras_single_payload['image'] if this does not work
1065
+ req .extras_single_payload .image = intermediate_image [0 ]
1066
+ response = self .extras_single_image_api (req .extras_single_payload )
1067
+ response .image = self .post_invocations ([response .image ], quality )[0 ]
1030
1068
response .parameters .clear ()
1031
1069
oldinfo = json .loads (response .info )
1032
1070
if "all_prompts" in oldinfo :
@@ -1036,17 +1074,15 @@ def invocations(self, req: models.InvocationsRequest):
1036
1074
if "infotexts" in oldinfo :
1037
1075
oldinfo .pop ("infotexts" , None )
1038
1076
response .info = json .dumps (oldinfo )
1077
+ # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ### get_cmd_flags is {self.get_cmd_flags()}")
1039
1078
return response
1040
- elif req .task == 'image-to-image' :
1041
- response = requests .get ('http://0.0.0.0:8080/controlnet/model_list' , params = {'update' : True })
1042
- print ('Controlnet models: ' , response .text )
1043
-
1044
- if embeddings_s3uri != '' :
1045
- shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
1046
- sd_hijack .model_hijack .embedding_db .load_textual_inversion_embeddings ()
1047
- response = self .img2imgapi (req .img2img_payload )
1048
- response .images = self .post_invocations (response .images , quality )
1049
- response .parameters .clear ()
1079
+ except Exception as e : # this is in fact obselete, because there will be a earlier return if OOM, won't reach here, but leaving here just in case
1080
+ print (
1081
+ f"An error occurred: { e } , step one upscale failed, reverting to just 4x upscale without Img2Img process" )
1082
+ elif req .task == 'extras-single-image' :
1083
+ response = self .extras_single_image_api (req .extras_single_payload )
1084
+ response .image = self .post_invocations ([response .image ], quality )[0 ]
1085
+ if "info" in response :
1050
1086
oldinfo = json .loads (response .info )
1051
1087
if "all_prompts" in oldinfo :
1052
1088
oldinfo .pop ("all_prompts" , None )
@@ -1055,89 +1091,53 @@ def invocations(self, req: models.InvocationsRequest):
1055
1091
if "infotexts" in oldinfo :
1056
1092
oldinfo .pop ("infotexts" , None )
1057
1093
response .info = json .dumps (oldinfo )
1058
- return response
1059
- elif req .task == 'upscale_from_feed' :
1060
- # only get the one image (in base64)
1061
- intermediate_image = self .img2imgapi (req .img2img_payload ).images
1062
- print ('finished intermediate img2img' )
1063
- try :
1064
- # update the base64 image # note might need to change to req.extras_single_payload['image'] if this does not work
1065
- req .extras_single_payload .image = intermediate_image [0 ]
1066
- response = self .extras_single_image_api (req .extras_single_payload )
1067
- response .image = self .post_invocations ([response .image ], quality )[0 ]
1068
- response .parameters .clear ()
1069
- oldinfo = json .loads (response .info )
1070
- if "all_prompts" in oldinfo :
1071
- oldinfo .pop ("all_prompts" , None )
1072
- if "all_negative_prompts" in oldinfo :
1073
- oldinfo .pop ("all_negative_prompts" , None )
1074
- if "infotexts" in oldinfo :
1075
- oldinfo .pop ("infotexts" , None )
1076
- response .info = json .dumps (oldinfo )
1077
- # print(f"log@{datetime.datetime.now().strftime(f'%Y%m%d%H%M%S')} ### get_cmd_flags is {self.get_cmd_flags()}")
1078
- return response
1079
- except Exception as e : # this is in fact obselete, because there will be a earlier return if OOM, won't reach here, but leaving here just in case
1080
- print (
1081
- f"An error occurred: { e } , step one upscale failed, reverting to just 4x upscale without Img2Img process" )
1082
- elif req .task == 'extras-single-image' :
1083
- response = self .extras_single_image_api (req .extras_single_payload )
1084
- response .image = self .post_invocations ([response .image ], quality )[0 ]
1085
- if "info" in response :
1086
- oldinfo = json .loads (response .info )
1087
- if "all_prompts" in oldinfo :
1088
- oldinfo .pop ("all_prompts" , None )
1089
- if "all_negative_prompts" in oldinfo :
1090
- oldinfo .pop ("all_negative_prompts" , None )
1091
- if "infotexts" in oldinfo :
1092
- oldinfo .pop ("infotexts" , None )
1093
- response .info = json .dumps (oldinfo )
1094
- return response
1095
- elif req .task == 'extras-batch-images' :
1096
- response = self .extras_batch_images_api (req .extras_batch_payload )
1097
- response .images = self .post_invocations (response .images , quality )
1098
- return response
1099
- elif req .task == 'interrogate' :
1100
- response = self .interrogateapi (req .interrogate_payload )
1101
- return response
1102
-
1103
- elif req .task == 'get-progress' :
1104
- response = self .progressapi (req .progress_payload )
1105
- print (response )
1106
- return response
1107
- elif req .task == 'get-options' :
1108
- response = self .get_config ()
1109
- return response
1110
- elif req .task == 'get-SDmodels' :
1111
- response = self .get_sd_models ()
1112
- return response
1113
- elif req .task == 'get-upscalers' :
1114
- response = self .get_upscalers ()
1115
- return response
1116
- elif req .task == 'get-memory' :
1117
- response = self .get_memory ()
1118
- return response
1119
- elif req .task == 'get-cmd-flags' :
1120
- response = self .get_cmd_flags ()
1121
- return response
1122
- elif req .task == 'do-nothing' :
1123
- print ("nothing has happened" )
1124
- return "nothing has happened"
1125
-
1126
- elif req .task .startswith ('/' ):
1127
- if req .extra_payload :
1128
- response = requests .post (url = f'http://0.0.0.0:8080{ req .task } ' , json = req .extra_payload )
1129
- else :
1130
- response = requests .get (url = f'http://0.0.0.0:8080{ req .task } ' )
1131
- if response .status_code == 200 :
1132
- return json .loads (response .text )
1133
- else :
1134
- raise HTTPException (status_code = response .status_code , detail = response .text )
1094
+ return response
1095
+ elif req .task == 'extras-batch-images' :
1096
+ response = self .extras_batch_images_api (req .extras_batch_payload )
1097
+ response .images = self .post_invocations (response .images , quality )
1098
+ return response
1099
+ elif req .task == 'interrogate' :
1100
+ response = self .interrogateapi (req .interrogate_payload )
1101
+ return response
1102
+
1103
+ elif req .task == 'get-progress' :
1104
+ response = self .progressapi (req .progress_payload )
1105
+ print (response )
1106
+ return response
1107
+ elif req .task == 'get-options' :
1108
+ response = self .get_config ()
1109
+ return response
1110
+ elif req .task == 'get-SDmodels' :
1111
+ response = self .get_sd_models ()
1112
+ return response
1113
+ elif req .task == 'get-upscalers' :
1114
+ response = self .get_upscalers ()
1115
+ return response
1116
+ elif req .task == 'get-memory' :
1117
+ response = self .get_memory ()
1118
+ return response
1119
+ elif req .task == 'get-cmd-flags' :
1120
+ response = self .get_cmd_flags ()
1121
+ return response
1122
+ elif req .task == 'do-nothing' :
1123
+ print ("nothing has happened" )
1124
+ return "nothing has happened"
1125
+
1126
+ elif req .task .startswith ('/' ):
1127
+ if req .extra_payload :
1128
+ response = requests .post (url = f'http://0.0.0.0:8080{ req .task } ' , json = req .extra_payload )
1129
+ else :
1130
+ response = requests .get (url = f'http://0.0.0.0:8080{ req .task } ' )
1131
+ if response .status_code == 200 :
1132
+ return json .loads (response .text )
1135
1133
else :
1136
- return models .InvocationsErrorResponse (error = f'Invalid task - { req .task } ' )
1134
+ raise HTTPException (status_code = response .status_code , detail = response .text )
1135
+ else :
1136
+ return models .InvocationsErrorResponse (error = f'Invalid task - { req .task } ' )
1137
1137
1138
- except Exception as e :
1139
- traceback .print_exc ()
1140
- return models .InvocationsErrorResponse (error = str (e ))
1138
+ except Exception as e :
1139
+ traceback .print_exc ()
1140
+ return models .InvocationsErrorResponse (error = str (e ))
1141
1141
1142
1142
def ping (self ):
1143
1143
return {'status' : 'Healthy' }
0 commit comments