Spaces:
Running
Running
Markdown翻译支持github url
Browse files- crazy_functional.py +8 -7
- crazy_functions/批量Markdown翻译.py +23 -3
- request_llm/bridge_newbing.py +1 -1
crazy_functional.py
CHANGED
@@ -21,6 +21,7 @@ def get_crazy_functions():
|
|
21 |
from crazy_functions.总结word文档 import 总结word文档
|
22 |
from crazy_functions.解析JupyterNotebook import 解析ipynb文件
|
23 |
from crazy_functions.对话历史存档 import 对话历史存档
|
|
|
24 |
function_plugins = {
|
25 |
|
26 |
"解析整个Python项目": {
|
@@ -81,8 +82,14 @@ def get_crazy_functions():
|
|
81 |
"Color": "stop", # 按钮颜色
|
82 |
"Function": HotReload(读文章写摘要)
|
83 |
},
|
|
|
|
|
|
|
|
|
|
|
84 |
"批量生成函数注释": {
|
85 |
"Color": "stop", # 按钮颜色
|
|
|
86 |
"Function": HotReload(批量生成函数注释)
|
87 |
},
|
88 |
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
@@ -110,7 +117,6 @@ def get_crazy_functions():
|
|
110 |
from crazy_functions.Latex全文翻译 import Latex中译英
|
111 |
from crazy_functions.Latex全文翻译 import Latex英译中
|
112 |
from crazy_functions.批量Markdown翻译 import Markdown中译英
|
113 |
-
from crazy_functions.批量Markdown翻译 import Markdown英译中
|
114 |
|
115 |
function_plugins.update({
|
116 |
"批量翻译PDF文档(多线程)": {
|
@@ -175,12 +181,7 @@ def get_crazy_functions():
|
|
175 |
"AsButton": False, # 加入下拉菜单中
|
176 |
"Function": HotReload(Markdown中译英)
|
177 |
},
|
178 |
-
|
179 |
-
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
180 |
-
"Color": "stop",
|
181 |
-
"AsButton": False, # 加入下拉菜单中
|
182 |
-
"Function": HotReload(Markdown英译中)
|
183 |
-
},
|
184 |
|
185 |
})
|
186 |
|
|
|
21 |
from crazy_functions.总结word文档 import 总结word文档
|
22 |
from crazy_functions.解析JupyterNotebook import 解析ipynb文件
|
23 |
from crazy_functions.对话历史存档 import 对话历史存档
|
24 |
+
from crazy_functions.批量Markdown翻译 import Markdown英译中
|
25 |
function_plugins = {
|
26 |
|
27 |
"解析整个Python项目": {
|
|
|
82 |
"Color": "stop", # 按钮颜色
|
83 |
"Function": HotReload(读文章写摘要)
|
84 |
},
|
85 |
+
"Markdown/Readme英译中": {
|
86 |
+
# HotReload 的意思是热更新,修改函数插件代码后,不需要重启程序,代码直接生效
|
87 |
+
"Color": "stop",
|
88 |
+
"Function": HotReload(Markdown英译中)
|
89 |
+
},
|
90 |
"批量生成函数注释": {
|
91 |
"Color": "stop", # 按钮颜色
|
92 |
+
"AsButton": False, # 加入下拉菜单中
|
93 |
"Function": HotReload(批量生成函数注释)
|
94 |
},
|
95 |
"[多线程Demo] 解析此项目本身(源码自译解)": {
|
|
|
117 |
from crazy_functions.Latex全文翻译 import Latex中译英
|
118 |
from crazy_functions.Latex全文翻译 import Latex英译中
|
119 |
from crazy_functions.批量Markdown翻译 import Markdown中译英
|
|
|
120 |
|
121 |
function_plugins.update({
|
122 |
"批量翻译PDF文档(多线程)": {
|
|
|
181 |
"AsButton": False, # 加入下拉菜单中
|
182 |
"Function": HotReload(Markdown中译英)
|
183 |
},
|
184 |
+
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
})
|
187 |
|
crazy_functions/批量Markdown翻译.py
CHANGED
@@ -98,6 +98,7 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|
98 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
99 |
try:
|
100 |
import tiktoken
|
|
|
101 |
except:
|
102 |
report_execption(chatbot, history,
|
103 |
a=f"解析项目: {txt}",
|
@@ -105,19 +106,38 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|
105 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
106 |
return
|
107 |
history = [] # 清空历史,以免输入溢出
|
108 |
-
|
109 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
project_folder = txt
|
|
|
111 |
else:
|
|
|
112 |
if txt == "": txt = '空空如也的输入栏'
|
113 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
114 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
115 |
return
|
116 |
-
|
117 |
if len(file_manifest) == 0:
|
118 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
|
119 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
120 |
return
|
|
|
121 |
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh')
|
122 |
|
123 |
|
|
|
98 |
# 尝试导入依赖,如果缺少依赖,则给出安装建议
|
99 |
try:
|
100 |
import tiktoken
|
101 |
+
import glob, os
|
102 |
except:
|
103 |
report_execption(chatbot, history,
|
104 |
a=f"解析项目: {txt}",
|
|
|
106 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
107 |
return
|
108 |
history = [] # 清空历史,以免输入溢出
|
109 |
+
|
110 |
+
if txt.startswith('http'):
|
111 |
+
# 网络的远程文件
|
112 |
+
txt = txt.replace("https://github.com/", "https://raw.githubusercontent.com/")
|
113 |
+
txt = txt.replace("/blob/", "/")
|
114 |
+
import requests
|
115 |
+
from toolbox import get_conf
|
116 |
+
proxies, = get_conf('proxies')
|
117 |
+
r = requests.get(txt, proxies=proxies)
|
118 |
+
with open('./gpt_log/temp.md', 'wb+') as f: f.write(r.content)
|
119 |
+
project_folder = './gpt_log/'
|
120 |
+
file_manifest = ['./gpt_log/temp.md']
|
121 |
+
elif txt.endswith('.md'):
|
122 |
+
# 直接给定文件
|
123 |
+
file_manifest = [txt]
|
124 |
+
project_folder = os.path.dirname(txt)
|
125 |
+
elif os.path.exists(txt):
|
126 |
+
# 本地路径,递归搜索
|
127 |
project_folder = txt
|
128 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
129 |
else:
|
130 |
+
# 什么都没有
|
131 |
if txt == "": txt = '空空如也的输入栏'
|
132 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|
133 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
134 |
return
|
135 |
+
|
136 |
if len(file_manifest) == 0:
|
137 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
|
138 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
139 |
return
|
140 |
+
|
141 |
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh')
|
142 |
|
143 |
|
request_llm/bridge_newbing.py
CHANGED
@@ -245,7 +245,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
|
|
245 |
for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
|
246 |
chatbot[-1] = (inputs, preprocess_newbing_out(response))
|
247 |
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
|
248 |
-
|
249 |
history.extend([inputs, response])
|
250 |
yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
|
251 |
|
|
|
245 |
for response in newbing_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
|
246 |
chatbot[-1] = (inputs, preprocess_newbing_out(response))
|
247 |
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
|
248 |
+
if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常,请刷新界面重试 ..."
|
249 |
history.extend([inputs, response])
|
250 |
yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
|
251 |
|