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

嵌入diagrams.net无法显示文件内容的问题求助

嵌入diagrams.net无法显示文件内容的问题求助

我现在有一段Gradio代码,想要把diagrams.net(即draw.io)的实例通过iframe嵌入进来,使用的URL是https://bennie-haelen.github.io/diagram.mx,这个URL本身是有效的。但运行代码之后,只能看到diagrams.net的控制栏,加载的动画一直在转,完全看不到文件内容。

以下是我的代码:

import gradio as gr
import urllib.parse
import requests

def show_diagram(xml_url: str):
    if not xml_url:
        return "No URL provided."
    
    # Clean the URL
    xml_url = xml_url.strip()
    
    try:
        # Create a URL that instructs draw.io to load from the provided URL
        embed_url = f"https://embed.diagrams.net/?embed=1&ui=min&spin=1&proto=json&url={urllib.parse.quote(xml_url)}"
        
        iframe_html = f"""
        <div style="width: 100%; height: 600px; border: 1px solid #ddd; border-radius: 4px; overflow: hidden;">
          <iframe 
             style="width: 100%; height: 100%; border: none;"
             src="{embed_url}"
           ></iframe>
        </div>
        """
        
        return iframe_html
    except Exception as e:
        return f"Error: {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("## Draw.io Embed from URL")
    input_box = gr.TextArea(
        label="URL to XML File", 
        lines=2,
        placeholder="Enter the URL to your .mx or .drawio XML file..."
    )
    button = gr.Button("Show Diagram")
    output_html = gr.HTML()
    
    button.click(fn=show_diagram, inputs=input_box, outputs=output_html)

demo.launch()

有没有什么解决建议?

备注:内容来源于stack exchange,提问作者Bennie Haelen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.13 19:38:09