File size: 873 Bytes
5090883
 
 
 
 
 
 
 
 
8ad9951
5090883
 
8ad9951
5090883
 
 
b118d20
 
 
 
5090883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr

# 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):
    # Wrap the input code into the HTML template
    html_content = html_template.format(mermaid_code)
    return html_content

# Create a Gradio interface
iface = gr.Interface(
    fn=render_mermaid,
    inputs="text",
    outputs="html",
    title="Mermaid Diagram Renderer",
    description="Input your Mermaid diagram code to render it."
)

# Launch the app
iface.launch()