Zero-Shot Image Classification
Transformers
PyTorch
Safetensors
English
clip
vision
language
fashion
ecommerce
Instructions to use risedev/test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use risedev/test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="risedev/test") pipe( "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png", candidate_labels=["animals", "humans", "landscape"], )# Load model directly from transformers import AutoProcessor, AutoModelForZeroShotImageClassification processor = AutoProcessor.from_pretrained("risedev/test") model = AutoModelForZeroShotImageClassification.from_pretrained("risedev/test") - Notebooks
- Google Colab
- Kaggle
Update handler.py
Browse files- handler.py +8 -5
handler.py
CHANGED
|
@@ -12,16 +12,19 @@ class EndpointHandler():
|
|
| 12 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 13 |
"""
|
| 14 |
data args:
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
Return:
|
| 18 |
A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}
|
| 19 |
"""
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
# decode base64 image to PIL
|
| 23 |
-
image = Image.open(BytesIO(base64.b64decode(inputs
|
| 24 |
|
| 25 |
# run prediction one image wit provided candiates
|
| 26 |
-
prediction = self.pipeline(images=[image], candidate_labels=
|
| 27 |
return prediction[0]
|
|
|
|
| 12 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 13 |
"""
|
| 14 |
data args:
|
| 15 |
+
parameters: {
|
| 16 |
+
candidate_labels: List[str]
|
| 17 |
+
}
|
| 18 |
+
inputs: str
|
| 19 |
Return:
|
| 20 |
A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}
|
| 21 |
"""
|
| 22 |
+
parameters = data.get("parameters", {})
|
| 23 |
+
inputs = data.get("inputs", "")
|
| 24 |
|
| 25 |
# decode base64 image to PIL
|
| 26 |
+
image = Image.open(BytesIO(base64.b64decode(inputs)))
|
| 27 |
|
| 28 |
# run prediction one image wit provided candiates
|
| 29 |
+
prediction = self.pipeline(images=[image], candidate_labels=parameters.get("candidate_labels", []))
|
| 30 |
return prediction[0]
|