File size: 962 Bytes
585747f
0a40653
585747f
 
 
 
 
 
 
 
 
 
 
0a40653
c875e8e
585747f
 
 
 
 
 
 
c875e8e
 
585747f
d11c1e5
585747f
 
c875e8e
585747f
d11c1e5
 
c875e8e
 
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
import gradio as gr
#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]
"""
# Create an ExecJS context
js_c=("""
    let mermaid = require('mermaid');
    mermaid.initialize({startOnLoad:true});
    function renderMermaid(mermaidCode) {
        mermaid.mermaidAPI.render('mermaid', mermaidCode, function(svgCode, bindFunctions) {
            document.getElementById('diagram').innerHTML = svgCode;
        });
    }
""")

def call_chart(mermaidCode):
    # Render the flowchart
    #context.call("renderMermaid", mermaid_code)
    # Print the Mermaid code for reference
    print(mermaid_code)
    
with gr.Blocks() as app:
    inp_text=gr.Textbox(value=mermaid_code)
    
    out_html=gr.HTML("""<div id='diagram'>Text</div>""")
    app.load(call_chart,inp_text,None,js=js_c)
app.launch()