Spaces:
Build error
Build error
Function Refector
Browse files- crazy_functions/批量Markdown翻译.py +29 -20
crazy_functions/批量Markdown翻译.py
CHANGED
@@ -84,7 +84,33 @@ def 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, ch
|
|
84 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
85 |
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
|
|
88 |
|
89 |
|
90 |
@CatchException
|
@@ -107,26 +133,9 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
|
107 |
return
|
108 |
history = [] # 清空历史,以免输入溢出
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
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}")
|
|
|
84 |
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
85 |
|
86 |
|
87 |
+
def get_files_from_everything(txt):
|
88 |
+
import glob, os
|
89 |
+
|
90 |
+
success = True
|
91 |
+
if txt.startswith('http'):
|
92 |
+
# 网络的远程文件
|
93 |
+
txt = txt.replace("https://github.com/", "https://raw.githubusercontent.com/")
|
94 |
+
txt = txt.replace("/blob/", "/")
|
95 |
+
import requests
|
96 |
+
from toolbox import get_conf
|
97 |
+
proxies, = get_conf('proxies')
|
98 |
+
r = requests.get(txt, proxies=proxies)
|
99 |
+
with open('./gpt_log/temp.md', 'wb+') as f: f.write(r.content)
|
100 |
+
project_folder = './gpt_log/'
|
101 |
+
file_manifest = ['./gpt_log/temp.md']
|
102 |
+
elif txt.endswith('.md'):
|
103 |
+
# 直接给定文件
|
104 |
+
file_manifest = [txt]
|
105 |
+
project_folder = os.path.dirname(txt)
|
106 |
+
elif os.path.exists(txt):
|
107 |
+
# 本地路径,递归搜索
|
108 |
+
project_folder = txt
|
109 |
+
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.md', recursive=True)]
|
110 |
+
else:
|
111 |
+
success = False
|
112 |
|
113 |
+
return success, file_manifest, project_folder
|
114 |
|
115 |
|
116 |
@CatchException
|
|
|
133 |
return
|
134 |
history = [] # 清空历史,以免输入溢出
|
135 |
|
136 |
+
success, file_manifest, project_folder = get_files_from_everything(txt)
|
137 |
+
|
138 |
+
if not success:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
# 什么都没有
|
140 |
if txt == "": txt = '空空如也的输入栏'
|
141 |
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
|