gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.41k stars 2.52k forks source link

Input in HighlightedText #2444

Closed shahbuland closed 1 year ago

shahbuland commented 2 years ago

Is your feature request related to a problem? Please describe.
As it stands highlighted text can only be used for output (i.e. in case of demonstrating a NER model). There could be a lot of use to adding interactivity to it. i.e. allowing users to highlight text and add labels/comments to it (similar to inline comments in a google doc).

Describe the solution you'd like
The ability to make HighlightedText interactive, such that a user can highlight text and click a button to write a label/comment for their highlighted text.

Additional context
I'm working on CHEESE, a labeling/evaluation/HITL platform that runs primarily off gradio. Having this kind of feature would allow us to add NER labelling tasks or generally any task that could make use of inline labels/comments.

abidlabs commented 2 years ago

Hi @shahbuland thanks for creating the issue! We've talked a little bit about this internally but haven't had a chance to implement. I do think this would be a good addition to the library to work on in the next few weeks. @dawoodkhan82 thoughts on this?

gsarti commented 1 year ago

Any update on this? I'd also be interested in allowing users to highlight text

abidlabs commented 1 year ago

For anyone who is interested, this is now easily possible! Here's a code snippet:

import gradio as gr

with gr.Blocks() as demo:
    h1 = gr.HighlightedText([("Hello my name is ", None), ("Abubakar", "PER"), (" and I live in ", None), ("Palo Alto", "LOC")], interactive=True)
    h2 = gr.HighlightedText()
    h1.change(lambda x:x, h1, h2)

demo.launch()
gsarti commented 1 year ago

Amazing, thank you for the update @abidlabs! I am trying to hide labels using the following code, but it doesn't seem to work as intended:

import gradio as gr

with gr.Blocks() as demo:
    h1 = gr.HighlightedText(
        [("Hello my name is ", None), ("Abubakar", "PER"), (" and I live in ", None), ("Palo Alto", "LOC")],
        interactive=True,
        show_label=False
    )

demo.launch()

At the moment labels are shown by default, and users are prompted to set the label upon adding it. Is there a way to set a single default label that will not be visible to the user? (i.e. simple highlighting)

abidlabs commented 1 year ago

Hi @gsarti not exactly -- the purpose of the gr.HighlightedText component is for named-entity recognition, where you usually have multiple entities. However, you could get something like what you're describing by setting show_legend=True in which case the label appears in a legend and not next to each word:

import gradio as gr

with gr.Blocks() as demo:
    h1 = gr.HighlightedText(
        [("Hello my name is ", None), ("Abubakar", "label"), (" and I live in ", None), ("Palo Alto", "label")],
        interactive=True,
        show_legend=True
    )

demo.launch()

which produces:

image

I don't think its exactly what you're describing, but we're working on making it possible for Gradio users to create their own custom components -- meaning that you'll be able to take an existing Gradio component and clone it, modify the backend or the frontend, and use it in your Gradio apps. This should hopefully help solve this use case!