Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,37 +3,25 @@ import base64
|
|
3 |
#import execjs
|
4 |
# Define the Mermaid code for the flowchart
|
5 |
|
6 |
-
mm_html="""
|
7 |
-
<pre class="mermaid">
|
8 |
-
graph LR
|
9 |
-
A --- B
|
10 |
-
B-->C[fa:fa-ban forbidden]
|
11 |
-
B-->D(fa:fa-spinner);
|
12 |
-
</pre>"""
|
13 |
|
14 |
mermaid_code = """graph TD;
|
15 |
-
A[Start] --> B[Decision]
|
16 |
-
B -- Yes --> C[Option 1]
|
17 |
-
B -- No --> D[Option 2]
|
18 |
-
C --> E[End]
|
19 |
-
D --> E
|
20 |
-
E[End] --> F[End]
|
21 |
"""
|
22 |
-
|
23 |
-
js_c=("""
|
24 |
-
let mermaid = require('mermaid');
|
25 |
-
mermaid.initialize({startOnLoad:true});
|
26 |
-
function renderMermaid(mermaidCode) {
|
27 |
-
mermaid.mermaidAPI.render('mermaid', mermaidCode, function(svgCode, bindFunctions) {
|
28 |
-
document.getElementById('diagram').innerHTML = svgCode;
|
29 |
-
});
|
30 |
-
}
|
31 |
-
""")
|
32 |
|
33 |
#def call_chart(mermaidCode):
|
34 |
def mm(graph=mermaid_code):
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
"""
|
39 |
graph LR;
|
@@ -50,7 +38,7 @@ graph LR;
|
|
50 |
with gr.Blocks() as app:
|
51 |
inp_text=gr.Textbox(value=mermaid_code)
|
52 |
btn=gr.Button()
|
53 |
-
out_html=gr.HTML()
|
54 |
btn.click(mm,inp_text,out_html)
|
55 |
app.load(mm,inp_text,out_html)
|
56 |
app.launch()
|
|
|
3 |
#import execjs
|
4 |
# Define the Mermaid code for the flowchart
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
mermaid_code = """graph TD;
|
8 |
+
A[Start] --> B[Decision];
|
9 |
+
B -- Yes --> C[Option 1];
|
10 |
+
B -- No --> D[Option 2];
|
11 |
+
C --> E[End];
|
12 |
+
D --> E;
|
13 |
+
E[End] --> F[End];
|
14 |
"""
|
15 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
#def call_chart(mermaidCode):
|
18 |
def mm(graph=mermaid_code):
|
19 |
+
code_out=""
|
20 |
+
for ea in mermaid_code.split("\n"):
|
21 |
+
code=ea.strip().strip("\n")
|
22 |
+
code_out+=code
|
23 |
+
out_html=f'''<div><iframe src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}" height="500" width="500"></iframe></div>'''
|
24 |
+
return out_html
|
25 |
|
26 |
"""
|
27 |
graph LR;
|
|
|
38 |
with gr.Blocks() as app:
|
39 |
inp_text=gr.Textbox(value=mermaid_code)
|
40 |
btn=gr.Button()
|
41 |
+
out_html=gr.HTML("""""")
|
42 |
btn.click(mm,inp_text,out_html)
|
43 |
app.load(mm,inp_text,out_html)
|
44 |
app.launch()
|