Spaces:
Runtime error
Runtime error
1littlecoder
commited on
Commit
•
5090883
1
Parent(s):
1cfcfaa
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# HTML template for rendering Mermaid diagrams
|
4 |
+
html_template = """
|
5 |
+
<!DOCTYPE html>
|
6 |
+
<html>
|
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 |
+
}
|
14 |
+
</style>
|
15 |
+
</head>
|
16 |
+
<body>
|
17 |
+
<mermaid>{}</mermaid>
|
18 |
+
</body>
|
19 |
+
</html>
|
20 |
+
"""
|
21 |
+
|
22 |
+
def render_mermaid(mermaid_code):
|
23 |
+
# Wrap the input code into the HTML template
|
24 |
+
html_content = html_template.format(mermaid_code)
|
25 |
+
return html_content
|
26 |
+
|
27 |
+
# Create a Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=render_mermaid,
|
30 |
+
inputs="text",
|
31 |
+
outputs="html",
|
32 |
+
title="Mermaid Diagram Renderer",
|
33 |
+
description="Input your Mermaid diagram code to render it."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the app
|
37 |
+
iface.launch()
|