Instructions to use aayushgs/clip-vit-large-patch14-custom-handler with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aayushgs/clip-vit-large-patch14-custom-handler with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("zero-shot-image-classification", model="aayushgs/clip-vit-large-patch14-custom-handler") 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("aayushgs/clip-vit-large-patch14-custom-handler") model = AutoModelForZeroShotImageClassification.from_pretrained("aayushgs/clip-vit-large-patch14-custom-handler", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from typing import Dict, List, Any | |
| from PIL import Image | |
| from io import BytesIO | |
| from transformers import pipeline | |
| import base64 | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| self.pipeline=pipeline("zero-shot-image-classification",model=path) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| images (:obj:`string`) | |
| candidates (:obj:`list`) | |
| Return: | |
| A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82} | |
| """ | |
| inputs = data.pop("inputs", data) | |
| # decode base64 image to PIL | |
| image = Image.open(BytesIO(base64.b64decode(inputs['image']))) | |
| # run prediction one image wit provided candidates | |
| prediction = self.pipeline(images=[image], candidate_labels=inputs["candidates"]) | |
| return prediction[0] |