mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
Links in updated markdown open in a new tab (#3236)
* links in updated markdowns open in a new tab * update changelog * fix test * consolidation * fix tests --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
170ad3d785
commit
595b314459
43
CHANGELOG.md
43
CHANGELOG.md
@ -44,7 +44,7 @@ by [@pngwn](https://github.com/pngwn) in [PR 3205](https://github.com/gradio-app
|
||||
|
||||
### New `gr.BarPlot` component! 📊
|
||||
|
||||
Create interactive bar plots from a high-level interface with `gr.BarPlot`.
|
||||
Create interactive bar plots from a high-level interface with `gr.BarPlot`.
|
||||
No need to remember matplotlib syntax anymore!
|
||||
|
||||
Example usage:
|
||||
@ -89,13 +89,14 @@ By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3212](https://git
|
||||
gr.Chatbot([("Hi, I'm DialoGPT. Try asking me a question.", None)])
|
||||
```
|
||||
By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3165](https://github.com/gradio-app/gradio/pull/3165)
|
||||
* Fixes `gr.utils.delete_none` to only remove props whose values are `None` from the config by [@abidlabs](https://github.com/abidlabs) in [PR 3188](https://github.com/gradio-app/gradio/pull/3188)
|
||||
* Fixes `gr.utils.delete_none` to only remove props whose values are `None` from the config by [@abidlabs](https://github.com/abidlabs) in [PR 3188](https://github.com/gradio-app/gradio/pull/3188)
|
||||
* Fix bug where embedded demos were not loading files properly by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3177](https://github.com/gradio-app/gradio/pull/3177)
|
||||
* The `change` event is now triggered when users click the 'Clear All' button of the multiselect DropDown component by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3195](https://github.com/gradio-app/gradio/pull/3195)
|
||||
* Stops File component from freezing when a large file is uploaded by [@aliabid94](https://github.com/aliabid94) in [PR 3191](https://github.com/gradio-app/gradio/pull/3191)
|
||||
* Support Chinese pinyin in Dataframe by [@aliabid94](https://github.com/aliabid94) in [PR 3206](https://github.com/gradio-app/gradio/pull/3206)
|
||||
* The `clear` event is now triggered when images are cleared by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3218](https://github.com/gradio-app/gradio/pull/3218)
|
||||
* Fix bug where auth cookies where not sent when connecting to an app via http by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3223](https://github.com/gradio-app/gradio/pull/3223)
|
||||
* Fix issue where updated markdown links were not being opened in a new tab by [@gante](https://github.com/gante) in [PR 3236](https://github.com/gradio-app/gradio/pull/3236)
|
||||
* Ensure latext CSS is always applied in light and dark mode by [@pngwn](https://github.com/pngwn) in [PR 3233](https://github.com/gradio-app/gradio/pull/3233)
|
||||
* Fixed comment typo in components.py by [@eltociear](https://github.com/eltociear) in [PR 3235](https://github.com/gradio-app/gradio/pull/3235)
|
||||
|
||||
@ -105,7 +106,7 @@ By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3165](https://github.
|
||||
* Keep pnginfo metadata for gallery by [@wfng92](https://github.com/wfng92) in [PR 3150](https://github.com/gradio-app/gradio/pull/3150)
|
||||
* Add a section on how to run a Gradio app locally [@osanseviero](https://github.com/osanseviero) in [PR 3170](https://github.com/gradio-app/gradio/pull/3170)
|
||||
* Fixed typos in gradio events function documentation by [@vidalmaxime](https://github.com/vidalmaxime) in [PR 3168](https://github.com/gradio-app/gradio/pull/3168)
|
||||
* Added an example using Gradio's batch mode with the diffusers library by [@abidlabs](https://github.com/abidlabs) in [PR 3224](https://github.com/gradio-app/gradio/pull/3224)
|
||||
* Added an example using Gradio's batch mode with the diffusers library by [@abidlabs](https://github.com/abidlabs) in [PR 3224](https://github.com/gradio-app/gradio/pull/3224)
|
||||
|
||||
## Testing and Infrastructure Changes:
|
||||
No changes to highlight.
|
||||
@ -115,8 +116,8 @@ No changes to highlight.
|
||||
|
||||
## Full Changelog:
|
||||
* Fix demos page css and add close demos button by [@aliabd](https://github.com/aliabd) in [PR 3151](https://github.com/gradio-app/gradio/pull/3151)
|
||||
* Caches temp files from base64 input data by giving them a deterministic path based on the contents of data by [@abidlabs](https://github.com/abidlabs) in [PR 3197](https://github.com/gradio-app/gradio/pull/3197)
|
||||
* Better warnings (when there is a mismatch between the number of output components and values returned by a function, or when the `File` component or `UploadButton` component includes a `file_types` parameter along with `file_count=="dir"`) by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Caches temp files from base64 input data by giving them a deterministic path based on the contents of data by [@abidlabs](https://github.com/abidlabs) in [PR 3197](https://github.com/gradio-app/gradio/pull/3197)
|
||||
* Better warnings (when there is a mismatch between the number of output components and values returned by a function, or when the `File` component or `UploadButton` component includes a `file_types` parameter along with `file_count=="dir"`) by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Raises a `gr.Error` instead of a regular Python error when you use `gr.Interface.load()` to load a model and there's an error querying the HF API by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Fixed gradio share links so that they are persistent and do not reset if network
|
||||
connection is disrupted by by [XciD](https://github.com/XciD), [Wauplin](https://github.com/Wauplin), and [@abidlabs](https://github.com/abidlabs) in [PR 3149](https://github.com/gradio-app/gradio/pull/3149) and a follow-up to allow it to work for users upgrading from a previous Gradio version in [PR 3221](https://github.com/gradio-app/gradio/pull/3221)
|
||||
@ -134,22 +135,22 @@ If your Interface function is a generator, there used to be a separate `Stop` bu
|
||||
to the `Submit` button.
|
||||
|
||||
We've revamed the `Submit` button so that it turns into a `Stop` button during the generation process.
|
||||
Clicking on the `Stop` button will cancel the generation and turn it back to a `Submit` button.
|
||||
Clicking on the `Stop` button will cancel the generation and turn it back to a `Submit` button.
|
||||
The `Stop` button will automatically turn back to a `Submit` button at the end of the generation if you don't use it!
|
||||
|
||||
By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3124](https://github.com/gradio-app/gradio/pull/3124)
|
||||
By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3124](https://github.com/gradio-app/gradio/pull/3124)
|
||||
|
||||
|
||||
### Queue now works with reload mode!
|
||||
|
||||
You can now call `queue` on your `demo` outside of the `if __name__ == "__main__"` block and
|
||||
run the script in reload mode with the `gradio` command.
|
||||
run the script in reload mode with the `gradio` command.
|
||||
|
||||
Any changes to the `app.py` file will be reflected in the webpage automatically and the queue will work
|
||||
properly!
|
||||
|
||||
|
||||
By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
|
||||
|
||||
### Allow serving files from additional directories
|
||||
@ -161,25 +162,25 @@ demo.launch(
|
||||
)
|
||||
```
|
||||
|
||||
By [@maxaudron](https://github.com/maxaudron) in [PR 3075](https://github.com/gradio-app/gradio/pull/3075)
|
||||
By [@maxaudron](https://github.com/maxaudron) in [PR 3075](https://github.com/gradio-app/gradio/pull/3075)
|
||||
|
||||
## Bug Fixes:
|
||||
- Fixes URL resolution on Windows by [@abidlabs](https://github.com/abidlabs) in [PR 3108](https://github.com/gradio-app/gradio/pull/3108)
|
||||
- Example caching now works with components without a label attribute (e.g. `Column`) by [@abidlabs](https://github.com/abidlabs) in [PR 3123](https://github.com/gradio-app/gradio/pull/3123)
|
||||
- Fixes URL resolution on Windows by [@abidlabs](https://github.com/abidlabs) in [PR 3108](https://github.com/gradio-app/gradio/pull/3108)
|
||||
- Example caching now works with components without a label attribute (e.g. `Column`) by [@abidlabs](https://github.com/abidlabs) in [PR 3123](https://github.com/gradio-app/gradio/pull/3123)
|
||||
- Ensure the Video component correctly resets the UI state whe a new video source is loaded and reduce choppiness of UI by [@pngwn](https://github.com/abidlabs) in [PR 3117](https://github.com/gradio-app/gradio/pull/3117)
|
||||
- Fixes loading private Spaces by [@abidlabs](https://github.com/abidlabs) in [PR 3068](https://github.com/gradio-app/gradio/pull/3068)
|
||||
- Fixes loading private Spaces by [@abidlabs](https://github.com/abidlabs) in [PR 3068](https://github.com/gradio-app/gradio/pull/3068)
|
||||
- Added a warning when attempting to launch an `Interface` via the `%%blocks` jupyter notebook magic command by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3126](https://github.com/gradio-app/gradio/pull/3126)
|
||||
- Fixes bug where interactive output image cannot be set when in edit mode by [@dawoodkhan82](https://github.com/@dawoodkhan82) in [PR 3135](https://github.com/gradio-app/gradio/pull/3135)
|
||||
- A share link will automatically be created when running on Sagemaker notebooks so that the front-end is properly displayed by [@abidlabs](https://github.com/abidlabs) in [PR 3137](https://github.com/gradio-app/gradio/pull/3137)
|
||||
- A share link will automatically be created when running on Sagemaker notebooks so that the front-end is properly displayed by [@abidlabs](https://github.com/abidlabs) in [PR 3137](https://github.com/gradio-app/gradio/pull/3137)
|
||||
- Fixes a few dropdown component issues; hide checkmark next to options as expected, and keyboard hover is visible by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3145]https://github.com/gradio-app/gradio/pull/3145)
|
||||
- Fixed bug where example pagination buttons were not visible in dark mode or displayed under the examples table. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3144](https://github.com/gradio-app/gradio/pull/3144)
|
||||
- Fixed bug where the font color of axis labels and titles for native plots did not respond to dark mode preferences. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3146](https://github.com/gradio-app/gradio/pull/3146)
|
||||
- Fixed bug where example pagination buttons were not visible in dark mode or displayed under the examples table. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3144](https://github.com/gradio-app/gradio/pull/3144)
|
||||
- Fixed bug where the font color of axis labels and titles for native plots did not respond to dark mode preferences. By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3146](https://github.com/gradio-app/gradio/pull/3146)
|
||||
|
||||
## Documentation Changes:
|
||||
- Added a guide on the 4 kinds of Gradio Interfaces by [@yvrjsharma](https://github.com/yvrjsharma) and [@abidlabs](https://github.com/abidlabs) in [PR 3003](https://github.com/gradio-app/gradio/pull/3003)
|
||||
- Explained that the parameters in `launch` will not be respected when using reload mode, e.g. `gradio` command by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
- Added a demo to show how to set up variable numbers of outputs in Gradio by [@abidlabs](https://github.com/abidlabs) in [PR 3127](https://github.com/gradio-app/gradio/pull/3127)
|
||||
- Updated docs to reflect that the `equal_height` parameter should be passed to the `.style()` method of `gr.Row()` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3125](https://github.com/gradio-app/gradio/pull/3125)
|
||||
- Added a guide on the 4 kinds of Gradio Interfaces by [@yvrjsharma](https://github.com/yvrjsharma) and [@abidlabs](https://github.com/abidlabs) in [PR 3003](https://github.com/gradio-app/gradio/pull/3003)
|
||||
- Explained that the parameters in `launch` will not be respected when using reload mode, e.g. `gradio` command by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
- Added a demo to show how to set up variable numbers of outputs in Gradio by [@abidlabs](https://github.com/abidlabs) in [PR 3127](https://github.com/gradio-app/gradio/pull/3127)
|
||||
- Updated docs to reflect that the `equal_height` parameter should be passed to the `.style()` method of `gr.Row()` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3125](https://github.com/gradio-app/gradio/pull/3125)
|
||||
|
||||
## Testing and Infrastructure Changes:
|
||||
No changes to highlight.
|
||||
@ -1104,7 +1105,7 @@ demo.queue().launch()
|
||||
No changes to highlight.
|
||||
|
||||
## Documentation Changes:
|
||||
* Explained how to set up `queue` and `auth` when working with reload mode by by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
* Explained how to set up `queue` and `auth` when working with reload mode by by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://github.com/gradio-app/gradio/pull/3089)
|
||||
|
||||
## Testing and Infrastructure Changes:
|
||||
No changes to highlight.
|
||||
|
@ -25,8 +25,6 @@ import pandas as pd
|
||||
import PIL
|
||||
import PIL.ImageOps
|
||||
from ffmpy import FFmpeg
|
||||
from markdown_it import MarkdownIt
|
||||
from mdit_py_plugins.dollarmath.index import dollarmath_plugin
|
||||
from pandas.api.types import is_numeric_dtype
|
||||
from PIL import Image as _Image # using _ to minimize namespace pollution
|
||||
from typing_extensions import Literal
|
||||
@ -2681,11 +2679,7 @@ class Dataframe(Changeable, IOComponent, JSONSerializable):
|
||||
return data
|
||||
|
||||
if cls.markdown_parser is None:
|
||||
cls.markdown_parser = (
|
||||
MarkdownIt()
|
||||
.use(dollarmath_plugin, renderer=utils.tex2svg, allow_digits=False)
|
||||
.enable("table")
|
||||
)
|
||||
cls.markdown_parser = utils.get_markdown_parser()
|
||||
|
||||
for i in range(len(data)):
|
||||
for j in range(len(data[i])):
|
||||
@ -3892,7 +3886,7 @@ class Chatbot(Changeable, IOComponent, JSONSerializable):
|
||||
"The 'color_map' parameter has been moved from the constructor to `Chatbot.style()` ",
|
||||
)
|
||||
self.color_map = color_map
|
||||
self.md = MarkdownIt()
|
||||
self.md = utils.get_markdown_parser()
|
||||
|
||||
IOComponent.__init__(
|
||||
self,
|
||||
@ -5226,11 +5220,7 @@ class Markdown(IOComponent, Changeable, SimpleSerializable):
|
||||
visible: If False, component will be hidden.
|
||||
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
|
||||
"""
|
||||
self.md = (
|
||||
MarkdownIt()
|
||||
.use(dollarmath_plugin, renderer=utils.tex2svg, allow_digits=False)
|
||||
.enable("table")
|
||||
)
|
||||
self.md = utils.get_markdown_parser()
|
||||
IOComponent.__init__(
|
||||
self, visible=visible, elem_id=elem_id, value=value, **kwargs
|
||||
)
|
||||
|
@ -14,10 +14,6 @@ import warnings
|
||||
import weakref
|
||||
from typing import TYPE_CHECKING, Any, Callable, List, Tuple
|
||||
|
||||
from markdown_it import MarkdownIt
|
||||
from mdit_py_plugins.dollarmath.index import dollarmath_plugin
|
||||
from mdit_py_plugins.footnote.index import footnote_plugin
|
||||
|
||||
from gradio import Examples, interpretation, utils
|
||||
from gradio.blocks import Blocks
|
||||
from gradio.components import (
|
||||
@ -298,20 +294,7 @@ class Interface(Blocks):
|
||||
cleantext = re.sub(CLEANER, "", raw_html)
|
||||
return cleantext
|
||||
|
||||
md = (
|
||||
MarkdownIt(
|
||||
"js-default",
|
||||
{
|
||||
"linkify": True,
|
||||
"typographer": True,
|
||||
"html": True,
|
||||
},
|
||||
)
|
||||
.use(dollarmath_plugin, renderer=utils.tex2svg, allow_digits=False)
|
||||
.use(footnote_plugin)
|
||||
.enable("table")
|
||||
)
|
||||
|
||||
md = utils.get_markdown_parser()
|
||||
simple_description = None
|
||||
if description is not None:
|
||||
description = md.render(description)
|
||||
|
@ -41,6 +41,9 @@ import fsspec.asyn
|
||||
import httpx
|
||||
import matplotlib.pyplot as plt
|
||||
import requests
|
||||
from markdown_it import MarkdownIt
|
||||
from mdit_py_plugins.dollarmath.index import dollarmath_plugin
|
||||
from mdit_py_plugins.footnote.index import footnote_plugin
|
||||
from pydantic import BaseModel, Json, parse_obj_as
|
||||
|
||||
import gradio
|
||||
@ -893,3 +896,28 @@ def abspath(path: str | Path) -> Path:
|
||||
return Path.cwd() / path
|
||||
else:
|
||||
return Path(path).resolve()
|
||||
|
||||
|
||||
def get_markdown_parser() -> MarkdownIt:
|
||||
md = (
|
||||
MarkdownIt(
|
||||
"js-default",
|
||||
{
|
||||
"linkify": True,
|
||||
"typographer": True,
|
||||
"html": True,
|
||||
},
|
||||
)
|
||||
.use(dollarmath_plugin, renderer=tex2svg, allow_digits=False)
|
||||
.use(footnote_plugin)
|
||||
.enable("table")
|
||||
)
|
||||
|
||||
# Add target="_blank" to all links. Taken from MarkdownIt docs: https://github.com/executablebooks/markdown-it-py/blob/master/docs/architecture.md
|
||||
def render_blank_link(self, tokens, idx, options, env):
|
||||
tokens[idx].attrSet("target", "_blank")
|
||||
return self.renderToken(tokens, idx, options, env)
|
||||
|
||||
md.add_render_rule("link_open", render_blank_link)
|
||||
|
||||
return md
|
||||
|
@ -1784,7 +1784,7 @@ class TestMarkdown:
|
||||
def test_component_functions(self):
|
||||
markdown_component = gr.Markdown("# Let's learn about $x$", label="Markdown")
|
||||
assert markdown_component.get_config()["value"].startswith(
|
||||
"""<h1>Let\'s learn about <span class="math inline"><span style=\'font-size: 0px\'>x</span><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="11.6pt" height="19.35625pt" viewBox="0 0 11.6 19.35625" xmlns="http://www.w3.org/2000/svg" version="1.1">\n \n <defs>\n <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id="figure_1">\n <g id="patch_1">\n <path d="M 0 19.35625"""
|
||||
"""<h1>Let’s learn about <span class="math inline"><span style=\'font-size: 0px\'>x</span><svg xmlns:xlink="http://www.w3.org/1999/xlink" width="11.6pt" height="19.35625pt" viewBox="0 0 11.6 19.35625" xmlns="http://www.w3.org/2000/svg" version="1.1">\n \n <defs>\n <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id="figure_1">\n <g id="patch_1">\n <path d="M 0 19.35625"""
|
||||
)
|
||||
|
||||
def test_in_interface(self):
|
||||
@ -1796,7 +1796,7 @@ class TestMarkdown:
|
||||
output_data = iface(input_data)
|
||||
assert (
|
||||
output_data
|
||||
== """<p>Here's an <a href="https://gradio.app/images/gradio_logo.png">image</a></p>\n"""
|
||||
== """<p>Here’s an <a href="https://gradio.app/images/gradio_logo.png" target="_blank">image</a></p>\n"""
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user