Skip to content

gr.HighlightedText.update not working well with color_map #5290

@ydshieh

Description

@ydshieh

Describe the bug

When using gr.HighlightedText.update to update its color_map, if the new color_map remove some keys from the original color_map, those deleted labels is still displayed.

See Reproduction.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

Colab

(running on Colab)

!pip install -q gradio 

Click the first radio component to see things showing, then click the second radio component to change color_map.
It's easy to see the deleted labels are not removed from the display.

import gradio as gr


def change_color_map(choice):
    if choice == "color map 1":
        return gr.HighlightedText.update(visible=True, color_map={"R": "red", "L": "lime"})
    elif choice == "color map 2":
        return gr.HighlightedText.update(visible=True, color_map={"G": "green", "P": "pink"})


def change_text(choice):
    if choice == "text 1":
        return [("a", None), ("b", "R")]
    elif choice == "text 2":
        return [("c", None), ("d", "G")]

with gr.Blocks() as demo:
    radio = gr.Radio(
        ["text 1", "text 2"], label="change text"
    )

    radio2 = gr.Radio(
        ["color map 1", "color map 2"], label="change color map"
    )

    text = gr.HighlightedText(
        label="Diff",
        combine_adjacent=True,
        show_legend=True,
    ).style(color_map={"R": "red", "G": "green", "B": "blue", "Y": "yellow"})

    radio.change(fn=change_text, inputs=radio, outputs=[text])
    radio2.change(fn=change_color_map, inputs=radio2, outputs=[text])


if __name__ == "__main__":
    demo.launch()

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 3.40.1
gradio_client version: 0.4.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
aiohttp: 3.8.5
altair: 4.2.2
fastapi: 0.101.1
ffmpy: 0.3.1
gradio-client: 0.4.0
httpx: 0.24.1
huggingface-hub: 0.16.4
importlib-resources: 6.0.1
jinja2: 3.1.2
markdown-it-py: 2.2.0
markupsafe: 2.1.3
matplotlib: 3.7.1
mdit-py-plugins: 0.3.3
numpy: 1.23.5
orjson: 3.9.5
packaging: 23.1
pandas: 1.5.3
pillow: 9.4.0
pydantic: 2.2.0
pydub: 0.25.1
python-multipart: 0.0.6
pyyaml: 6.0.1
requests: 2.31.0
semantic-version: 2.10.0
typing-extensions: 4.7.1
uvicorn: 0.23.2
websockets: 11.0.3
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2023.6.0
httpx: 0.24.1
huggingface-hub: 0.16.4
packaging: 23.1
requests: 2.31.0
typing-extensions: 4.7.1
websockets: 11.0.3

Severity

I can work around it

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions