Views
No views yet
zero-sho-image-classification Inference endpoint.custom task for zero-shot-image-classification for 🤗 Inference Endpoints. The code for the customized pipeline is in the pipeline.py.Custom as task to use the pipeline.py file. -> double check if it is selected1{
2 "image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
3 "candiates":["sea","palace","car","ship"]
4}requests.!wget https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg1import json
2from typing import List
3import requests as r
4import base64
5
6ENDPOINT_URL = ""
7HF_TOKEN = ""
8
9
10def predict(path_to_image: str = None, candiates: List[str] = None):
11 with open(path_to_image, "rb") as i:
12 b64 = base64.b64encode(i.read())
13
14 payload = {"inputs": {"image": b64.decode("utf-8"), "candiates": candiates}}
15 response = r.post(
16 ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
17 )
18 return response.json()
19
20
21prediction = predict(
22 path_to_image="palace.jpg", candiates=["sea", "palace", "car", "ship"]
23)1[{'label': 'palace', 'score': 0.9996134638786316},
2 {'label': 'car', 'score': 0.0002602009626571089},
3 {'label': 'ship', 'score': 0.00011758189066313207},
4 {'label': 'sea', 'score': 8.666840585647151e-06}]