demos / api /core /controllers /text2text.py
coder160's picture
bug:txt2txt response
91304ee
raw
history blame
1.47 kB
from transformers import pipeline as Pipe
class Traductor:
def EN_ES(texto:str)->str:
try:
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-en-es")
_traduccion = _traductor(texto)[0]
_response = _traduccion.get('generated_text')
except Exception as e:
_response = str(e)
finally:
return _response
def ES_EN(texto:str)->str:
try:
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-es-en")
_traduccion = _traductor(texto)[0]
_response = _traduccion.get('generated_text')
except Exception as e:
_response = str(e)
finally:
return _response
def AR_ES(texto:str)->str:
try:
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-ar-es")
_traduccion = _traductor(texto)[0]
_response = _traduccion.get('generated_text')
except Exception as e:
_response = str(e)
finally:
return _response
class Abstractor:
def resumen(texto:str)->str:
try:
_abstractor = Pipe("text2text-generation", model="facebook/bart-large-cnn")
_resumen = _abstractor(texto)[0]
_response = _resumen.get('generated_text')
except Exception as e:
_response = str(e)
finally:
return _response