新版HTML报告页面
This commit is contained in:
		
							parent
							
								
									ea28db855d
								
							
						
					
					
						commit
						4ad432e1da
					
				@ -767,54 +767,6 @@ def try_install_deps(deps, reload_m=[]):
 | 
				
			|||||||
        importlib.reload(__import__(m))
 | 
					        importlib.reload(__import__(m))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HTML_CSS = """
 | 
					 | 
				
			||||||
.row {
 | 
					 | 
				
			||||||
  display: flex;
 | 
					 | 
				
			||||||
  flex-wrap: wrap;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
.column {
 | 
					 | 
				
			||||||
  flex: 1;
 | 
					 | 
				
			||||||
  padding: 10px;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
.table-header {
 | 
					 | 
				
			||||||
  font-weight: bold;
 | 
					 | 
				
			||||||
  border-bottom: 1px solid black;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
.table-row {
 | 
					 | 
				
			||||||
  border-bottom: 1px solid lightgray;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
.table-cell {
 | 
					 | 
				
			||||||
  padding: 5px;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TABLE_CSS = """
 | 
					 | 
				
			||||||
<div class="row table-row">
 | 
					 | 
				
			||||||
    <div class="column table-cell">REPLACE_A</div>
 | 
					 | 
				
			||||||
    <div class="column table-cell">REPLACE_B</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class construct_html():
 | 
					 | 
				
			||||||
    def __init__(self) -> None:
 | 
					 | 
				
			||||||
        self.css = HTML_CSS
 | 
					 | 
				
			||||||
        self.html_string = f'<!DOCTYPE html><head><meta charset="utf-8"><title>翻译结果</title><style>{self.css}</style></head>'
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def add_row(self, a, b):
 | 
					 | 
				
			||||||
        tmp = TABLE_CSS
 | 
					 | 
				
			||||||
        from toolbox import markdown_convertion
 | 
					 | 
				
			||||||
        tmp = tmp.replace('REPLACE_A', markdown_convertion(a))
 | 
					 | 
				
			||||||
        tmp = tmp.replace('REPLACE_B', markdown_convertion(b))
 | 
					 | 
				
			||||||
        self.html_string += tmp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def save_file(self, file_name):
 | 
					 | 
				
			||||||
        with open(os.path.join(get_log_folder(), file_name), 'w', encoding='utf8') as f:
 | 
					 | 
				
			||||||
            f.write(self.html_string.encode('utf-8', 'ignore').decode())
 | 
					 | 
				
			||||||
        return os.path.join(get_log_folder(), file_name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def get_plugin_arg(plugin_kwargs, key, default):
 | 
					def get_plugin_arg(plugin_kwargs, key, default):
 | 
				
			||||||
    # 如果参数是空的
 | 
					    # 如果参数是空的
 | 
				
			||||||
    if (key in plugin_kwargs) and (plugin_kwargs[key] == ""): plugin_kwargs.pop(key)
 | 
					    if (key in plugin_kwargs) and (plugin_kwargs[key] == ""): plugin_kwargs.pop(key)
 | 
				
			||||||
 | 
				
			|||||||
@ -423,7 +423,7 @@ def write_html(sp_file_contents, sp_file_result, chatbot, project_folder):
 | 
				
			|||||||
    # write html
 | 
					    # write html
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        import shutil
 | 
					        import shutil
 | 
				
			||||||
        from ..crazy_utils import construct_html
 | 
					        from crazy_functions.pdf_fns.report_gen_html import construct_html
 | 
				
			||||||
        from toolbox import gen_time_str
 | 
					        from toolbox import gen_time_str
 | 
				
			||||||
        ch = construct_html() 
 | 
					        ch = construct_html() 
 | 
				
			||||||
        orig = ""
 | 
					        orig = ""
 | 
				
			||||||
 | 
				
			|||||||
@ -73,7 +73,7 @@ def produce_report_markdown(gpt_response_collection, meta, paper_meta_info, chat
 | 
				
			|||||||
    return res_path
 | 
					    return res_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def translate_pdf(article_dict, llm_kwargs, chatbot, fp, generated_conclusion_files, TOKEN_LIMIT_PER_FRAGMENT, DST_LANG):
 | 
					def translate_pdf(article_dict, llm_kwargs, chatbot, fp, generated_conclusion_files, TOKEN_LIMIT_PER_FRAGMENT, DST_LANG):
 | 
				
			||||||
    from crazy_functions.crazy_utils import construct_html
 | 
					    from crazy_functions.pdf_fns.report_gen_html import construct_html
 | 
				
			||||||
    from crazy_functions.crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
 | 
					    from crazy_functions.crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
 | 
				
			||||||
    from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
 | 
					    from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
 | 
				
			||||||
    from crazy_functions.crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
 | 
					    from crazy_functions.crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										48
									
								
								crazy_functions/pdf_fns/report_gen_html.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								crazy_functions/pdf_fns/report_gen_html.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					from toolbox import update_ui, get_conf, trimmed_format_exc, get_log_folder
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class construct_html():
 | 
				
			||||||
 | 
					    def __init__(self) -> None:
 | 
				
			||||||
 | 
					        self.html_string = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def add_row(self, a, b):
 | 
				
			||||||
 | 
					        from toolbox import markdown_convertion
 | 
				
			||||||
 | 
					        template = """
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                primary_col: {
 | 
				
			||||||
 | 
					                    header: `__PRIMARY_HEADER__`,
 | 
				
			||||||
 | 
					                    msg: `__PRIMARY_MSG__`,
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                secondary_rol: {
 | 
				
			||||||
 | 
					                    header: `__SECONDARY_HEADER__`,
 | 
				
			||||||
 | 
					                    msg: `__SECONDARY_MSG__`,
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        template_ = template
 | 
				
			||||||
 | 
					        if len(a.split('\n')) == 1:
 | 
				
			||||||
 | 
					            template_ = template_.replace("__PRIMARY_HEADER__", markdown_convertion(a[:10]) + ' ...')
 | 
				
			||||||
 | 
					            template_ = template_.replace("__PRIMARY_MSG__", markdown_convertion(a))
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            template_ = template_.replace("__PRIMARY_HEADER__", markdown_convertion(a.split('\n')[0]))
 | 
				
			||||||
 | 
					            template_ = template_.replace("__PRIMARY_MSG__", markdown_convertion('\n'.join(a.split('\n')[1:])))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if len(b.split('\n')) == 1:
 | 
				
			||||||
 | 
					            template_ = template_.replace("__SECONDARY_HEADER__", markdown_convertion(b[:10]) + ' ...')
 | 
				
			||||||
 | 
					            template_ = template_.replace("__SECONDARY_MSG__", markdown_convertion(b))
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            template_ = template_.replace("__SECONDARY_HEADER__", markdown_convertion(b.split('\n')[0]))
 | 
				
			||||||
 | 
					            template_ = template_.replace("__SECONDARY_MSG__", markdown_convertion('\n'.join(b.split('\n')[1:])))
 | 
				
			||||||
 | 
					        self.html_string += template_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def save_file(self, file_name):
 | 
				
			||||||
 | 
					        from toolbox import get_log_folder
 | 
				
			||||||
 | 
					        with open('crazy_functions/pdf_fns/report_template.html', 'r', encoding='utf8') as f:
 | 
				
			||||||
 | 
					            html_template = f.read()
 | 
				
			||||||
 | 
					        html_template = html_template.replace("__TF_ARR__", self.html_string)
 | 
				
			||||||
 | 
					        with open(os.path.join(get_log_folder(), file_name), 'w', encoding='utf8') as f:
 | 
				
			||||||
 | 
					            f.write(html_template.encode('utf-8', 'ignore').decode())
 | 
				
			||||||
 | 
					        return os.path.join(get_log_folder(), file_name)
 | 
				
			||||||
							
								
								
									
										104
									
								
								crazy_functions/pdf_fns/report_template.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								crazy_functions/pdf_fns/report_template.html
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -97,7 +97,8 @@ def 解析PDF_基于NOUGAT(file_manifest, project_folder, llm_kwargs, plugin_kwa
 | 
				
			|||||||
    generated_conclusion_files = []
 | 
					    generated_conclusion_files = []
 | 
				
			||||||
    generated_html_files = []
 | 
					    generated_html_files = []
 | 
				
			||||||
    DST_LANG = "中文"
 | 
					    DST_LANG = "中文"
 | 
				
			||||||
    from crazy_functions.crazy_utils import nougat_interface, construct_html
 | 
					    from crazy_functions.crazy_utils import nougat_interface
 | 
				
			||||||
 | 
					    from crazy_functions.pdf_fns.report_gen_html import construct_html
 | 
				
			||||||
    nougat_handle = nougat_interface()
 | 
					    nougat_handle = nougat_interface()
 | 
				
			||||||
    for index, fp in enumerate(file_manifest):
 | 
					    for index, fp in enumerate(file_manifest):
 | 
				
			||||||
        chatbot.append(["当前进度:", f"正在解析论文,请稍候。(第一次运行时,需要花费较长时间下载NOUGAT参数)"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
 | 
					        chatbot.append(["当前进度:", f"正在解析论文,请稍候。(第一次运行时,需要花费较长时间下载NOUGAT参数)"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
 | 
				
			||||||
 | 
				
			|||||||
@ -63,7 +63,7 @@ def 解析PDF_基于GROBID(file_manifest, project_folder, llm_kwargs, plugin_kwa
 | 
				
			|||||||
    generated_conclusion_files = []
 | 
					    generated_conclusion_files = []
 | 
				
			||||||
    generated_html_files = []
 | 
					    generated_html_files = []
 | 
				
			||||||
    DST_LANG = "中文"
 | 
					    DST_LANG = "中文"
 | 
				
			||||||
    from crazy_functions.crazy_utils import construct_html
 | 
					    from crazy_functions.pdf_fns.report_gen_html import construct_html
 | 
				
			||||||
    for index, fp in enumerate(file_manifest):
 | 
					    for index, fp in enumerate(file_manifest):
 | 
				
			||||||
        chatbot.append(["当前进度:", f"正在连接GROBID服务,请稍候: {grobid_url}\n如果等待时间过长,请修改config中的GROBID_URL,可修改成本地GROBID服务。"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
 | 
					        chatbot.append(["当前进度:", f"正在连接GROBID服务,请稍候: {grobid_url}\n如果等待时间过长,请修改config中的GROBID_URL,可修改成本地GROBID服务。"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
 | 
				
			||||||
        article_dict = parse_pdf(fp, grobid_url)
 | 
					        article_dict = parse_pdf(fp, grobid_url)
 | 
				
			||||||
@ -86,7 +86,7 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
 | 
				
			|||||||
    TOKEN_LIMIT_PER_FRAGMENT = 1024
 | 
					    TOKEN_LIMIT_PER_FRAGMENT = 1024
 | 
				
			||||||
    generated_conclusion_files = []
 | 
					    generated_conclusion_files = []
 | 
				
			||||||
    generated_html_files = []
 | 
					    generated_html_files = []
 | 
				
			||||||
    from crazy_functions.crazy_utils import construct_html
 | 
					    from crazy_functions.pdf_fns.report_gen_html import construct_html
 | 
				
			||||||
    for index, fp in enumerate(file_manifest):
 | 
					    for index, fp in enumerate(file_manifest):
 | 
				
			||||||
        # 读取PDF文件
 | 
					        # 读取PDF文件
 | 
				
			||||||
        file_content, page_one = read_and_clean_pdf_text(fp)
 | 
					        file_content, page_one = read_and_clean_pdf_text(fp)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user