[hf space api]ModuleNotFoundError: No module named ‘websockets.legacy‘和TypeError: Client.predict问题解决

在调用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

 即可正常运行:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值