Skip to main content

Simple multi-language document translator in Python. A quick project.

·2 mins
Marc Alier
Author
Marc Alier
Personal homepage and miscellany.
Table of Contents

[Note: using OpenAI’s API has its costs. The cost of using the translator will depend on the size of the documents you translate. As a guideline, so far with development, tests, and translating a few documents I’ve spent €0.03. ]

In this post I present a small project I’ve released as open source. What would once have been a project taking many years and several million euros is now a small experiment done on a Saturday morning. The keys are GitHub Copilot, ChatGPT 4 as programming assistants, and the GPT-3.5 Turbo API.

GPT-Translate screenshot

gpt-translator
#

You can download it from https://github.com/granludo/gpt-test/tree/main/file-trasnlator

Licensed under the GNU General Public License v3.0

Simple Python 3 program that uses OpenAI’s GPT-3.5-turbo model to translate files from one language to another. It splits the file into 20-line chunks.

Requirements
#

You need an API key to use OpenAI. You can get one here: https://beta.openai.com/docs/developer-quickstart/api-key this program looks for the key in a file indicated in the variable “mykeypath” by default at the path ‘..//..//mykey.json’

You need to have Python 3 installed on your system. I’ve used Python 3.10

You need to install the json and openai packages

pip install openai

pip install json

On your system you may need to use pip3 instead of pip.

Usage
#

python3 gpt-traductor.py archivo_origen idioma_origen idioma_destino archivo_destinoExample

python3 gpt-translate.py sample.md catalan italian sample_translated.md

Have fun.

Related

Participation in a session on AI and teaching at UIC

On March 2, 2023, I took part in the session on AI chatbots in higher education organized by the Universitat Internacional de Catalunya UIC. At https://www.linkedin.com/events/sessi-sobrexatbotsd-intel-lig-n7034187811851235329/comments/ you can find the video of the event. Yours truly and his talk appear starting at 1h:25 minutes.

What ChatGPT Is and Isn't?

·10 mins
Contents # What is ChatGPT? ChatGPT is Software As A Service (SaaS) Terms and conditions Authorship rights and responsibility for ChatGPT’s outputs Cost and access What’s ChatGPT for and why is it free? ChatGPT isn’t open source Ethical aspects Ethical reflections from the creators of GPT-3 The ChatGPT Hype What is ChatGPT ? # ChatGTP is a web application based on GPT-3, specifically the GPT-3.5 “text-davinci-003” model developed by OpenAi. The ChatGPT model is optimized to work in conversational form, responding to inputs that users provide as a text “prompt”. ChatGPT is a type of Generative AI based on a Machine Learning Model . We can consider ChatGPT a weak AI (see Types of Artificial Intelligence].