From 567c6530d844fc9e3efa7ed800c16714d5423576 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Thu, 14 Sep 2023 21:38:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0NOUGAT=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=92=8C=E9=94=99=E8=AF=AF=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/crazy_utils.py | 13 +++++++++++-- crazy_functions/批量翻译PDF文档_NOUGAT.py | 2 +- request_llm/bridge_chatgpt.py | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crazy_functions/crazy_utils.py b/crazy_functions/crazy_utils.py index 66c53a9..bd2ee3f 100644 --- a/crazy_functions/crazy_utils.py +++ b/crazy_functions/crazy_utils.py @@ -1,6 +1,7 @@ from toolbox import update_ui, get_conf, trimmed_format_exc, get_log_folder import threading import os +import logging def input_clipping(inputs, history, max_token_limit): import numpy as np @@ -714,6 +715,7 @@ class nougat_interface(): def nougat_with_timeout(self, command, cwd, timeout=3600): import subprocess + logging.info('正在执行命令', command) process = subprocess.Popen(command, shell=True, cwd=cwd) try: stdout, stderr = process.communicate(timeout=timeout) @@ -725,13 +727,20 @@ class nougat_interface(): return True - def NOUGAT_parse_pdf(self, fp): + def NOUGAT_parse_pdf(self, fp, chatbot, history): + from toolbox import update_ui_lastest_msg + + yield from update_ui_lastest_msg("正在解析论文, 请稍候。进度:正在排队, 等待线程锁...", + chatbot=chatbot, history=history, delay=0) self.threadLock.acquire() import glob, threading, os from toolbox import get_log_folder, gen_time_str dst = os.path.join(get_log_folder(plugin_name='nougat'), gen_time_str()) os.makedirs(dst) - self.nougat_with_timeout(f'nougat --out "{os.path.abspath(dst)}" "{os.path.abspath(fp)}"', os.getcwd(), timeout=300) + + yield from update_ui_lastest_msg("正在解析论文, 请稍候。进度:正在加载NOUGAT... (提示:首次运行需要花费较长时间下载NOUGAT参数)", + chatbot=chatbot, history=history, delay=0) + self.nougat_with_timeout(f'nougat --out "{os.path.abspath(dst)}" "{os.path.abspath(fp)}"', os.getcwd(), timeout=3600) res = glob.glob(os.path.join(dst,'*.mmd')) if len(res) == 0: self.threadLock.release() diff --git a/crazy_functions/批量翻译PDF文档_NOUGAT.py b/crazy_functions/批量翻译PDF文档_NOUGAT.py index 0e2fb81..2dc15f7 100644 --- a/crazy_functions/批量翻译PDF文档_NOUGAT.py +++ b/crazy_functions/批量翻译PDF文档_NOUGAT.py @@ -100,7 +100,7 @@ def 解析PDF_基于NOUGAT(file_manifest, project_folder, llm_kwargs, plugin_kwa nougat_handle = nougat_interface() for index, fp in enumerate(file_manifest): chatbot.append(["当前进度:", f"正在解析论文,请稍候。(第一次运行时,需要花费较长时间下载NOUGAT参数)"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - fpp = nougat_handle.NOUGAT_parse_pdf(fp) + fpp = yield from nougat_handle.NOUGAT_parse_pdf(fp, chatbot, history) with open(fpp, 'r', encoding='utf8') as f: article_content = f.readlines() diff --git a/request_llm/bridge_chatgpt.py b/request_llm/bridge_chatgpt.py index 6a458f2..3fe854c 100644 --- a/request_llm/bridge_chatgpt.py +++ b/request_llm/bridge_chatgpt.py @@ -128,6 +128,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp yield from update_ui(chatbot=chatbot, history=history, msg="缺少api_key") # 刷新界面 return + user_input = inputs if additional_fn is not None: from core_functional import handle_core_functionality inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot) @@ -138,8 +139,8 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp yield from update_ui(chatbot=chatbot, history=history, msg="等待响应") # 刷新界面 # check mis-behavior - if is_the_upload_folder(raw_input): - chatbot[-1] = (inputs, f"[Local Message] 检测到操作错误!当您上传文档之后,需要点击“函数插件区”按钮进行处理,而不是点击“提交”按钮。") + if is_the_upload_folder(user_input): + chatbot[-1] = (inputs, f"[Local Message] 检测到操作错误!当您上传文档之后,需点击“**函数插件区**”按钮进行处理,请勿点击“提交”按钮或者“基础功能区”按钮。") yield from update_ui(chatbot=chatbot, history=history, msg="正常") # 刷新界面 time.sleep(2)