bug:txt2txt response
Browse files- api/core/controllers/text2text.py +32 -12
- api/main.py +1 -1
api/core/controllers/text2text.py
CHANGED
@@ -2,22 +2,42 @@ from transformers import pipeline as Pipe
|
|
2 |
|
3 |
class Traductor:
|
4 |
def EN_ES(texto:str)->str:
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def ES_EN(texto:str)->str:
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def AR_ES(texto:str)->str:
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
class Abstractor:
|
20 |
def resumen(texto:str)->str:
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
class Traductor:
|
4 |
def EN_ES(texto:str)->str:
|
5 |
+
try:
|
6 |
+
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-en-es")
|
7 |
+
_traduccion = _traductor(texto)[0]
|
8 |
+
_response = _traduccion.get('generated_text')
|
9 |
+
except Exception as e:
|
10 |
+
_response = str(e)
|
11 |
+
finally:
|
12 |
+
return _response
|
13 |
|
14 |
def ES_EN(texto:str)->str:
|
15 |
+
try:
|
16 |
+
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-es-en")
|
17 |
+
_traduccion = _traductor(texto)[0]
|
18 |
+
_response = _traduccion.get('generated_text')
|
19 |
+
except Exception as e:
|
20 |
+
_response = str(e)
|
21 |
+
finally:
|
22 |
+
return _response
|
23 |
|
24 |
def AR_ES(texto:str)->str:
|
25 |
+
try:
|
26 |
+
_traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-ar-es")
|
27 |
+
_traduccion = _traductor(texto)[0]
|
28 |
+
_response = _traduccion.get('generated_text')
|
29 |
+
except Exception as e:
|
30 |
+
_response = str(e)
|
31 |
+
finally:
|
32 |
+
return _response
|
33 |
|
34 |
class Abstractor:
|
35 |
def resumen(texto:str)->str:
|
36 |
+
try:
|
37 |
+
_abstractor = Pipe("text2text-generation", model="facebook/bart-large-cnn")
|
38 |
+
_resumen = _abstractor(texto)[0]
|
39 |
+
_response = _resumen.get('generated_text')
|
40 |
+
except Exception as e:
|
41 |
+
_response = str(e)
|
42 |
+
finally:
|
43 |
+
return _response
|
api/main.py
CHANGED
@@ -56,7 +56,7 @@ def get_traduccion(data:dict) -> dict:
|
|
56 |
if data:
|
57 |
__response['original']= data.get('texto')
|
58 |
__response['traduccion']= __main.traducir(texto=data.get('texto'),
|
59 |
-
idioma=
|
60 |
else:
|
61 |
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
62 |
except Exception as e:
|
|
|
56 |
if data:
|
57 |
__response['original']= data.get('texto')
|
58 |
__response['traduccion']= __main.traducir(texto=data.get('texto'),
|
59 |
+
idioma=data.get('idioma'))
|
60 |
else:
|
61 |
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
62 |
except Exception as e:
|