This script uses the OpenAI API to translate English text to traditional Chinese using the ChatGPT model. It reads an input text file named article.txt
, splits the text into sentences, and translates each sentence to Chinese using the API. The translated text is then written to an output file named translated_result.txt
.
- Install the required Python packages by running
pip install -r requirements.txt
. - Set your OpenAI API key by replacing
<<YOUR API KEY>>
with your actual API key on line 5 ofchinese_translator.py
. - Create an input text file named
article.txt
in the same directory aschinese_translator.py
. - Run the script by running
python chinese_translator.py
. - The translated text will be written to an output file named
translated_result.txt
in the same directory aschinese_translator.py
.