Skip to content
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

Move markdown & latex processing to the frontend for the gr.Markdown and gr.DataFrame components #5268

Merged
merged 23 commits into from Aug 21, 2023

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Aug 18, 2023

Moves markdown and latex processing to the frontend for the gr.Markdown and gr.DataFrame components. This has several advantages:

  1. Removes 2 dependencies from the gradio python package 🥳
  2. Katex.js renders LaTeX much more nicely and without the alignment issue that we were seeing with markdown_it (see screenshots below)
  3. Moves some of the work client side making gradio apps faster (we've seen this before with gr.Chatbot)

It should be noted that this increases the javascript bundle size for these two components.

Screenshots (before):

image image

Screenshots (after):

image image

Closes: #4523

Also added:

  • the latex_delimiters parameter to gr.Markdown() and gr.DataFrame for control over whether to parse LaTeX
  • stories for these two components as a visual test.

Thanks @dawoodkhan82 for the pointers!

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Aug 18, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/3ae854f789f5d2075b447cb6d59e22975058a292/gradio-3.40.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3ae854f789f5d2075b447cb6d59e22975058a292#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Aug 18, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/dataframe minor
@gradio/markdown minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Move markdown & latex processing to the frontend for the gr.Markdown and gr.DataFrame components

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs changed the title Move markdown & latex rendering to the frontend Move markdown & latex processing to the frontend Aug 18, 2023
@abidlabs abidlabs marked this pull request as ready for review August 18, 2023 20:10
@abidlabs
Copy link
Member Author

abidlabs commented Aug 18, 2023

Fighting an issue with the frontend build step, which was working until just recently (seems flaky?)

@dawoodkhan82 dawoodkhan82 self-requested a review August 18, 2023 22:06
@dawoodkhan82
Copy link
Collaborator

We use $$ as the default latex_delimiters for chatbot. We should be consistent across components.

@dawoodkhan82
Copy link
Collaborator

Tested both markdown and dataframe. Both look good to me!

@abidlabs
Copy link
Member Author

We use $$ as the default latex_delimiters for chatbot. We should be consistent across components.

That is true -- however, the previous behavior of gr.Markdown and gr.Dataframe was to render LaTeX enclosed in $ so I kept it that way for backwards compatibility. Maybe we make the change in 4.0?

@abidlabs
Copy link
Member Author

abidlabs commented Aug 19, 2023

Fixed up the backend tests -- also I've recently had to make a lot of changes manually to the XRAY_CONFIG e.g. every time I add a new parameter to a component. I wrote a script scripts/overwrite_xray_config.py that overwrites the test XRAY_CONFIG based on the config that is generated from a blocks app.

Of course, it should be used with caution since we should only override the test config if we're sure that there aren't any accidental changes to the config generation. But it can help avoid tedious manual work particularly for the component cleanup. cc @dawoodkhan82 @hannahblair for visibility

@abidlabs abidlabs changed the title Move markdown & latex processing to the frontend Move markdown & latex processing to the frontend for the gr.Markdown and gr.DataFrame components Aug 19, 2023
@abidlabs
Copy link
Member Author

Thanks for the review @dawoodkhan82! Merging

@abidlabs abidlabs merged commit f49028c into main Aug 21, 2023
16 checks passed
@abidlabs abidlabs deleted the frontend-md branch August 21, 2023 13:54
@pngwn pngwn mentioned this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Render Markdown and LaTeX in gr.Markdown and gr.DataFrame in the frontend, like gr.Chatbot
3 participants