-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChat-GPT-Translator.py
More file actions
23 lines (16 loc) · 949 Bytes
/
Chat-GPT-Translator.py
File metadata and controls
23 lines (16 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import openai
def correct_and_translate(text, target_language):
api_key = "your_api_key_here"
# Correct spelling using GPT-3
correction_prompt = f"Correct the following text: {text}"
corrected_text = openai.Completion.create(engine="text-davinci-003", prompt=correction_prompt, max_tokens=50, api_key=api_key).choices[0].text.strip()
print(f"corrected text: {corrected_text}")
# Translate the text to the desired language using GPT-3
translation_prompt = f"Translate the following text to {target_language}: {corrected_text}"
translated_text = openai.Completion.create(engine="text-davinci-003", prompt=translation_prompt, max_tokens=50, api_key=api_key).choices[0].text.strip()
return translated_text
# Example usage
text_to_translate = "can men get breast cancer?"
target_language = "Spanish"
corrected_translation = correct_and_translate(text_to_translate, target_language)
print(corrected_translation)