Skip to content

Commit 4ce7bf1

Browse files
[Inference Client] fix zero_shot_image_classification's parameters (#2665)
* fix zero shot image classification * send image as binary
1 parent d30853b commit 4ce7bf1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/huggingface_hub/inference/_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,10 +2913,11 @@ def zero_shot_image_classification(
29132913
# Raise ValueError if input is less than 2 labels
29142914
if len(labels) < 2:
29152915
raise ValueError("You must specify at least 2 classes to compare.")
2916-
2917-
inputs = {"image": _b64_encode(image), "candidateLabels": ",".join(labels)}
2918-
parameters = {"hypothesis_template": hypothesis_template}
2919-
payload = _prepare_payload(inputs, parameters=parameters)
2916+
parameters = {
2917+
"candidate_labels": labels,
2918+
"hypothesis_template": hypothesis_template,
2919+
}
2920+
payload = _prepare_payload(image, parameters=parameters, expect_binary=True)
29202921
response = self.post(
29212922
**payload,
29222923
model=model,

src/huggingface_hub/inference/_generated/_async_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,10 +2985,11 @@ async def zero_shot_image_classification(
29852985
# Raise ValueError if input is less than 2 labels
29862986
if len(labels) < 2:
29872987
raise ValueError("You must specify at least 2 classes to compare.")
2988-
2989-
inputs = {"image": _b64_encode(image), "candidateLabels": ",".join(labels)}
2990-
parameters = {"hypothesis_template": hypothesis_template}
2991-
payload = _prepare_payload(inputs, parameters=parameters)
2988+
parameters = {
2989+
"candidate_labels": labels,
2990+
"hypothesis_template": hypothesis_template,
2991+
}
2992+
payload = _prepare_payload(image, parameters=parameters, expect_binary=True)
29922993
response = await self.post(
29932994
**payload,
29942995
model=model,

0 commit comments

Comments
 (0)