Spaces:
Runtime error
Runtime error
import gradio as gr | |
from pymermaid import mermaid | |
# HTML template for rendering Mermaid diagrams | |
html_template = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> | |
<style> | |
.mermaid {{ | |
display: block; | |
margin: auto; | |
}} | |
</style> | |
</head> | |
<body> | |
<div class="mermaid">{}</div> | |
<script> | |
mermaid.initialize({{ startOnLoad: true }}); | |
</script> | |
</body> | |
</html> | |
""" | |
def render_mermaid(mermaid_code): | |
# Create HTML output | |
html_content = html_template.format(mermaid_code) | |
# Create PNG output | |
png_path = "diagram.png" | |
mermaid.render(mermaid_code, filename=png_path) | |
return html_content, png_path | |
# 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." | |
) | |
# Launch the app | |
iface.launch() | |