-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_traducir_texto.py
More file actions
40 lines (28 loc) · 894 Bytes
/
07_traducir_texto.py
File metadata and controls
40 lines (28 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Programa para analizar los sentimientos predominantes
de un texto
"""
import openai
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
openai.api_key = api_key
def traducir_texto(texto, idioma):
"""
Analizar sentimientos con OpenAI GPT-3
"""
prompt = f"Traduce el siguiente texto al idioma {idioma}:\n\n{texto}\n\nTexto traducido: "
respuesta = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
n=1,
temperature=0.5,
max_tokens=1000
)
return respuesta.choices[0].text.strip()
print("Bienvenido al traductor de texto\n")
idioma = input("Escribe el idioma al que quieres traducir: ")
texto_a_traducir = input("Escribe el texto a traducir: ")
texto_traducido = traducir_texto(texto_a_traducir, idioma)
print(f"El texto traducido es: {texto_traducido}")