import gradio as gr import base64 # HTML template for rendering Mermaid diagrams html_template = """
{}
""" def render_mermaid(mermaid_code): # Create HTML output html_content = html_template.format(mermaid_code) # Create PNG output graphbytes = mermaid_code.encode("utf8") base64_bytes = base64.urlsafe_b64encode(graphbytes) base64_string = base64_bytes.decode("ascii") png_url = "https://mermaid.ink/img/" + base64_string return html_content, png_url # Create a Gradio interface iface = gr.Interface( fn=render_mermaid, inputs="text", outputs=["html", "image"], title="Mermaid Diagram Renderer", description="Input your Mermaid diagram code to render it and get a PNG image." ) # Launch the app iface.launch()