Spaces:
Runtime error
Runtime error
1littlecoder
commited on
Commit
•
e7a385f
1
Parent(s):
82cae8f
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
# HTML template for rendering Mermaid diagrams
|
5 |
html_template = """
|
@@ -28,10 +28,12 @@ def render_mermaid(mermaid_code):
|
|
28 |
html_content = html_template.format(mermaid_code)
|
29 |
|
30 |
# Create PNG output
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
-
return html_content,
|
35 |
|
36 |
# Create a Gradio interface
|
37 |
iface = gr.Interface(
|
@@ -39,7 +41,7 @@ iface = gr.Interface(
|
|
39 |
inputs="text",
|
40 |
outputs=["html", "image"],
|
41 |
title="Mermaid Diagram Renderer",
|
42 |
-
description="Input your Mermaid diagram code to render it."
|
43 |
)
|
44 |
|
45 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
2 |
+
import base64
|
3 |
|
4 |
# HTML template for rendering Mermaid diagrams
|
5 |
html_template = """
|
|
|
28 |
html_content = html_template.format(mermaid_code)
|
29 |
|
30 |
# Create PNG output
|
31 |
+
graphbytes = mermaid_code.encode("utf8")
|
32 |
+
base64_bytes = base64.urlsafe_b64encode(graphbytes)
|
33 |
+
base64_string = base64_bytes.decode("ascii")
|
34 |
+
png_url = "https://mermaid.ink/img/" + base64_string
|
35 |
|
36 |
+
return html_content, png_url
|
37 |
|
38 |
# Create a Gradio interface
|
39 |
iface = gr.Interface(
|
|
|
41 |
inputs="text",
|
42 |
outputs=["html", "image"],
|
43 |
title="Mermaid Diagram Renderer",
|
44 |
+
description="Input your Mermaid diagram code to render it and get a PNG image."
|
45 |
)
|
46 |
|
47 |
# Launch the app
|