Skip to content

Commit bb3d3b5

Browse files
Fix Replicate image-to-image compatibility with different model schemas (#3749)
Pass the input image in multiple payload keys (image, images, input_image, input_images) to support different Replicate models that expect the image in different keys. Similar to: huggingface/huggingface.js#1938 Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent ebb9ceb commit bb3d3b5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/huggingface_hub/inference/_providers/replicate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,16 @@ def _prepare_payload_as_dict(
142142
) -> Optional[dict]:
143143
image_url = _as_url(inputs, default_mime_type="image/jpeg")
144144

145-
payload: dict[str, Any] = {"input": {"input_image": image_url, **filter_none(parameters)}}
145+
# Different Replicate models expect the image in different keys
146+
payload: dict[str, Any] = {
147+
"input": {
148+
"image": image_url,
149+
"images": [image_url],
150+
"input_image": image_url,
151+
"input_images": [image_url],
152+
**filter_none(parameters),
153+
}
154+
}
146155

147156
mapped_model = provider_mapping_info.provider_id
148157
if ":" in mapped_model:

tests/test_inference_providers.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,13 @@ def test_image_to_image_payload(self):
16511651
),
16521652
)
16531653
assert payload == {
1654-
"input": {"input_image": image_uri, "num_inference_steps": 20},
1654+
"input": {
1655+
"image": image_uri,
1656+
"images": [image_uri],
1657+
"input_image": image_uri,
1658+
"input_images": [image_uri],
1659+
"num_inference_steps": 20,
1660+
},
16551661
}
16561662

16571663
payload = helper._prepare_payload_as_dict(
@@ -1666,7 +1672,13 @@ def test_image_to_image_payload(self):
16661672
),
16671673
)
16681674
assert payload == {
1669-
"input": {"input_image": image_uri, "num_inference_steps": 20},
1675+
"input": {
1676+
"image": image_uri,
1677+
"images": [image_uri],
1678+
"input_image": image_uri,
1679+
"input_images": [image_uri],
1680+
"num_inference_steps": 20,
1681+
},
16701682
"version": "123456",
16711683
}
16721684

0 commit comments

Comments
 (0)