Spaces:
Runtime error
Runtime error
1littlecoder
commited on
Commit
•
52e1974
1
Parent(s):
b118d20
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
# HTML template for rendering Mermaid diagrams
|
4 |
html_template = """
|
@@ -7,7 +8,7 @@ html_template = """
|
|
7 |
<head>
|
8 |
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
9 |
<style>
|
10 |
-
mermaid {{
|
11 |
display: block;
|
12 |
margin: auto;
|
13 |
}}
|
@@ -23,15 +24,20 @@ html_template = """
|
|
23 |
"""
|
24 |
|
25 |
def render_mermaid(mermaid_code):
|
26 |
-
#
|
27 |
html_content = html_template.format(mermaid_code)
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Create a Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
fn=render_mermaid,
|
33 |
inputs="text",
|
34 |
-
outputs="html",
|
35 |
title="Mermaid Diagram Renderer",
|
36 |
description="Input your Mermaid diagram code to render it."
|
37 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
from pymermaid import mermaid
|
3 |
|
4 |
# HTML template for rendering Mermaid diagrams
|
5 |
html_template = """
|
|
|
8 |
<head>
|
9 |
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
10 |
<style>
|
11 |
+
.mermaid {{
|
12 |
display: block;
|
13 |
margin: auto;
|
14 |
}}
|
|
|
24 |
"""
|
25 |
|
26 |
def render_mermaid(mermaid_code):
|
27 |
+
# Create HTML output
|
28 |
html_content = html_template.format(mermaid_code)
|
29 |
+
|
30 |
+
# Create PNG output
|
31 |
+
png_path = "diagram.png"
|
32 |
+
mermaid.render(mermaid_code, filename=png_path)
|
33 |
+
|
34 |
+
return html_content, png_path
|
35 |
|
36 |
# Create a Gradio interface
|
37 |
iface = gr.Interface(
|
38 |
fn=render_mermaid,
|
39 |
inputs="text",
|
40 |
+
outputs=["html", "image"],
|
41 |
title="Mermaid Diagram Renderer",
|
42 |
description="Input your Mermaid diagram code to render it."
|
43 |
)
|