Open gante opened 1 year ago
hi, @gante @abidlabs ! Great issue here! I come across the exact same issue when it comes to continuous labels.
I want to highlight some scores for each sentence in a paragraph. What I'm doing is a trick that convert each float to a string, and replace the key in colormap by the float-string.
Here's a demo:
color_map = {str(k):v for k, v in zip(sentence_scores, hex_colors)}
text_list = [(k, str(v)) for k, v in zip(abstract_sentences, sentence_scores)]
with gr.Blocks() as block:
gr.HighlightedText(text_list, color_map=color_map)
block.launch()
It works well. However, when I want to use other components as inputs, the key issue here is the fixed color_map.
with gr.Blocks() as block:
text_box = gr.Text("some text", interactive=True)
highlighted_text_box = gr.HighlightedText()
def process_text_box(text):
text_list = [(sentence, idx/len(text.strip().split(". "))) for idx, sentence in enumerate(text.strip().split(". "))]
return text_list
text_box.submit(process_text_box, inputs=text_box, outputs=[highlighted_text_box])
block.launch()
Even though the text is highlighted, I couldn't find a way to configure the colormap.
Almost a year later, are there any solutions here to solve this issue, like the .style
method?
Is your feature request related to a problem? Please describe.
A common feature related to models with text generation capabilities is text highlighting according to some specifications, including (but not limited to):
gradio.HighlightedText
kinda does the trick, but it is missing customization :) At the moment, I find it reliable if we discretize the highlighted labels (e.g.), but not with continuous labels.Describe the solution you'd like
My apologies if this already exists, I couldn't find it in the documentation (which would mean the docs need an update if it does exist š). Precisely, I think it is missing two customization options.
.style(color_map=...)
compatible with continuous variables. In a perfect world, matplotlib-like syntax would be accepted, which would enable transparency šAdditionally, I've found a minor issue:
float
-like values will not get highlighted and require an explicitfloat()
cast. In the example below, if you remove the cast, you'll see that it doesn't work. š¤Additional context
See the screenshot and the gradio demo that generates it š