1littlecoder commited on
Commit
ac4e4bc
1 Parent(s): c1b36c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  import base64
 
 
3
 
4
  # HTML template for rendering Mermaid diagrams
5
  html_template = """
@@ -18,18 +20,18 @@ html_template = """
18
  <div class="mermaid">{}</div>
19
  <script>
20
  mermaid.initialize({{ startOnLoad: true }});
21
- mermaid.render('graphDiv', `{}`, function(svgCode) {{
22
- document.getElementById('graphDiv').innerHTML = svgCode;
23
- }});
24
  </script>
25
- <div id="graphDiv"></div>
26
  </body>
27
  </html>
28
  """
29
 
30
  def render_mermaid(mermaid_code):
 
 
 
 
31
  # Create HTML output
32
- html_content = html_template.format(mermaid_code, mermaid_code)
33
 
34
  # Create PNG output
35
  graphbytes = mermaid_code.encode("utf8")
 
1
  import gradio as gr
2
  import base64
3
+ from mermaid import Mermaid
4
+ from mermaid.graph import Graph
5
 
6
  # HTML template for rendering Mermaid diagrams
7
  html_template = """
 
20
  <div class="mermaid">{}</div>
21
  <script>
22
  mermaid.initialize({{ startOnLoad: true }});
 
 
 
23
  </script>
 
24
  </body>
25
  </html>
26
  """
27
 
28
  def render_mermaid(mermaid_code):
29
+ # Create a Mermaid graph using mermaid-py
30
+ sequence = Graph('Sequence-diagram', mermaid_code)
31
+ render = Mermaid(sequence)
32
+
33
  # Create HTML output
34
+ html_content = html_template.format(render)
35
 
36
  # Create PNG output
37
  graphbytes = mermaid_code.encode("utf8")