openai_translation

Docx Translator with OpenAI

This repository provides a Python script for translating .docx files using OpenAI’s GPT(-4) API.


Features


Requirements

  1. Python 3.7 or higher.
  2. Required libraries:
    • openai
    • python-docx
    • tiktoken
  3. A valid OpenAI API key.

To install the required libraries, run:

pip install openai python-docx tiktoken
## Setup

### Configuration File

Create a `config.json` file in the same directory as the script and add your OpenAI API key:

```json
{
    "OPENAI_API_KEY": "your-api-key-here"
}

Input


Usage

  1. Open the script and modify the main() function call:

    main('input.docx', 'output.docx', sample_translation_file='sample_translation.docx')
    
    • Replace input.docx with the path to your input file.
    • Replace output.docx with the desired output file path.
    • Optionally, specify a sample translation file.
  2. Run the script; e.g. in bash:

    python openai_translator.py
    
  3. The translated document will be saved as the specified output file.