Spaces:
Paused
Paused
| 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): | |
| def mm(graph): | |
| graphbytes = graph.encode("utf8") | |
| base64_bytes = base64.b64encode(graphbytes) | |
| base64_string = base64_bytes.decode("ascii") | |
| #display(Image(url="https://mermaid.ink/img/" + base64_string)) | |
| out_im=f"""<img src="https://mermaid.ink/img/" + {base64_string}""" | |
| return gr.update(out_im0 | |
| """ | |
| graph LR; | |
| A--> B & C & D; | |
| B--> A & E; | |
| C--> A & E; | |
| D--> A & E; | |
| E--> B & C & D; | |
| """ | |
| with gr.Blocks() as app: | |
| inp_text=gr.Textbox(value=mermaid_code) | |
| out_html=gr.HTML("""<div id='diagram'>Text</div>""") | |
| app.load(mm,inp_text,out_html) | |
| app.launch() |