Spaces:
Runtime error
Runtime error
Latex全文润色
Browse files- check_proxy.py +1 -1
- config.py +1 -1
- crazy_functional.py +14 -0
- crazy_functions/Latex全文润色.py +144 -34
- crazy_functions/crazy_utils.py +7 -3
- crazy_functions/批量翻译PDF文档_多线程.py +3 -5
- crazy_functions/解析项目源代码.py +4 -2
- theme.py +2 -0
- version +1 -1
check_proxy.py
CHANGED
@@ -72,7 +72,7 @@ def patch_and_restart(path):
|
|
72 |
time.sleep(1)
|
73 |
print(i)
|
74 |
print(' ------------------------------ -----------------------------------')
|
75 |
-
os.execl(sys.executable,
|
76 |
|
77 |
|
78 |
def get_current_version():
|
|
|
72 |
time.sleep(1)
|
73 |
print(i)
|
74 |
print(' ------------------------------ -----------------------------------')
|
75 |
+
os.execl(sys.executable, *sys.argv)
|
76 |
|
77 |
|
78 |
def get_current_version():
|
config.py
CHANGED
@@ -31,7 +31,7 @@ CODE_HIGHLIGHT = True
|
|
31 |
LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布局)
|
32 |
|
33 |
# 发送请求到OpenAI后,等待多久判定为超时
|
34 |
-
TIMEOUT_SECONDS =
|
35 |
|
36 |
# 网页的端口, -1代表随机端口
|
37 |
WEB_PORT = -1
|
|
|
31 |
LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布局)
|
32 |
|
33 |
# 发送请求到OpenAI后,等待多久判定为超时
|
34 |
+
TIMEOUT_SECONDS = 30
|
35 |
|
36 |
# 网页的端口, -1代表随机端口
|
37 |
WEB_PORT = -1
|
crazy_functional.py
CHANGED
@@ -76,6 +76,8 @@ def get_crazy_functions():
|
|
76 |
from crazy_functions.谷歌检索小助手 import 谷歌检索小助手
|
77 |
from crazy_functions.理解PDF文档内容 import 理解PDF文档内容
|
78 |
from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入
|
|
|
|
|
79 |
|
80 |
function_plugins.update({
|
81 |
"批量翻译PDF文档(多线程)": {
|
@@ -114,6 +116,18 @@ def get_crazy_functions():
|
|
114 |
"AsButton": False, # 加入下拉菜单中
|
115 |
"Function": HotReload(理解PDF文档内容标准文件输入)
|
116 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
})
|
118 |
|
119 |
###################### 第三组插件 ###########################
|
|
|
76 |
from crazy_functions.谷歌检索小助手 import 谷歌检索小助手
|
77 |
from crazy_functions.理解PDF文档内容 import 理解PDF文档内容
|
78 |
from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入
|
79 |
+
from crazy_functions.Latex全文润色 import Latex英文润色
|
80 |
+
from crazy_functions.Latex全文润色 import Latex中文润色
|
81 |
|
82 |
function_plugins.update({
|
83 |
"批量翻译PDF文档(多线程)": {
|
|
|
116 |
"AsButton": False, # 加入下拉菜单中
|
117 |
"Function": HotReload(理解PDF文档内容标准文件输入)
|
118 |
},
|
119 |
+
"英文Latex项目全文润色(输入路径或上传压缩包)": {
|
120 |
+
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
121 |
+
"Color": "stop",
|
122 |
+
"AsButton": False, # 加入下拉菜单中
|
123 |
+
"Function": HotReload(Latex英文润色)
|
124 |
+
},
|
125 |
+
# "中文Latex项目全文润色(输入路径或上传压缩包)": {
|
126 |
+
# # HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
127 |
+
# "Color": "stop",
|
128 |
+
# "AsButton": False, # 加入下拉菜单中
|
129 |
+
# "Function": HotReload(Latex中文润色)
|
130 |
+
# },
|
131 |
})
|
132 |
|
133 |
###################### 第三组插件 ###########################
|
crazy_functions/Latex全文润色.py
CHANGED
@@ -2,51 +2,163 @@ from toolbox import update_ui
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
def 解析Paper(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt):
|
7 |
-
import time, glob, os
|
8 |
-
print('begin analysis on:', file_manifest)
|
9 |
for index, fp in enumerate(file_manifest):
|
10 |
with open(fp, 'r', encoding='utf-8') as f:
|
11 |
file_content = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
chatbot[-1] = (i_say_show_user, gpt_say)
|
25 |
-
history.append(i_say_show_user); history.append(gpt_say)
|
26 |
-
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg) # 刷新界面
|
27 |
-
if not fast_debug: time.sleep(2)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
33 |
|
34 |
-
if not fast_debug:
|
35 |
-
msg = '正常'
|
36 |
-
# ** gpt request **
|
37 |
-
gpt_say = yield from predict_no_ui_but_counting_down(i_say, i_say, chatbot, llm_kwargs, plugin_kwargs, history=history) # 带超时倒计时
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
|
48 |
@CatchException
|
49 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
history = [] # 清空历史,以免输入溢出
|
51 |
import glob, os
|
52 |
if os.path.exists(txt):
|
@@ -56,11 +168,9 @@ def 读文章写摘要(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_
|
|
56 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
57 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
58 |
return
|
59 |
-
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
|
60 |
-
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
|
61 |
-
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
|
62 |
if len(file_manifest) == 0:
|
63 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
64 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
65 |
return
|
66 |
-
yield from
|
|
|
2 |
from toolbox import CatchException, report_execption, write_results_to_file, predict_no_ui_but_counting_down
|
3 |
fast_debug = False
|
4 |
|
5 |
+
class PaperFileGroup():
|
6 |
+
def __init__(self):
|
7 |
+
self.file_paths = []
|
8 |
+
self.file_contents = []
|
9 |
+
self.sp_file_contents = []
|
10 |
+
self.sp_file_index = []
|
11 |
+
self.sp_file_tag = []
|
12 |
+
|
13 |
+
# count_token
|
14 |
+
import tiktoken
|
15 |
+
from toolbox import get_conf
|
16 |
+
enc = tiktoken.encoding_for_model(*get_conf('LLM_MODEL'))
|
17 |
+
def get_token_num(txt): return len(enc.encode(txt))
|
18 |
+
self.get_token_num = get_token_num
|
19 |
+
|
20 |
+
def run_file_split(self, max_token_limit=1900):
|
21 |
+
"""
|
22 |
+
将长文本分离开来
|
23 |
+
"""
|
24 |
+
for index, file_content in enumerate(self.file_contents):
|
25 |
+
if self.get_token_num(file_content) < max_token_limit:
|
26 |
+
self.sp_file_contents.append(file_content)
|
27 |
+
self.sp_file_index.append(index)
|
28 |
+
self.sp_file_tag.append(self.file_paths[index])
|
29 |
+
else:
|
30 |
+
from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
|
31 |
+
segments = breakdown_txt_to_satisfy_token_limit_for_pdf(file_content, self.get_token_num, max_token_limit)
|
32 |
+
for j, segment in enumerate(segments):
|
33 |
+
self.sp_file_contents.append(segment)
|
34 |
+
self.sp_file_index.append(index)
|
35 |
+
self.sp_file_tag.append(self.file_paths[index] + f".part-{j}.tex")
|
36 |
+
|
37 |
+
print('Segmentation: done')
|
38 |
+
|
39 |
+
def 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en'):
|
40 |
+
import time, os, re
|
41 |
+
from .crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
|
42 |
+
|
43 |
+
|
44 |
+
# <-------- 读取Latex文件,删除其中的所有注释 ---------->
|
45 |
+
pfg = PaperFileGroup()
|
46 |
|
|
|
|
|
|
|
47 |
for index, fp in enumerate(file_manifest):
|
48 |
with open(fp, 'r', encoding='utf-8') as f:
|
49 |
file_content = f.read()
|
50 |
+
# 定义注释的正则表达式
|
51 |
+
comment_pattern = r'%.*'
|
52 |
+
# 使用正则表达式查找注释,并替换为空字符串
|
53 |
+
clean_tex_content = re.sub(comment_pattern, '', file_content)
|
54 |
+
# 记录删除注释后的文本
|
55 |
+
pfg.file_paths.append(fp)
|
56 |
+
pfg.file_contents.append(clean_tex_content)
|
57 |
|
58 |
+
# <-------- 拆分过长的latex文件 ---------->
|
59 |
+
pfg.run_file_split(max_token_limit=1024)
|
60 |
+
n_split = len(pfg.sp_file_contents)
|
61 |
+
|
62 |
+
# <-------- 抽取摘要 ---------->
|
63 |
+
# if language == 'en':
|
64 |
+
# abs_extract_inputs = f"Please write an abstract for this paper"
|
65 |
+
|
66 |
+
# # 单线,获取文章meta信息
|
67 |
+
# paper_meta_info = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
68 |
+
# inputs=abs_extract_inputs,
|
69 |
+
# inputs_show_user=f"正在抽取摘要信息。",
|
70 |
+
# llm_kwargs=llm_kwargs,
|
71 |
+
# chatbot=chatbot, history=[],
|
72 |
+
# sys_prompt="Your job is to collect information from materials。",
|
73 |
+
# )
|
74 |
|
75 |
+
# <-------- 多线程润色开始(第一次) ---------->
|
76 |
+
if language == 'en':
|
77 |
+
inputs_array = [f"Below is an academic paper, polish the writing to meet the academic style, "+
|
78 |
+
f"improve the spelling, grammar, clarity, concision and overall readability. " +
|
79 |
+
f"The paper begins now: \n{frag}" for frag in pfg.sp_file_contents]
|
80 |
+
inputs_show_user_array = [f"Polish {f}" for f in pfg.sp_file_tag]
|
81 |
+
sys_prompt_array = ["You are a professional academic paper writer." for _ in range(n_split)]
|
82 |
+
elif language == 'zh':
|
83 |
+
inputs_array = [f"这里有一个使用Latex格式的学术论文,请把写作风格要求的学术风格进行润色,改进拼写、语法、清晰度、简洁度和整体可读性。" +
|
84 |
+
f"论文现在开始:\n{frag}" for frag in pfg.sp_file_contents]
|
85 |
+
inputs_show_user_array = [f"润色 {f}" for f in pfg.sp_file_tag]
|
86 |
+
sys_prompt_array=["你是一位专业的学术论文作家。润色以下论文。输出中保留Latex格式。" for _ in range(n_split)]
|
87 |
|
|
|
|
|
|
|
|
|
88 |
|
89 |
+
gpt_response_collection = yield from request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
90 |
+
inputs_array=inputs_array,
|
91 |
+
inputs_show_user_array=inputs_show_user_array,
|
92 |
+
llm_kwargs=llm_kwargs,
|
93 |
+
chatbot=chatbot,
|
94 |
+
history_array=[[""] for _ in range(n_split)],
|
95 |
+
sys_prompt_array=sys_prompt_array,
|
96 |
+
max_workers=10, # OpenAI所允许的最大并行过载
|
97 |
+
scroller_max_len = 80
|
98 |
+
)
|
99 |
+
|
100 |
+
create_report_file_name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + f"-chatgpt.polish.md"
|
101 |
+
res = write_results_to_file(gpt_response_collection, file_name=create_report_file_name)
|
102 |
+
history = gpt_response_collection
|
103 |
+
chatbot.append((f"{fp}完成了吗?", res))
|
104 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
105 |
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
@CatchException
|
108 |
+
def Latex英文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
109 |
+
# 基本信息:功能、贡献者
|
110 |
+
chatbot.append([
|
111 |
+
"函数插件功能?",
|
112 |
+
"对整个Latex项目进行润色。函数插件贡献者: Binary-Husky"])
|
113 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
114 |
+
|
115 |
+
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
116 |
+
try:
|
117 |
+
import tiktoken
|
118 |
+
except:
|
119 |
+
report_execption(chatbot, history,
|
120 |
+
a=f"解析项目: {txt}",
|
121 |
+
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
|
122 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
123 |
+
return
|
124 |
+
history = [] # 清空历史,以免输入溢出
|
125 |
+
import glob, os
|
126 |
+
if os.path.exists(txt):
|
127 |
+
project_folder = txt
|
128 |
+
else:
|
129 |
+
if txt == "": txt = '空空如也的输入栏'
|
130 |
+
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
131 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
132 |
+
return
|
133 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
|
134 |
+
if len(file_manifest) == 0:
|
135 |
+
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
136 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
137 |
+
return
|
138 |
+
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en')
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
|
143 |
|
144 |
|
145 |
@CatchException
|
146 |
+
def Latex中文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
147 |
+
# 基本信息:功能、贡献者
|
148 |
+
chatbot.append([
|
149 |
+
"函数插件功能?",
|
150 |
+
"对整个Latex项目进行润色。函数插件贡献者: Binary-Husky"])
|
151 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
152 |
+
|
153 |
+
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
154 |
+
try:
|
155 |
+
import tiktoken
|
156 |
+
except:
|
157 |
+
report_execption(chatbot, history,
|
158 |
+
a=f"解析项目: {txt}",
|
159 |
+
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
|
160 |
+
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
161 |
+
return
|
162 |
history = [] # 清空历史,以免输入溢出
|
163 |
import glob, os
|
164 |
if os.path.exists(txt):
|
|
|
168 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
169 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
170 |
return
|
171 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
|
|
|
|
|
172 |
if len(file_manifest) == 0:
|
173 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
|
174 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
175 |
return
|
176 |
+
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh')
|
crazy_functions/crazy_utils.py
CHANGED
@@ -80,7 +80,7 @@ def request_gpt_model_in_new_thread_with_ui_alive(
|
|
80 |
history=history, sys_prompt=sys_prompt, observe_window=mutable)
|
81 |
return result
|
82 |
except ConnectionAbortedError as token_exceeded_error:
|
83 |
-
# 【第二种情况】:Token
|
84 |
if handle_token_exceed:
|
85 |
exceeded_cnt += 1
|
86 |
# 【选择处理】 尝试计算比例,尽可能多地保留文本
|
@@ -97,7 +97,7 @@ def request_gpt_model_in_new_thread_with_ui_alive(
|
|
97 |
mutable[0] += f"[Local Message] 警告,在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
98 |
return mutable[0] # 放弃
|
99 |
except:
|
100 |
-
#
|
101 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
102 |
mutable[0] += f"[Local Message] 警告,在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
103 |
if retry_op > 0:
|
@@ -119,7 +119,11 @@ def request_gpt_model_in_new_thread_with_ui_alive(
|
|
119 |
break
|
120 |
chatbot[-1] = [chatbot[-1][0], mutable[0]]
|
121 |
yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面
|
122 |
-
|
|
|
|
|
|
|
|
|
123 |
|
124 |
|
125 |
def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
|
|
80 |
history=history, sys_prompt=sys_prompt, observe_window=mutable)
|
81 |
return result
|
82 |
except ConnectionAbortedError as token_exceeded_error:
|
83 |
+
# 【第二种情况】:Token溢出
|
84 |
if handle_token_exceed:
|
85 |
exceeded_cnt += 1
|
86 |
# 【选择处理】 尝试计算比例,尽可能多地保留文本
|
|
|
97 |
mutable[0] += f"[Local Message] 警告,在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
98 |
return mutable[0] # 放弃
|
99 |
except:
|
100 |
+
# 【第三种情况】:其他错误:重试几次
|
101 |
tb_str = '```\n' + traceback.format_exc() + '```'
|
102 |
mutable[0] += f"[Local Message] 警告,在执行过程中遭遇问题, Traceback:\n\n{tb_str}\n\n"
|
103 |
if retry_op > 0:
|
|
|
119 |
break
|
120 |
chatbot[-1] = [chatbot[-1][0], mutable[0]]
|
121 |
yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面
|
122 |
+
|
123 |
+
final_result = future.result()
|
124 |
+
chatbot[-1] = [chatbot[-1][0], final_result]
|
125 |
+
yield from update_ui(chatbot=chatbot, history=[]) # 如果最后成功了,则删除报错信息
|
126 |
+
return final_result
|
127 |
|
128 |
|
129 |
def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
|
crazy_functions/批量翻译PDF文档_多线程.py
CHANGED
@@ -96,7 +96,7 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys_
|
|
96 |
# 基本信息:功能、贡献者
|
97 |
chatbot.append([
|
98 |
"函数插件功能?",
|
99 |
-
"批量总结PDF文档。函数插件贡献者: Binary-Husky
|
100 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
101 |
|
102 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
@@ -185,11 +185,9 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
|
|
185 |
final.extend(gpt_response_collection)
|
186 |
create_report_file_name = f"{os.path.basename(fp)}.trans.md"
|
187 |
res = write_results_to_file(final, file_name=create_report_file_name)
|
188 |
-
generated_conclusion_files.append(
|
189 |
-
f'./gpt_log/{create_report_file_name}')
|
190 |
chatbot.append((f"{fp}完成了吗?", res))
|
191 |
-
|
192 |
-
yield from update_ui(chatbot=chatbot, history=chatbot, msg=msg) # 刷新界面
|
193 |
|
194 |
# 准备文件的下载
|
195 |
import shutil
|
|
|
96 |
# 基本信息:功能、贡献者
|
97 |
chatbot.append([
|
98 |
"函数插件功能?",
|
99 |
+
"批量总结PDF文档。函数插件贡献者: Binary-Husky"])
|
100 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
101 |
|
102 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
|
|
185 |
final.extend(gpt_response_collection)
|
186 |
create_report_file_name = f"{os.path.basename(fp)}.trans.md"
|
187 |
res = write_results_to_file(final, file_name=create_report_file_name)
|
188 |
+
generated_conclusion_files.append(f'./gpt_log/{create_report_file_name}')
|
|
|
189 |
chatbot.append((f"{fp}完成了吗?", res))
|
190 |
+
yield from update_ui(chatbot=chatbot, history=chatbot) # 刷新界面
|
|
|
191 |
|
192 |
# 准备文件的下载
|
193 |
import shutil
|
crazy_functions/解析项目源代码.py
CHANGED
@@ -45,6 +45,7 @@ def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs,
|
|
45 |
batchsize = 16 # 10个文件为一组
|
46 |
report_part_2 = []
|
47 |
previous_iteration_files = []
|
|
|
48 |
while True:
|
49 |
if len(file_manifest) == 0: break
|
50 |
this_iteration_file_manifest = file_manifest[:batchsize]
|
@@ -59,12 +60,13 @@ def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs,
|
|
59 |
i_say = f'根据以上分析,对程序的整体功能和构架重新做出概括。然后用一张markdown表格整理每个文件的功能(包括{previous_iteration_files_string})。'
|
60 |
inputs_show_user = f'根据以上分析,对程序的整体功能和构架重新做出概括,由于输入长度限制,可能需要分组处理,本组文件为 {current_iteration_focus} + 已经汇总的文件组。'
|
61 |
this_iteration_history = copy.deepcopy(this_iteration_gpt_response_collection)
|
62 |
-
this_iteration_history.extend(
|
63 |
result = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
64 |
inputs=i_say, inputs_show_user=inputs_show_user, llm_kwargs=llm_kwargs, chatbot=chatbot,
|
65 |
history=this_iteration_history, # 迭代之前的分析
|
66 |
-
sys_prompt="
|
67 |
report_part_2.extend([i_say, result])
|
|
|
68 |
|
69 |
file_manifest = file_manifest[batchsize:]
|
70 |
gpt_response_collection = gpt_response_collection[batchsize*2:]
|
|
|
45 |
batchsize = 16 # 10个文件为一组
|
46 |
report_part_2 = []
|
47 |
previous_iteration_files = []
|
48 |
+
last_iteration_result = ""
|
49 |
while True:
|
50 |
if len(file_manifest) == 0: break
|
51 |
this_iteration_file_manifest = file_manifest[:batchsize]
|
|
|
60 |
i_say = f'根据以上分析,对程序的整体功能和构架重新做出概括。然后用一张markdown表格整理每个文件的功能(包括{previous_iteration_files_string})。'
|
61 |
inputs_show_user = f'根据以上分析,对程序的整体功能和构架重新做出概括,由于输入长度限制,可能需要分组处理,本组文件为 {current_iteration_focus} + 已经汇总的文件组。'
|
62 |
this_iteration_history = copy.deepcopy(this_iteration_gpt_response_collection)
|
63 |
+
this_iteration_history.extend(last_iteration_result)
|
64 |
result = yield from request_gpt_model_in_new_thread_with_ui_alive(
|
65 |
inputs=i_say, inputs_show_user=inputs_show_user, llm_kwargs=llm_kwargs, chatbot=chatbot,
|
66 |
history=this_iteration_history, # 迭代之前的分析
|
67 |
+
sys_prompt="你是一个程序架构分析师,正在分析一个项目的源代码。")
|
68 |
report_part_2.extend([i_say, result])
|
69 |
+
last_iteration_result = result
|
70 |
|
71 |
file_manifest = file_manifest[batchsize:]
|
72 |
gpt_response_collection = gpt_response_collection[batchsize*2:]
|
theme.py
CHANGED
@@ -154,10 +154,12 @@ advanced_css = """
|
|
154 |
padding: 1em;
|
155 |
margin: 1em 2em 1em 0.5em;
|
156 |
}
|
|
|
157 |
"""
|
158 |
|
159 |
if CODE_HIGHLIGHT:
|
160 |
advanced_css += """
|
|
|
161 |
.hll { background-color: #ffffcc }
|
162 |
.c { color: #3D7B7B; font-style: italic } /* Comment */
|
163 |
.err { border: 1px solid #FF0000 } /* Error */
|
|
|
154 |
padding: 1em;
|
155 |
margin: 1em 2em 1em 0.5em;
|
156 |
}
|
157 |
+
|
158 |
"""
|
159 |
|
160 |
if CODE_HIGHLIGHT:
|
161 |
advanced_css += """
|
162 |
+
|
163 |
.hll { background-color: #ffffcc }
|
164 |
.c { color: #3D7B7B; font-style: italic } /* Comment */
|
165 |
.err { border: 1px solid #FF0000 } /* Error */
|
version
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
{
|
2 |
"version": 2.6,
|
3 |
"show_feature": true,
|
4 |
-
"new_feature": "增强多线程稳定性(涉及代码解析、PDF
|
5 |
}
|
|
|
1 |
{
|
2 |
"version": 2.6,
|
3 |
"show_feature": true,
|
4 |
+
"new_feature": "现可通过输入区更新临时api-key <-> 增强多线程稳定性(涉及代码解析、PDF翻译等) <-> 修复Token计数错误(解决PDF翻译的分割不合理的问题) "
|
5 |
}
|