BUG: gradio RuntimeError: async generator raised StopAsyncIteration

BUG: gradio RuntimeError: async generator raised StopAsyncIteration

环境

python 复制代码
gradio                        4.20.0

详情

在使用gradio编写大模型可视化demo的时候,大模型正常输出,但gradio弹出此错误。

经过排除,发现是返回方式的问题,gradio传输信息给web网页的时候,我使用了return,但实际上应该 使用yield

解决方法

return改为yield

例子

python 复制代码
# 旧
def generate(message: str) -> Iterator[str]:
    stream = False
    response = "你好"
    if stream:
        for _ in range(5):
		        response += response
            yield response
    else:
        return response  # 错误

# 新
def generate(message: str) -> Iterator[str]:
    stream = False
    response = "你好"
    if stream:
        for _ in range(5):
		        response += response
            yield response
    else:
        yield response  # 正确

相关推荐
xingzhemengyou11 分钟前
python pandas操作excel
python·excel·pandas
兴趣使然黄小黄3 分钟前
【Pytest】Pytest框架快速入门
python·pytest
dagouaofei5 分钟前
文档生成PPT到底快不快?PDF转PPT工具实测分析
python·pdf·powerpoint
玖日大大20 分钟前
TensorFlow 深度解析:从基础到实战的全维度指南
人工智能·python·tensorflow
不拱地的猪26 分钟前
Matplotlib 的字体参数设置方法(MAC OSX)
python·mac·matplotlib·字体设置·文中显示中文
free-elcmacom26 分钟前
机器学习高阶教程<3>统计学习理论进阶
人工智能·python·机器学习·统计学习理论
zuoyou-HPU28 分钟前
ChatGLM4 的 tokenizer 配置文件解析
python·大模型·glm
keineahnung234530 分钟前
從 SymBool 到 SymFloat:PyTorch user magic methods 如何支持符號形狀運算?
人工智能·pytorch·python·深度学习
_妲己44 分钟前
SD的细分功能包括重绘,图像处理、放大等扩散模型应用
人工智能·python·深度学习·机器学习·stable diffusion·comfyui·ai工作流
暗之星瞳1 小时前
python爬虫学习(搜索)
爬虫·python·学习