Instructions to use ashm/test-doc with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- OpenCLIP
How to use ashm/test-doc with OpenCLIP:
import open_clip model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:ashm/test-doc') tokenizer = open_clip.get_tokenizer('hf-hub:ashm/test-doc') - Notebooks
- Google Colab
- Kaggle
Download handler.py from ashm/test-doc: direct link, hf CLI and curl.
- Browser
- Download file 908 Bytes
-
https://huggingface.co/ashm/test-doc/resolve/main/handler.py
- Command line
-
hf download hf://ashm/test-doc/handler.py
-
curl -L -o handler.py https://huggingface.co/ashm/test-doc/resolve/main/handler.py
908 Bytes
| 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`) | |
| candiates (: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 candiates | |
| prediction = self.pipeline(images=[image], candidate_labels=inputs["candiates"]) | |
| return prediction[0] |