Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import execjs
|
3 |
+
# Define the Mermaid code for the flowchart
|
4 |
+
mermaid_code = """
|
5 |
+
graph TD;
|
6 |
+
A[Start] --> B[Decision]
|
7 |
+
B -- Yes --> C[Option 1]
|
8 |
+
B -- No --> D[Option 2]
|
9 |
+
C --> E[End]
|
10 |
+
D --> E
|
11 |
+
E[End] --> F[End]
|
12 |
+
"""
|
13 |
+
# Create an ExecJS context
|
14 |
+
context = execjs.compile("""
|
15 |
+
var mermaid = require('mermaid');
|
16 |
+
mermaid.initialize({startOnLoad:true});
|
17 |
+
function renderMermaid(mermaidCode) {
|
18 |
+
mermaid.mermaidAPI.render('mermaid', mermaidCode, function(svgCode, bindFunctions) {
|
19 |
+
document.getElementById('diagram').innerHTML = svgCode;
|
20 |
+
});
|
21 |
+
}
|
22 |
+
""")
|
23 |
+
def call_chart():
|
24 |
+
# Render the flowchart
|
25 |
+
context.call("renderMermaid", mermaid_code)
|
26 |
+
# Print the Mermaid code for reference
|
27 |
+
print(mermaid_code)
|
28 |
+
|
29 |
+
with gr.Blocks() as app:
|
30 |
+
gr.HTML("""<div id='diagram'></div>""")
|
31 |
+
app.load(call_chart,None,None)
|
32 |
+
app.launch()
|