Commit
·
0401760
1
Parent(s):
6c31c36
try something else
Browse files- handler.py +8 -8
handler.py
CHANGED
|
@@ -12,12 +12,12 @@ class EndpointHandler():
|
|
| 12 |
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
| 13 |
|
| 14 |
|
| 15 |
-
def __call__(self, data
|
| 16 |
-
|
| 17 |
-
|
| 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 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
self.processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
| 13 |
|
| 14 |
|
| 15 |
+
def __call__(self, data):
|
| 16 |
+
images = list(map(file_to_image, [data]))
|
| 17 |
+
inputs = self.processor(images=images, return_tensors="jax", padding=True) # converts the images into model-acceptable inputs and applies padding
|
| 18 |
+
emb = self.model.get_image_features(**inputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return { "embeddings": embeddings }
|
| 20 |
+
|
| 21 |
+
def file_to_image(file):
|
| 22 |
+
image = Image.open(BytesIO(file)).convert("RGB")
|
| 23 |
+
return image
|