-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for mermaid.js
in Markdown
component (as well as components like gr.Chatbot
that use Markdown)
#10854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/f3dc81d777f1f33567869e76a9dd11230c36d382/gradio-5.22.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@f3dc81d777f1f33567869e76a9dd11230c36d382#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/f3dc81d777f1f33567869e76a9dd11230c36d382/gradio-client-1.13.1.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/f3dc81d777f1f33567869e76a9dd11230c36d382/dist/lite.js""></script> |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
Actually the behavior isn't great when streaming (note the flickering & syntax error). Will work on a better solution: import gradio as gr
import time
value = """
abc
```mermaid
graph TD
A[Start] --> B[Step 1]
B --> C[Step 2]
C --> D[End]
```
defdefdefdefdefdefdefdef
defdefdefdefdefdefdefdef
defdefdefdefdefdefdefdef
"""
demo = gr.Blocks()
def update():
for i in range(len(value)):
time.sleep(0.03)
yield [(value[:i+1], None)]
with demo:
chatbot = gr.Chatbot(height=600)
btn = gr.Button()
btn.click(update, None, chatbot)
demo.launch() |
The syntax error has been resolved. The flickering is still there, but that's tricky to resolve as the HTML gets re-rendered every time there's a new update. Note that this happens anytime there's HTML in the chat body, e.g. with this: import gradio as gr
import time
value = """
abc
<marquee>abc</marquee>
defdefdefdefdefdefdefdef
defdefdefdefdefdefdefdef
defdefdefdefdefdefdefdef
"""
demo = gr.Blocks()
def update():
for i in range(len(value)):
time.sleep(0.03)
yield [(value[:i+1], None)]
with demo:
chatbot = gr.Chatbot(height=600)
btn = gr.Button()
btn.click(update, None, chatbot)
demo.launch() There are ways we could fix this, e.g. by adding a small debounce before the html is rendered, but I think we can tackle that later. |
js/markdown-code/MarkdownCode.svelte
Outdated
import render_math_in_element from "katex/contrib/auto-render"; | ||
import "katex/dist/katex.min.css"; | ||
import { create_marked } from "./utils"; | ||
import { sanitize } from "@gradio/sanitize"; | ||
import "./prism.css"; | ||
import { standardHtmlTags } from "./html-tags"; | ||
import mermaid from "mermaid"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mermaid can be pretty big, maybe we should dynamically import it if someone uses mermaid syntax, rather than everyone paying that cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now @pngwn
Thanks @pngwn! |
@aliabid94 pointed out that we should use the dark mermaid.js theme when we are in dark mode. Will update and then merge this in for the release |
I think this library is worth including in our Markdown component as it's a pretty popular way to generate diagrams & nice visualizations. Test with the new demo I added or with the code snippets below:
or
Closes: #10844
Closes: #9048