1littlecoder commited on
Commit
c1b36c8
·
verified ·
1 Parent(s): 90efa7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import base64
3
 
 
4
  html_template = """
5
  <!DOCTYPE html>
6
  <html>
@@ -17,14 +18,18 @@ html_template = """
17
  <div class="mermaid">{}</div>
18
  <script>
19
  mermaid.initialize({{ startOnLoad: true }});
 
 
 
20
  </script>
 
21
  </body>
22
  </html>
23
  """
24
 
25
  def render_mermaid(mermaid_code):
26
  # Create HTML output
27
- html_content = html_template.format(mermaid_code)
28
 
29
  # Create PNG output
30
  graphbytes = mermaid_code.encode("utf8")
@@ -34,6 +39,7 @@ def render_mermaid(mermaid_code):
34
 
35
  return html_content, png_url
36
 
 
37
  with gr.Blocks(theme=gr.themes.Citrus()) as mrender:
38
  gr.Markdown("# Mermaid Diagram Renderer")
39
  gr.Markdown("Input your Mermaid diagram code to render it and get a PNG image.")
 
1
  import gradio as gr
2
  import base64
3
 
4
+ # HTML template for rendering Mermaid diagrams
5
  html_template = """
6
  <!DOCTYPE html>
7
  <html>
 
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")
 
39
 
40
  return html_content, png_url
41
 
42
+ # Create a Gradio Blocks interface with Citrus theme
43
  with gr.Blocks(theme=gr.themes.Citrus()) as mrender:
44
  gr.Markdown("# Mermaid Diagram Renderer")
45
  gr.Markdown("Input your Mermaid diagram code to render it and get a PNG image.")