Skip to content

Commit

Permalink
Fix InferenceClient.image_to_text output value (#2285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored May 27, 2024
1 parent 11e692a commit bf6011b
Show file tree
Hide file tree
Showing 4 changed files with 3,543 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,8 @@ def image_to_text(self, image: ContentT, *, model: Optional[str] = None) -> Imag
```
"""
response = self.post(data=image, model=model, task="image-to-text")
return ImageToTextOutput.parse_obj_as_instance(response)
output = ImageToTextOutput.parse_obj(response)
return output[0] if isinstance(output, list) else output

def list_deployed_models(
self, frameworks: Union[None, str, Literal["all"], List[str]] = None
Expand Down
3 changes: 2 additions & 1 deletion src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ async def image_to_text(self, image: ContentT, *, model: Optional[str] = None) -
```
"""
response = await self.post(data=image, model=model, task="image-to-text")
return ImageToTextOutput.parse_obj_as_instance(response)
output = ImageToTextOutput.parse_obj(response)
return output[0] if isinstance(output, list) else output

async def list_deployed_models(
self, frameworks: Union[None, str, Literal["all"], List[str]] = None
Expand Down
Loading

0 comments on commit bf6011b

Please sign in to comment.