Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from difflib import Differ
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
def diff_texts(text1, text2):
|
6 |
+
d = Differ()
|
7 |
+
return [
|
8 |
+
(token[2:], token[0] if token[0] != " " else None)
|
9 |
+
for token in d.compare(text1, text2)
|
10 |
+
]
|
11 |
+
|
12 |
+
demo = gr.Interface(
|
13 |
+
diff_texts,
|
14 |
+
[
|
15 |
+
gr.Textbox(
|
16 |
+
label="Text 1",
|
17 |
+
info="Initial text",
|
18 |
+
lines=3,
|
19 |
+
value="The quick brown fox jumped over the lazy dogs.",
|
20 |
+
),
|
21 |
+
gr.Textbox(
|
22 |
+
label="Text 2",
|
23 |
+
info="Text to compare",
|
24 |
+
lines=3,
|
25 |
+
value="The fast brown fox jumps over lazy dogs.",
|
26 |
+
),
|
27 |
+
],
|
28 |
+
gr.HighlightedText(
|
29 |
+
label="Diff",
|
30 |
+
combine_adjacent=True,
|
31 |
+
show_legend=True,
|
32 |
+
color_map={"+": "red", "-": "green"}),
|
33 |
+
theme=gr.themes.Base()
|
34 |
+
)
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch()
|