huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
1.83k stars 471 forks source link

Invalid input data for `ImageToTextOutput`: Expected a single instance, but got a list. #2273

Closed whiskyboy closed 1 month ago

whiskyboy commented 2 months ago

Describe the bug

When inferencing with image_to_text() method, it reports a value error: ValueError: Invalid input data for <class 'huggingface_hub.inference._generated.types.image_to_text.ImageToTextOutput'>. Expected a single instance, but got a list.

It looks like the post response need to be parsed as a list:

raw_response = client.post(data=image_data, task="image-to-text")
ImageToTextOutput.parse_obj_as_list(raw_response)[0].generated_text

I verified the above code could work as expected.

Reproduction

No response

Logs

No response

System info

- huggingface_hub version: 0.23.0
- Platform: Linux-6.5.0-1019-azure-x86_64-with-glibc2.35
- Python version: 3.11.9
- Running in iPython ?: Yes
- iPython shell: ZMQInteractiveShell
- Running in notebook ?: Yes
- Running in Google Colab ?: No
- Token path ?: /home/weitian/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers: 
- FastAI: N/A
- Tensorflow: N/A
- Torch: N/A
- Jinja2: N/A
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: 10.3.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.26.4
- pydantic: 2.7.1
- aiohttp: N/A
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /home/weitian/.cache/huggingface/hub
- HF_ASSETS_CACHE: /home/weitian/.cache/huggingface/assets
- HF_TOKEN_PATH: /home/weitian/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10
tejas36026 commented 1 month ago

same here . for some code i am running i am also getting this error lets say for example running this code


import gradio as gr

gr.load("models/naver-clova-ix/donut-base").launch(share=True)   

i get this error

ValueError: Invalid input data for <class 'huggingface_hub.inference._generated.types.image_to_text.ImageToTextOutput'>. Expected a single instance, but got a list.

Wauplin commented 1 month ago

Thanks for reporting @whiskyboy @tejas36026 and sorry for the inconvenience! I have opened a PR to fix this: https://github.com/huggingface/huggingface_hub/pull/2285