gradio/demo/diff_texts/run.py
aliabid94 5fc00b4567
Automatic word-break in highlighted text, combine_adjacent support (#1209)
* changes

* changes

* updated PyPi version to 2.9b26

* changes

* css tweaks (#1213)

* css tweaks

* more tweaks

* fix lint error

Co-authored-by: pngwn <hello@pngwn.io>
2022-05-11 20:09:25 +01:00

32 lines
685 B
Python

from difflib import Differ
import gradio as gr
def diff_texts(text1, text2):
d = Differ()
return [
(token[2:], token[0] if token[0] != " " else None)
for token in d.compare(text1, text2)
]
demo = gr.Interface(
diff_texts,
[
gr.Textbox(
label="Initial text",
lines=3,
value="The quick brown fox jumped over the lazy dogs.",
),
gr.Textbox(
label="Text to compare",
lines=3,
value="The fast brown fox jumps over lazy dogs.",
),
],
gr.HighlightedText(label="Diff", combine_adjacent=True),
)
if __name__ == "__main__":
demo.launch()