镜像自地址
https://github.com/binary-husky/gpt_academic.git
已同步 2025-12-07 15:06:48 +00:00
"version": 3.48
这个提交包含在:
@@ -3,16 +3,18 @@
|
||||
|
||||
|
||||
Usage:
|
||||
1. modify LANG
|
||||
1. modify config.py, set your LLM_MODEL and API_KEY(s) to provide access to OPENAI (or any other LLM model provider)
|
||||
|
||||
2. modify LANG (below ↓)
|
||||
LANG = "English"
|
||||
|
||||
2. modify TransPrompt
|
||||
3. modify TransPrompt (below ↓)
|
||||
TransPrompt = f"Replace each json value `#` with translated results in English, e.g., \"原始文本\":\"TranslatedText\". Keep Json format. Do not answer #."
|
||||
|
||||
3. Run `python multi_language.py`.
|
||||
4. Run `python multi_language.py`.
|
||||
Note: You need to run it multiple times to increase translation coverage because GPT makes mistakes sometimes.
|
||||
|
||||
4. Find the translated program in `multi-language\English\*`
|
||||
5. Find the translated program in `multi-language\English\*`
|
||||
|
||||
P.S.
|
||||
|
||||
@@ -33,7 +35,7 @@ import pickle
|
||||
import time
|
||||
|
||||
CACHE_FOLDER = "gpt_log"
|
||||
blacklist = ['multi-language', 'gpt_log', '.git', 'private_upload', 'multi_language.py']
|
||||
blacklist = ['multi-language', 'gpt_log', '.git', 'private_upload', 'multi_language.py', 'build', '.github', '.vscode', '__pycache__', 'venv']
|
||||
|
||||
# LANG = "TraditionalChinese"
|
||||
# TransPrompt = f"Replace each json value `#` with translated results in Traditional Chinese, e.g., \"原始文本\":\"翻譯後文字\". Keep Json format. Do not answer #."
|
||||
@@ -286,6 +288,7 @@ def trans_json(word_to_translate, language, special=False):
|
||||
|
||||
|
||||
def step_1_core_key_translate():
|
||||
LANG_STD = 'std'
|
||||
def extract_chinese_characters(file_path):
|
||||
syntax = []
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
@@ -301,6 +304,7 @@ def step_1_core_key_translate():
|
||||
elif isinstance(node, ast.ImportFrom):
|
||||
for n in node.names:
|
||||
if contains_chinese(n.name): syntax.append(n.name)
|
||||
# if node.module is None: print(node.module)
|
||||
for k in node.module.split('.'):
|
||||
if contains_chinese(k): syntax.append(k)
|
||||
return syntax
|
||||
@@ -310,6 +314,7 @@ def step_1_core_key_translate():
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
if any([b in root for b in blacklist]):
|
||||
continue
|
||||
print(files)
|
||||
for file in files:
|
||||
if file.endswith('.py'):
|
||||
file_path = os.path.join(root, file)
|
||||
@@ -323,15 +328,15 @@ def step_1_core_key_translate():
|
||||
for d in chinese_core_keys:
|
||||
if d not in chinese_core_keys_norepeat: chinese_core_keys_norepeat.append(d)
|
||||
need_translate = []
|
||||
cached_translation = read_map_from_json(language=LANG)
|
||||
cached_translation = read_map_from_json(language=LANG_STD)
|
||||
cached_translation_keys = list(cached_translation.keys())
|
||||
for d in chinese_core_keys_norepeat:
|
||||
if d not in cached_translation_keys:
|
||||
need_translate.append(d)
|
||||
|
||||
need_translate_mapping = trans(need_translate, language=LANG, special=True)
|
||||
map_to_json(need_translate_mapping, language=LANG)
|
||||
cached_translation = read_map_from_json(language=LANG)
|
||||
need_translate_mapping = trans(need_translate, language=LANG_STD, special=True)
|
||||
map_to_json(need_translate_mapping, language=LANG_STD)
|
||||
cached_translation = read_map_from_json(language=LANG_STD)
|
||||
cached_translation = dict(sorted(cached_translation.items(), key=lambda x: -len(x[0])))
|
||||
|
||||
chinese_core_keys_norepeat_mapping = {}
|
||||
@@ -505,6 +510,6 @@ def step_2_core_key_translate():
|
||||
with open(file_path_new, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
os.remove(file_path)
|
||||
|
||||
step_1_core_key_translate()
|
||||
step_2_core_key_translate()
|
||||
print('Finished, checkout generated results at ./multi-language/')
|
||||
在新工单中引用
屏蔽一个用户