在调用huggingface space上api时遇到了如下报错
PS F:\Desktop> & C:/Users/ASUS/AppData/Local/Programs/Python/Python311/python.exe f:/Desktop/svg/1.py
Traceback (most recent call last):
File "f:\Desktop\svg\1.py", line 1, in <module>
from gradio_client import Client
File "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\gradio_client\__init__.py", line 1, in <module>
from gradio_client.client import Client
File "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\gradio_client\client.py", line 31, in <module>
from gradio_client import serializing, utils
File "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\gradio_client\serializing.py", line 9, in <module>
from gradio_client import media_data, utils
File "C:\Users\ASUS\AppData\Roaming\Python\Python311\site-packages\gradio_client\utils.py", line 26, in <module>
from websockets.legacy.protocol import WebSocketCommonProtocol
ModuleNotFoundError: No module named 'websockets.legacy'
解决方法:
由于 Websockets 版本与 Gradio 客户端不兼容导致的。安装兼容版本包的websockets
pip install websockets -U
同时还遇到了这个问题:
Traceback (most recent call last):
File "f:\Desktop\svg\1.py", line 4, in <module>
result = client.predict(
^^^^^^^^^^^^^^^
TypeError: Client.predict() got an unexpected keyword argument 'query'
继续将gradio包更新至最新即可解决:
pip install gradio -U
即可正常运行: