Update handler.py
Browse files- handler.py +4 -4
handler.py
CHANGED
@@ -6,13 +6,13 @@ import base64
|
|
6 |
from typing import Dict, List, Any
|
7 |
|
8 |
class EndpointHandler():
|
9 |
-
def __init__(self, path="
|
10 |
-
# Carrega el model i el
|
11 |
self.model = CLIPModel.from_pretrained(path)
|
12 |
self.processor = CLIPProcessor.from_pretrained(path)
|
13 |
|
14 |
# Crea la pipeline de classificació d'imatges zero-shot
|
15 |
-
self.classifier = pipeline("zero-shot-image-classification", model=self.model,
|
16 |
|
17 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
18 |
image_input = data.get("inputs", None)
|
@@ -26,7 +26,7 @@ class EndpointHandler():
|
|
26 |
response = requests.get(image_input)
|
27 |
image = Image.open(BytesIO(response.content))
|
28 |
else:
|
29 |
-
#
|
30 |
image_data = base64.b64decode(image_input)
|
31 |
image = Image.open(BytesIO(image_data))
|
32 |
|
|
|
6 |
from typing import Dict, List, Any
|
7 |
|
8 |
class EndpointHandler():
|
9 |
+
def __init__(self, path=""):
|
10 |
+
# Carrega el model i el processador específics de CLIP
|
11 |
self.model = CLIPModel.from_pretrained(path)
|
12 |
self.processor = CLIPProcessor.from_pretrained(path)
|
13 |
|
14 |
# Crea la pipeline de classificació d'imatges zero-shot
|
15 |
+
self.classifier = pipeline("zero-shot-image-classification", model=self.model, processor=self.processor)
|
16 |
|
17 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
18 |
image_input = data.get("inputs", None)
|
|
|
26 |
response = requests.get(image_input)
|
27 |
image = Image.open(BytesIO(response.content))
|
28 |
else:
|
29 |
+
# Suposem que l'input és base64 i decodifica-la
|
30 |
image_data = base64.b64decode(image_input)
|
31 |
image = Image.open(BytesIO(image_data))
|
32 |
|