Skip to content

Commit 34da505

Browse files
committed
Update api.py
1 parent 89a2517 commit 34da505

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

modules/api/api.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,32 @@ def decode_to_image(encoding):
105105
except Exception as err:
106106
raise HTTPException(status_code=500, detail="Invalid encoded image")
107107

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+
108134
def decode_base64_to_image(encoding):
109135
if encoding.startswith("http://") or encoding.startswith("https://"):
110136
if not opts.api_enable_requests:
@@ -1093,16 +1119,16 @@ def invocations(self, req: models.InvocationsRequest):
10931119
elif req.task == 'image-to-image':
10941120
# response = requests.get('http://0.0.0.0:8080/controlnet/model_list', params={'update': True})
10951121
# print('Controlnet models: ', response.text)
1096-
response = requests.get('http://0.0.0.0:8080/sam/heartbeat')
1097-
print(f'\nsam/heartbeat: {response.text}\n')
1098-
response = requests.get('http://0.0.0.0:8080/sam/sam-model')
1099-
print(f'\nsam/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']}")
11061132

11071133
if embeddings_s3uri != '':
11081134
shared.s3_download(embeddings_s3uri, shared.cmd_opts.embeddings_dir)

0 commit comments

Comments
 (0)