Update handler.py
Browse files- handler.py +5 -4
handler.py
CHANGED
@@ -13,11 +13,12 @@ class EndpointHandler():
|
|
13 |
|
14 |
|
15 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
16 |
-
|
17 |
-
text =
|
18 |
-
|
19 |
-
image = Image.open(BytesIO(base64.b64decode(imageData)))
|
20 |
inputs = self.processor(text=text, images=image, return_tensors="pt", padding=True)
|
21 |
outputs = self.model(**inputs)
|
|
|
|
|
22 |
embeddings = outputs.image_embeds.detach().numpy().flatten().tolist()
|
23 |
return { "embeddings": embeddings }
|
|
|
13 |
|
14 |
|
15 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
16 |
+
url = data.get("inputs")
|
17 |
+
text = data.get("text")
|
18 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
|
|
19 |
inputs = self.processor(text=text, images=image, return_tensors="pt", padding=True)
|
20 |
outputs = self.model(**inputs)
|
21 |
+
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
|
22 |
+
probs = logits_per_image.softmax(dim=1)
|
23 |
embeddings = outputs.image_embeds.detach().numpy().flatten().tolist()
|
24 |
return { "embeddings": embeddings }
|