Spaces:
Runtime error
Runtime error
File size: 1,291 Bytes
60fde8d 84395f7 60fde8d 84395f7 60fde8d a0206a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import gradio as gr
import re
def split(lst):
return lst.split(",")
def inters(lst1, lst2):
return list(set(lst1) & set(lst2))
def diff(lst1, lst2):
return list(set(lst1) - set(lst2))
def convert(list, sign):
return [(item, sign) for item in list]
def diff_texts(text1, text2):
input1 = re.findall('袗袚小 (.+?) ', text1)
input2 = re.findall('袗袚小 (.+?) ', text2)
lst1 = input1 or split(text1)
lst2 = input2 or split(text2)
diff1 = convert(diff(lst1, lst2), '-')
diff2 = convert(diff(lst2, lst1), '+')
intrs = convert(inters(lst1, lst2), None)
return diff1 + diff2 + intrs
demo = gr.Interface(
diff_texts,
[
gr.Textbox(
label="Text 1",
info="Initial text",
lines=3,
#value="协校063473,协校063414,孝袨041305",
),
gr.Textbox(
label="Text 2",
info="Text to compare",
lines=3,
#value="协校063443,协校063473,孝袨041384,孝袨041305,协校063414",
),
],
#"textbox",
gr.HighlightedText(
label="Diff",
combine_adjacent=True,
adjacent_separator=", ",
show_legend=True,
color_map={"-": "red", "+": "green"}
),
theme=gr.themes.Base()
)
demo.launch()
|