gradio/demo/diff_texts.py

29 lines
614 B
Python
Raw Normal View History

2020-08-22 05:20:05 +08:00
# Demo: (Textbox, Textbox) -> (HighlightedText)
2020-08-20 05:27:22 +08:00
import gradio as gr
from difflib import Differ
2020-08-28 23:56:03 +08:00
2020-08-20 05:27:22 +08:00
def diff_texts(text1, text2):
d = Differ()
return [
(token[2:], token[0]) for token in d.compare(text1, text2)
]
2020-08-28 23:56:03 +08:00
io = gr.Interface(
2020-08-20 05:27:22 +08:00
diff_texts,
[
gr.inputs.Textbox(lines=3, default="The quick brown fox jumped over the lazy dogs."),
gr.inputs.Textbox(lines=3, default="The fast brown fox jumps over lazy dogs."),
],
gr.outputs.HighlightedText(color_map={
"+": "lightgreen",
"-": "pink",
" ": "none",
})
2020-08-28 23:56:03 +08:00
)
io.test_launch()
io.launch()