Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2023 11:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import openai
import re
# Define GPT-3.5-turbo API key
openai_api_key = 'YOUR-OPENAI-API-KEY'
openai.api_key = openai_api_key
# Read the Bengali text from the file
with open('/home/ehz/Downloads/nlu.txt', 'r', encoding='utf-8') as file:
bengali_text =
# Split the text into sentences using regex (modify as needed)
bengali_sentences = re.split(r'(?<=[।?!])\s+', bengali_text.strip())
# Translate the sentences
translated_sentences = []
for sentence in bengali_sentences:
response = openai.Completion.create(
prompt=f"Translate the following Bengali sentence to English: {sentence}",
# Write the translated sentences to a new file, each on a new line
with open('/home/ehz/Downloads/translated_text.txt', 'w', encoding='utf-8') as file:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment