每当我提交第一个查询时,Gradio 总是会出现“错误”。但后续查询工作正常。为什么?

问题描述 投票:0回答:1

我正在遵循 Gradio 文档中的基本 Gradio 界面:

import gradio as gr

def greet(name):
    return "Hello " + name #+ "!" +a

demo = gr.Interface(fn=greet, inputs="text", outputs="text")

demo.launch()

当我通过 Chrome 访问 UI (http://127.0.0.1:7860/) 时,每当我在声明服务器后立即提交第一个查询时,我总是会收到“错误”:

错误信息是:

Traceback (most recent call last):
  File "C:\Users\fra\anaconda3\envs\project\lib\site-packages\gradio\routes.py", line 534, in predict
    output = await route_utils.call_process_api(
  File "C:\Users\fra\anaconda3\envs\project\lib\site-packages\gradio\route_utils.py", line 226, in call_process_api
    output = await app.get_blocks().process_api(
  File "C:\Users\fra\anaconda3\envs\project\lib\site-packages\gradio\utils.py", line 855, in __exit__
    matplotlib.use(self._original_backend)
  File "C:\Users\fra\anaconda3\envs\project\lib\site-packages\matplotlib\__init__.py", line 1276, in use
    plt.switch_backend(name)
  File "C:\Users\fra\anaconda3\envs\project\lib\site-packages\matplotlib\pyplot.py", line 343, in switch_backend
    canvas_class = module.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'

但是,后续查询工作正常:

为什么第一次查询出错,而后续查询却正常?我使用 Windows 10。

python gradio
1个回答
0
投票

在 anaconda 中创建了一个新环境,安装了

python 3.8.18
,它对我有用

© www.soinside.com 2019 - 2024. All rights reserved.