[Python] embed.diagrams.net embedding is not showing file contents

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following Gradio code which embeds a diagrams.net (draw.io) instance within an iFrame. The URL ("https://bennie-haelen.github.io/diagram.mx") is a valid URL. However, when I run the code, I see the controls from diagrams.net, 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"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()


    Any suggestions?

    Continue reading...

Compartilhe esta Página