File size: 1,275 Bytes
585747f
ae02035
ae8f10f
0a40653
585747f
fe88e4d
 
77b211d
32e4ce7
 
 
 
 
 
585747f
32e4ce7
c875e8e
73c565e
3ee3c91
32e4ce7
ae8f10f
32e4ce7
 
ae8f10f
22e8acb
32e4ce7
73c565e
 
 
 
 
 
 
 
 
efafbe1
 
965bec8
ed46b3d
c997017
965bec8
ed46b3d
ae8f10f
c997017
058c62a
965bec8
efafbe1
058c62a
d11c1e5
77b211d
32e4ce7
77b211d
efafbe1
585747f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import base64
import random
#import execjs
# Define the Mermaid code for the flowchart


mermaid_code = """graph TD;
    A[Start] --> B[Decision];
    B -- Yes --> C[Option 1];
    B -- No --> D[Option 2];
    C --> E[End];
    D --> E;
    E[End] --> F[End];
"""


#def call_chart(mermaidCode):
def mm(graph):
    code_out=""
    for ea in graph.split("\n"):
        code=ea.strip().strip("\n")
        code_out+=code
    #out_html=f'''<div><iframe src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}&rand={random.randint(1,1111111111)}" height="500" width="500"></iframe></div>'''
    out_html=f'''<div><iframe src="https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={code_out}" height="500" width="500"></iframe></div>'''
    return out_html

"""
graph LR;
    A--> B & C & D;
    B--> A & E;
    C--> A & E;
    D--> A & E;
    E--> B & C & D;
"""


css="""
svg.style .flowchart-link{
stroke:red;!important;
}
svg.style .marker {
    fill: #ed0000!important;
    stroke: #ff0101;!important;
}
"""

with gr.Blocks(css=css) as app:
    inp_text=gr.Textbox(value=mermaid_code)
    btn=gr.Button()
    out_html=gr.HTML("""""")
    btn.click(mm,inp_text,out_html)
    app.load(mm,inp_text,out_html)
app.launch()