Commit
•
89e197c
1
Parent(s):
0639203
Update handler.py
Browse files- handler.py +11 -4
handler.py
CHANGED
@@ -24,12 +24,19 @@ class EndpointHandler():
|
|
24 |
image=info.pop('image',data)
|
25 |
image=base64.b64decode(image)
|
26 |
raw_image=Image.open(BytesIO(image)).convert('RGB')
|
27 |
-
|
28 |
-
|
|
|
29 |
if replacement=="":
|
30 |
-
|
|
|
|
|
|
|
31 |
else:
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
if __name__=="__main__":
|
|
|
24 |
image=info.pop('image',data)
|
25 |
image=base64.b64decode(image)
|
26 |
raw_image=Image.open(BytesIO(image)).convert('RGB')
|
27 |
+
texts=info.pop('texts',data)
|
28 |
+
target=texts[0]
|
29 |
+
replacement=texts[1]
|
30 |
if replacement=="":
|
31 |
+
img=self.model.inference_remove(raw_image,target)
|
32 |
+
img_data=img.tobytes()
|
33 |
+
img_base64=base64.b64encode(img_data).decode('utf-8')
|
34 |
+
return {'image':img_base64}
|
35 |
else:
|
36 |
+
img=self.model.inference_replace_sam(raw_image,target,replacement)
|
37 |
+
img_data=img.tobytes()
|
38 |
+
img_base64=base64.b64encode(img_data).decode('utf-8')
|
39 |
+
return {'image':img_base64}
|
40 |
|
41 |
|
42 |
if __name__=="__main__":
|