Skip to content

因为OpenAI更新了Python API,Raychanan大佬的ChatGPT-for-Translation暂时不可用了。本项目对ChatGPT-for-Translation中的API进行了更新,亲测可用。

License

Notifications You must be signed in to change notification settings

YuxuanXiu/ChatGPT-for-Translation-with-Updated-API

Repository files navigation

ChatGPT for Translation | ChatGPT用于翻译

Use ChatGPT to complete document translations. This tool accepts a text file (.pdf, .txt, .md, .html, or .rtf) or a folder containing text files. It will generate both a direct translation and a bilingual text file. Special optimization has been done for parsing PDFs.

使用ChatGPT完成文件翻译。该工具接受一个文本文件(.pdf, .txt, .md, .html.rtf)或者一个包含文本的文件夹。它将生成一个直接翻译和一个双语文本文件。对于 PDF 解析做了优化。

Use this on Google Colab (recommended). See here

Google Colab上使用这个工具(推荐)。见这里

Example | 例子

# Install
git clone https://github.com/Raychanan/ChatGPT-for-Translation.git
cd ./ChatGPT-for-Translation/
pip install -r requirements.txt --quiet

# Run
python ChatGPT-translate.py --input_path=input.txt --openai_key=password

This command will translate the text in input.txt into simplified Chinese using ChatGPT. You can also specify any language you want. For example, --target_language="Traditional Chinese".

这个命令将使用ChatGPT把input.txt中的文本翻译成简体中文。你也可以指定任何你想要的语言。例如,--target_language="Traditional Chinese"

Translate All Files Within the Folder | 翻译文件夹内所有文本文件

python ChatGPT-translate.py --input_path=./folder_name/ --openai_key=password

Other Examples | 其它例子

Azure:

python ChatGPT-translate.py --input_path=input.pdf --use_azure --azure_endpoint=endpoint_uri --azure_deployment_name=deployment_name --openai_key=your_AOAI_key

GPT-4:

python ChatGPT-translate.py --input_path=input.txt --model=gpt-4 --openai_key=password

Virtual Environment Setup

Note:

Run: python --version to see if it is Python 3.6 or above. Run python3 --version to see if it is aliased under python3 instead.

If it is python3 then use python3 when creating the virtual environment.

First create virtual environment if it doesn't exist: (Use python3 here if needed.)

python -m venv venv

Second activate it:

source venv/bin/activate

Third install requirements.txt:

pip install -r requirements.txt

If necessary sometimes dependencies may have changed and no longer works. You can instead run:

pip install stable_requirements.txt

Prerequisites | 要求

OpenAI API key (https://beta.openai.com/signup/) or Azure

You need to link a payment method in the OpenAI API, otherwise you'll face extremely stringent API rate limits.

OpenAI API 里面要绑定支付方式,否则会有极其严苛的API速率限制.

Arguments | 可用参数

--num_threads: The number of threads to use for translation (default: 10).
--only_process_this_file_extension. For example, set only_process_this_file_extension="txt".
--not_to_translate_references. By default, not to translate references.

Acknowledge

The PDF parser is built on Grobid, a machine learning-driven PDF content extraction tool.

About

因为OpenAI更新了Python API,Raychanan大佬的ChatGPT-for-Translation暂时不可用了。本项目对ChatGPT-for-Translation中的API进行了更新,亲测可用。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages