gradio/demo/diff_texts.py

20 lines
593 B
Python
Raw Normal View History

2020-08-20 05:27:22 +08:00
import gradio as gr
from difflib import Differ
def diff_texts(text1, text2):
d = Differ()
return [
2021-05-24 14:53:30 +08:00
(token[2:], token[0] if token[0] != " " else None) for token in d.compare(text1, text2)
2020-08-20 05:27:22 +08:00
]
2020-08-28 23:56:03 +08:00
2020-11-11 22:15:53 +08:00
iface = gr.Interface(
2020-08-20 05:27:22 +08:00
diff_texts,
[
2021-08-26 05:25:53 +08:00
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."),
2020-08-20 05:27:22 +08:00
],
2021-08-26 05:42:45 +08:00
gr.outputs.HighlightedText(color_map={"+": "lightgreen", "-": "pink", }))
if __name__ == "__main__":
2021-08-26 05:25:53 +08:00
iface.launch()