import openai # Set your OpenAI API key openai.api_key = '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' def translate_spanish_to_english(spanish_text): # Use ChatGPT to generate an English translation prompt = f"Translate the following Spanish text to English:\n\n{spanish_text}\n\nTranslation:" response = openai.Completion.create( engine="text-davinci-003", # You can experiment with different engines prompt=prompt, temperature=0.7, max_tokens=150, stop=None ) # Extract the generated translation from the model's response translation = response['choices'][0]['text'].strip() return translation if __name__ == "__main__": # Example usage spanish_text = "Hola, ¿cómo estás?" english_translation = translate_spanish_to_english(spanish_text) print(f"Original text (Spanish): {spanish_text}") print(f"Translation (English): {english_translation}")