python - embed.diagrams.net embedding is not showing file contents - Stack Overflow

I have the following Gradio code which embedsa diagrams (draw.io) instance within an iFrame. The URL

I have the following Gradio code which embeds a diagrams (draw.io) instance within an iFrame. The URL (".mx") is a valid URL. However, when I run the code, I see the controls from diagrams, and the spinner is spinning forever, and no contents is shown.

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"/?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()

Any suggestions?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744378292a4571294.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信