[docs]deftext_diff(text1:Union[ModelProto,str],text2:Union[ModelProto,str])->str:""" Produces a string showing the differences between two strings. :param text1: first string :param text2: second string :return: differences """ifnotisinstance(text1,str):from..plotting.text_plotimportonnx_simple_text_plottext1=onnx_simple_text_plot(text1,indent=False)ifnotisinstance(text2,str):from..plotting.text_plotimportonnx_simple_text_plottext2=onnx_simple_text_plot(text2,indent=False)differ=difflib.Differ()result=list(differ.compare(text1.splitlines(keepends=True),text2.splitlines(keepends=True)))raw="".join(result)returnraw
[docs]defhtml_diff(text1:Union[ModelProto,str],text2:Union[ModelProto,str],title:str="html_diff",div_name:str="div_name",header:bool=True,)->str:""" Produces a HTML files showing the differences between two strings. :param text1: first string :param text2: second string :param title: title :param div: html format, section name :param header: if True, add header and html main tags :return: differences """raw=text_diff(text1,text2)diff=_get_diff_template().render(title=title,version1=text1,version2=text2,div_name=f"div_{div_name}",diff_content=raw,)returnf"<html><body>\n{diff}\n</body></html>\n"