Code: Select all
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"""
"""
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()