Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow interactive input in
gr.HighlightedText
(#5400)
* add preprocess param to highlighted_text.py * add params * static tweaks * add interactive highlight container * highlight selection logic * allow editing label value and move shared funcs * add changeset * remove py code * wait for input render * remove redundant event listeners * accessibility enhancements and remove label logic * add keyboard navigation and interaction * merge adjacent empty elements and split input element * add interactive support for scores mode * remove merge adjacent logic and move to frontend * tweak * add changeset * format backend * tweaks * backend test tweaks * set the interactive default to None * BE tweak * unit tests and stories * be formatting * fix label errors * tweak * fix tests * fix tests * fix test --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
- Loading branch information
1 parent
05715f5
commit d112e26
Showing
13 changed files
with
943 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@gradio/app": minor | ||
"@gradio/highlightedtext": minor | ||
"gradio": minor | ||
--- | ||
|
||
feat:Allow interactive input in `gr.HighlightedText` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { test, describe, assert, afterEach } from "vitest"; | ||
import { cleanup, fireEvent, render } from "@gradio/tootils"; | ||
import { setupi18n } from "../app/src/i18n"; | ||
|
||
import HighlightedText from "./interactive"; | ||
import type { LoadingStatus } from "@gradio/statustracker"; | ||
|
||
const loading_status: LoadingStatus = { | ||
eta: 0, | ||
queue_position: 1, | ||
queue_size: 1, | ||
status: "complete" as LoadingStatus["status"], | ||
scroll_to_output: false, | ||
visible: true, | ||
fn_index: 0, | ||
show_progress: "full" | ||
}; | ||
|
||
describe("HighlightedText", () => { | ||
afterEach(() => cleanup()); | ||
|
||
setupi18n(); | ||
|
||
test("renders provided text and labels", async () => { | ||
const { getByText, getByTestId, getAllByText } = await render( | ||
HighlightedText, | ||
{ | ||
loading_status, | ||
value: [ | ||
["The", null], | ||
["quick", "adjective"], | ||
[" sneaky", "adjective"], | ||
["fox", "subject"], | ||
[" jumped ", "past tense verb"], | ||
["over the", null], | ||
["lazy dog", "object"] | ||
] | ||
} | ||
); | ||
|
||
const quick = getByText("quick"); | ||
const adjectiveLabels = getAllByText("adjective"); | ||
|
||
assert.exists(quick); | ||
assert.exists(adjectiveLabels); | ||
assert.equal(adjectiveLabels.length, 2); | ||
}); | ||
|
||
test("renders labels with remove label buttons which trigger change", async () => { | ||
const { getAllByText, listen } = await render(HighlightedText, { | ||
loading_status, | ||
value: [ | ||
["The", null], | ||
["quick", "adjective"], | ||
[" sneaky", "adjective"], | ||
["fox", "subject"], | ||
[" jumped ", "past tense verb"], | ||
["over the", null], | ||
["lazy dog", "object"] | ||
] | ||
}); | ||
|
||
const mock = listen("change"); | ||
|
||
const removeButtons = getAllByText("脳"); | ||
|
||
assert.equal(removeButtons.length, 5); | ||
|
||
assert.equal(mock.callCount, 0); | ||
|
||
fireEvent.click(removeButtons[0]); | ||
|
||
assert.equal(mock.callCount, 1); | ||
}); | ||
}); |
Oops, something went wrong.