Co-authored-by: Ali Abid <aliabid94@gmail.com>
This commit is contained in:
aliabid94 2022-04-20 21:43:14 -07:00 committed by GitHub
parent 84cdcf3647
commit 9a62b25bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 25 deletions

View File

@ -14,8 +14,8 @@ def diff_texts(text1, text2):
demo = gr.Interface(
diff_texts,
[
gr.Textbox(lines=3, default="The quick brown fox jumped over the lazy dogs."),
gr.Textbox(lines=3, default="The fast brown fox jumps over lazy dogs."),
gr.Textbox(lines=3, default_value="The quick brown fox jumped over the lazy dogs."),
gr.Textbox(lines=3, default_value="The fast brown fox jumps over lazy dogs."),
],
gr.HighlightedText(),
)

View File

@ -26,34 +26,35 @@
if (color_map === null) {
color_map = {};
}
if (value.length > 0) {
for (let [_, label] of value) {
if (label !== null) {
if (typeof label === "string") {
mode = "categories";
if (!(label in color_map)) {
let color = getNextColor(Object.keys(color_map).length);
color_map[label] = color;
$: {
if (value.length > 0) {
for (let [_, label] of value) {
if (label !== null) {
if (typeof label === "string") {
mode = "categories";
if (!(label in color_map)) {
let color = getNextColor(Object.keys(color_map).length);
color_map[label] = color;
}
} else {
mode = "scores";
}
} else {
mode = "scores";
}
}
}
}
function correct_color_map() {
for (const col in color_map) {
const _c = color_map[col].trim();
if (_c.startsWith("rgba")) {
color_map[col] = color_map[col];
} else {
color_map[col] = name_to_rgba(color_map[col]);
function correct_color_map() {
for (const col in color_map) {
const _c = color_map[col].trim();
if (_c.startsWith("rgba")) {
color_map[col] = color_map[col];
} else {
color_map[col] = name_to_rgba(color_map[col]);
}
}
}
}
correct_color_map();
correct_color_map();
}
</script>
<div class="output-highlightedtext" {theme}>
@ -73,7 +74,7 @@
<div
class="textfield p-2 bg-white dark:bg-gray-800 rounded box-border max-w-full leading-8 break-word"
>
{#each value as [text, category], i}
{#each value as [text, category]}
<span
class="textspan p-1 mr-0.5 bg-opacity-20 dark:bg-opacity-80 rounded-sm"
style={category === null
@ -110,7 +111,7 @@
<div
class="textfield p-2 bg-white dark:bg-gray-800 rounded box-border max-w-full leading-8 break-word"
>
{#each value as [text, score], i}
{#each value as [text, score]}
<span
class="textspan p-1 mr-0.5 bg-opacity-20 dark:bg-opacity-80 rounded-sm"
style={"background-color: rgba(" +