You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradio应用进度条重复显示两次的问题求助

解决Gradio中调用含gr.Progress()的函数时重复显示进度条的问题

我在开发Gradio应用时,使用gr.HTML和gr.File组件,通过按钮的.click()方法调用process函数。函数内用gr.Progress()实现进度条,会输出对应两个组件的值,但运行时会显示两个进度条,需要只保留一个。

相关代码片段

process_btn = gr.Button("Create Note")

status = gr.HTML(label="Status")
download = gr.File(label="Download Your Note", interactive=False)

def update_download_link(file_path):
    return gr.File.update(value=file_path, visible=True)

process_btn.click(
    fn=process,
    inputs=[agree, doc_type, audio, file, session_state],
    outputs=[status, download]
)

process函数定义:

def process(agreement, document_type, microphone_input: np.ndarray, transcript_files, session_state: dict, progress=gr.Progress()):
    # 函数内进度更新逻辑

问题截图

进度条重复显示截图

解决方法

重复进度条出现的原因是:Gradio会为每个输出组件自动生成进度条,当函数返回多个输出时就会重复渲染。以下两种方法可以解决:

方法1:指定全局共享进度条

不在process函数参数中声明progress,而是在.click()调用时统一指定全局进度条,让所有输出共用同一个:

process_btn.click(
    fn=process,
    inputs=[agree, doc_type, audio, file, session_state],
    outputs=[status, download],
    progress=gr.Progress()  # 在这里设置全局进度条
)

同时修改process函数,改为在内部初始化进度条:

def process(agreement, document_type, microphone_input: np.ndarray, transcript_files, session_state: dict):
    progress = gr.Progress()  # 函数内创建进度条实例
    # 后续进度更新逻辑保持不变

方法2:禁用自动进度条,手动控制

在.click()方法中关闭自动生成的进度条,只保留函数内手动创建的那一个:

process_btn.click(
    fn=process,
    inputs=[agree, doc_type, audio, file, session_state],
    outputs=[status, download],
    show_progress=False  # 禁用组件自动生成的进度条
)

process函数的原有定义无需修改,内部的进度更新逻辑正常执行即可。

内容的提问来源于stack exchange,提问作者Mit Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 21:03:21