Spaces:
Sleeping
Sleeping
Merge branch 'master' into v3.1
Browse files- crazy_functions/crazy_utils.py +4 -3
- crazy_functions/批量翻译PDF文档_多线程.py +4 -4
- toolbox.py +1 -1
crazy_functions/crazy_utils.py
CHANGED
@@ -448,6 +448,7 @@ def read_and_clean_pdf_text(fp):
|
|
448 |
pf = 998
|
449 |
for l in t['lines']:
|
450 |
txt_line = "".join([wtf['text'] for wtf in l['spans']])
|
|
|
451 |
pf = primary_ffsize(l)
|
452 |
meta_line.append([txt_line, pf, l['bbox'], l])
|
453 |
for wtf in l['spans']: # for l in t['lines']:
|
@@ -558,8 +559,8 @@ def read_and_clean_pdf_text(fp):
|
|
558 |
meta_txt = meta_txt.replace('\n', '\n\n')
|
559 |
|
560 |
############################## <第 5 步,展示分割效果> ##################################
|
561 |
-
for f in finals:
|
562 |
-
|
563 |
-
|
564 |
|
565 |
return meta_txt, page_one_meta
|
|
|
448 |
pf = 998
|
449 |
for l in t['lines']:
|
450 |
txt_line = "".join([wtf['text'] for wtf in l['spans']])
|
451 |
+
if len(txt_line) == 0: continue
|
452 |
pf = primary_ffsize(l)
|
453 |
meta_line.append([txt_line, pf, l['bbox'], l])
|
454 |
for wtf in l['spans']: # for l in t['lines']:
|
|
|
559 |
meta_txt = meta_txt.replace('\n', '\n\n')
|
560 |
|
561 |
############################## <第 5 步,展示分割效果> ##################################
|
562 |
+
# for f in finals:
|
563 |
+
# print亮黄(f)
|
564 |
+
# print亮绿('***************************')
|
565 |
|
566 |
return meta_txt, page_one_meta
|
crazy_functions/批量翻译PDF文档_多线程.py
CHANGED
@@ -13,7 +13,7 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys_
|
|
13 |
# 基本信息:功能、贡献者
|
14 |
chatbot.append([
|
15 |
"函数插件功能?",
|
16 |
-
"
|
17 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
18 |
|
19 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
@@ -59,7 +59,7 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys_
|
|
59 |
def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, sys_prompt):
|
60 |
import os
|
61 |
import tiktoken
|
62 |
-
TOKEN_LIMIT_PER_FRAGMENT =
|
63 |
generated_conclusion_files = []
|
64 |
for index, fp in enumerate(file_manifest):
|
65 |
|
@@ -91,13 +91,13 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
|
|
91 |
# 多线,翻译
|
92 |
gpt_response_collection = yield from request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
93 |
inputs_array=[
|
94 |
-
f"
|
95 |
inputs_show_user_array=[f"\n---\n 原文: \n\n {frag.replace('#', '')} \n---\n 翻译:\n " for frag in paper_fragments],
|
96 |
llm_kwargs=llm_kwargs,
|
97 |
chatbot=chatbot,
|
98 |
history_array=[[paper_meta] for _ in paper_fragments],
|
99 |
sys_prompt_array=[
|
100 |
-
"
|
101 |
# max_workers=5 # OpenAI所允许的最大并行过载
|
102 |
)
|
103 |
|
|
|
13 |
# 基本信息:功能、贡献者
|
14 |
chatbot.append([
|
15 |
"函数插件功能?",
|
16 |
+
"批量翻译PDF文档。函数插件贡献者: Binary-Husky"])
|
17 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
18 |
|
19 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
|
|
59 |
def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, sys_prompt):
|
60 |
import os
|
61 |
import tiktoken
|
62 |
+
TOKEN_LIMIT_PER_FRAGMENT = 1280
|
63 |
generated_conclusion_files = []
|
64 |
for index, fp in enumerate(file_manifest):
|
65 |
|
|
|
91 |
# 多线,翻译
|
92 |
gpt_response_collection = yield from request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
93 |
inputs_array=[
|
94 |
+
f"你需要翻译以下内容:\n{frag}" for frag in paper_fragments],
|
95 |
inputs_show_user_array=[f"\n---\n 原文: \n\n {frag.replace('#', '')} \n---\n 翻译:\n " for frag in paper_fragments],
|
96 |
llm_kwargs=llm_kwargs,
|
97 |
chatbot=chatbot,
|
98 |
history_array=[[paper_meta] for _ in paper_fragments],
|
99 |
sys_prompt_array=[
|
100 |
+
"请你作为一个学术翻译,负责把学术论文准确翻译成中文。注意文章中的每一句话都要翻译。" for _ in paper_fragments],
|
101 |
# max_workers=5 # OpenAI所允许的最大并行过载
|
102 |
)
|
103 |
|
toolbox.py
CHANGED
@@ -401,7 +401,7 @@ def on_file_uploaded(files, chatbot, txt, txt2, checkboxes):
|
|
401 |
chatbot.append(['我上传了文件,请查收',
|
402 |
f'[Local Message] 收到以下文件: \n\n{moved_files_str}' +
|
403 |
f'\n\n调用路径参数已自动修正到: \n\n{txt}' +
|
404 |
-
f'\n\n
|
405 |
return chatbot, txt, txt2
|
406 |
|
407 |
|
|
|
401 |
chatbot.append(['我上传了文件,请查收',
|
402 |
f'[Local Message] 收到以下文件: \n\n{moved_files_str}' +
|
403 |
f'\n\n调用路径参数已自动修正到: \n\n{txt}' +
|
404 |
+
f'\n\n现在您点击任意“红颜色”标识的函数插件时,以上文件将被作为输入参数'+err_msg])
|
405 |
return chatbot, txt, txt2
|
406 |
|
407 |
|