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

如何在Gradio聊天机器人的输出中显示可激活超链接?

在Gradio聊天机器人输出中显示可点击超链接的解决方案

你提到的相关GitHub issue已解决,当前Gradio支持通过Markdown格式实现可点击超链接的需求,以下是具体解决方案:

问题根源

你当前的代码使用outputs="text",该组件会将返回内容作为纯文本渲染,因此链接仅显示为字符串,无法点击。

解决方案1:使用Markdown输出组件

将输出组件替换为gr.Markdown(),同时返回内容采用Markdown链接语法[显示文本](链接地址):

import gradio as gr

def my_function(text):
    href = "https://www.google.com/"
    return f"This is a link to Google: [Google]({href})"

gr.Interface(my_function, inputs="text", outputs=gr.Markdown()).launch()

解决方案2:针对聊天机器人组件(如ChatInterface/Chatbot)

如果是开发聊天机器人,直接返回Markdown格式的链接即可,聊天组件默认支持Markdown渲染:

import gradio as gr

def respond(message, history):
    href = "https://www.google.com/"
    return f"我给你找了个链接:[Google]({href})"

gr.ChatInterface(respond).launch()

上述两种方式都能让链接在Gradio界面中显示为可点击状态,对应issue的问题已在Gradio后续版本中修复,无需额外处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 10:13:18