1littlecoder commited on
Commit
e7a385f
1 Parent(s): 82cae8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from pymermaid import mermaid
3
 
4
  # HTML template for rendering Mermaid diagrams
5
  html_template = """
@@ -28,10 +28,12 @@ def render_mermaid(mermaid_code):
28
  html_content = html_template.format(mermaid_code)
29
 
30
  # Create PNG output
31
- png_path = "diagram.png"
32
- mermaid.render(mermaid_code, filename=png_path)
 
 
33
 
34
- return html_content, png_path
35
 
36
  # Create a Gradio interface
37
  iface = gr.Interface(
@@ -39,7 +41,7 @@ iface = gr.Interface(
39
  inputs="text",
40
  outputs=["html", "image"],
41
  title="Mermaid Diagram Renderer",
42
- description="Input your Mermaid diagram code to render it."
43
  )
44
 
45
  # Launch the app
 
1
  import gradio as gr
2
+ import base64
3
 
4
  # HTML template for rendering Mermaid diagrams
5
  html_template = """
 
28
  html_content = html_template.format(mermaid_code)
29
 
30
  # Create PNG output
31
+ graphbytes = mermaid_code.encode("utf8")
32
+ base64_bytes = base64.urlsafe_b64encode(graphbytes)
33
+ base64_string = base64_bytes.decode("ascii")
34
+ png_url = "https://mermaid.ink/img/" + base64_string
35
 
36
+ return html_content, png_url
37
 
38
  # Create a Gradio interface
39
  iface = gr.Interface(
 
41
  inputs="text",
42
  outputs=["html", "image"],
43
  title="Mermaid Diagram Renderer",
44
+ description="Input your Mermaid diagram code to render it and get a PNG image."
45
  )
46
 
47
  # Launch the app