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条)