@@ -105,6 +105,32 @@ def decode_to_image(encoding):
105
105
except Exception as err :
106
106
raise HTTPException (status_code = 500 , detail = "Invalid encoded image" )
107
107
108
+ def mask_decode_to_image (encoding ):
109
+ image = decode_to_image (encoding )
110
+ try :
111
+ # response = requests.get('http://0.0.0.0:8080/sam/sam-model')
112
+ # print(f'\nsam/sam-model: {response.text}\n')
113
+ if "Success" in requests .get ('http://0.0.0.0:8080/sam/heartbeat' ):
114
+ # print(f'\nsam/heartbeat: {response.text}\n')
115
+ image = encode_pil_to_base64 (image )
116
+ response = requests .post ('http://0.0.0.0:8080/sam/heartbeat' , json = {
117
+ "input_image" : image ,
118
+ "mask" : image ,
119
+ "dilate_amount" : 16
120
+ })
121
+ if "masked_image" in response :
122
+ image = decode_base64_to_image (response .masked_image )
123
+
124
+ else :
125
+ print (f'!!!! Error: sam did not return a masked_image!' )
126
+ raise HTTPException (status_code = 500 , detail = "Error: sam did not return a masked_image!" )
127
+ else :
128
+ print (f'!!!! Error: sam heartbeat lost!' )
129
+ except Exception as err :
130
+ pass
131
+
132
+ return image
133
+
108
134
def decode_base64_to_image (encoding ):
109
135
if encoding .startswith ("http://" ) or encoding .startswith ("https://" ):
110
136
if not opts .api_enable_requests :
@@ -1093,16 +1119,16 @@ def invocations(self, req: models.InvocationsRequest):
1093
1119
elif req .task == 'image-to-image' :
1094
1120
# response = requests.get('http://0.0.0.0:8080/controlnet/model_list', params={'update': True})
1095
1121
# print('Controlnet models: ', response.text)
1096
- response = requests .get ('http://0.0.0.0:8080/sam/heartbeat' )
1097
- print (f'\n sam/heartbeat: { response .text } \n ' )
1098
- response = requests .get ('http://0.0.0.0:8080/sam/sam-model' )
1099
- print (f'\n sam/sam-model: { response .text } \n ' )
1100
-
1101
-
1102
- if 'user_input_data' in globals ():
1103
- # global user_input_data
1104
- if user_input_data ['workflow' ] in ["style" , "image" ]:
1105
- print (f"In { user_input_data ['workflow' ]} " )
1122
+ # response = requests.get('http://0.0.0.0:8080/sam/heartbeat')
1123
+ # print(f'\nsam/heartbeat: {response.text}\n')
1124
+ # response = requests.get('http://0.0.0.0:8080/sam/sam-model')
1125
+ # print(f'\nsam/sam-model: {response.text}\n')
1126
+ #
1127
+ #
1128
+ # if 'user_input_data' in globals():
1129
+ # # global user_input_data
1130
+ # if user_input_data['workflow'] in ["style", "image"]:
1131
+ # print(f"In {user_input_data['workflow']}")
1106
1132
1107
1133
if embeddings_s3uri != '' :
1108
1134
shared .s3_download (embeddings_s3uri , shared .cmd_opts .embeddings_dir )
0 commit comments