Add base64
Browse files- handler.py +9 -3
handler.py
CHANGED
|
@@ -4,7 +4,8 @@ from PIL import Image
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import torchvision.transforms as T
|
| 6 |
from typing import Dict, List, Any
|
| 7 |
-
|
|
|
|
| 8 |
# image = Image.open("man.png").convert("RGB")
|
| 9 |
# trimap = Image.open("mask2.png").convert("L")
|
| 10 |
|
|
@@ -17,8 +18,13 @@ class EndpointHandler():
|
|
| 17 |
"hustvl/vitmatte-small-composition-1k")
|
| 18 |
|
| 19 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
inputs = self.processor(
|
| 24 |
images=image, trimaps=trimap, return_tensors="pt")
|
|
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import torchvision.transforms as T
|
| 6 |
from typing import Dict, List, Any
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
import base64
|
| 9 |
# image = Image.open("man.png").convert("RGB")
|
| 10 |
# trimap = Image.open("mask2.png").convert("L")
|
| 11 |
|
|
|
|
| 18 |
"hustvl/vitmatte-small-composition-1k")
|
| 19 |
|
| 20 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 21 |
+
inputs = data.pop("inputs", data)
|
| 22 |
+
# parameters = data.pop("parameters", {"mode": "image"})
|
| 23 |
+
|
| 24 |
+
image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
|
| 25 |
+
trimap = Image.open(BytesIO(base64.b64decode(inputs['trimap'])))
|
| 26 |
+
# image = data.pop("image")
|
| 27 |
+
# trimap = data.pop("trimap")
|
| 28 |
|
| 29 |
inputs = self.processor(
|
| 30 |
images=image, trimaps=trimap, return_tensors="pt")
|