gradio/demo/diff_texts/run.py
pngwn 068132836c
Style updates (#1350)
* clean up python style api

* allow Box to be styled

* changes

* update style args and add md doc detailing

* cleanup

* add deprecation warnings

* fix

* formatting
2022-06-01 18:02:18 +01:00

35 lines
752 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,
).style(color_map={"+": "red", "-": "green"}),
)
if __name__ == "__main__":
demo.launch()