coder160 commited on
Commit
ce3761d
·
1 Parent(s): 00e36bb

update endpoints

Browse files
Files changed (2) hide show
  1. api/core/app.py +93 -1
  2. api/main.py +116 -3
api/core/app.py CHANGED
@@ -23,4 +23,96 @@ class Demos:
23
  _texto = str("PDF")
24
  else:
25
  _texto = str("Ninguna opción seleccionada")
26
- return _texto
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  _texto = str("PDF")
24
  else:
25
  _texto = str("Ninguna opción seleccionada")
26
+ return _texto
27
+ @staticmethod
28
+ def generar_bloques(texto:str=None,s:int=1500)->list:
29
+ """Genera bloques de texto de longitud S, a partir de un texto plano.
30
+
31
+ args:
32
+ texto (str) : Texto para generar bloques.
33
+ s (int) : Longitud de los bloques de texto, default 1500 caracteres.
34
+ return:
35
+ _bloques (list) : Lista de bloques de textos de longitud s.
36
+ """
37
+ _bloques = list()
38
+ return _bloques
39
+ @staticmethod
40
+ def traducir(texto:str=None, idioma:str="EN/ES")->str:
41
+ """Genera una traducción del texto dado.
42
+
43
+ args:
44
+ texto (str) : Texto para traducir
45
+ idioma (str) : Idioma, default "EN/ES"
46
+ return:
47
+ _traduccion (str) : Traducción del texto
48
+ """
49
+ _traduccion = str()
50
+ if "EN/ES" in idioma.upper():
51
+ _traduccion = "input inglés, output español"
52
+ elif "ES/EN" in idioma.upper():
53
+ _traduccion = "input español, output inglés"
54
+ elif "AR/ES" in idioma.upper():
55
+ _traduccion = "input arabe, output español"
56
+ else:
57
+ _traduccion = "Idioma no válido"
58
+ return _traduccion
59
+ @staticmethod
60
+ def resumir(texto:str=None)->str:
61
+ """Genera un resumen del texto dado.
62
+
63
+ args:
64
+ texto (str) : Texto para generar resumen
65
+ return:
66
+ _resumen (str) : Resumen generado
67
+ """
68
+ _bloques = list()
69
+ return _bloques
70
+ @staticmethod
71
+ def text_to_img(texto:str=None)->str:
72
+ """Genera un BITARRAY de la imagen con el texto dado.
73
+
74
+ args:
75
+ texto (str) : Texto para generar imagen
76
+ return:
77
+ _img (str) : Imagen en BITARRAY
78
+ """
79
+ _img = str()
80
+ return _img
81
+ @staticmethod
82
+ def text_to_video(texto:str=None)->str:
83
+ """Genera un BITARRAY del video con el texto dado.
84
+
85
+ args:
86
+ texto (str) : Texto para generar video
87
+ return:
88
+ _video (str) : Video en BITARRAY
89
+ """
90
+ _video = str()
91
+ return _video
92
+ @staticmethod
93
+ def text_to_speach(texto:str=None)->str:
94
+ """Genera un BITARRAY del audio con el texto dado.
95
+
96
+ args:
97
+ texto (str) : Texto para generar audio
98
+ return:
99
+ _speach (str) : Audio en BITARRAY
100
+ """
101
+ _speach = str()
102
+ return _speach
103
+ @staticmethod
104
+ def image_to_image(task:str="MSLD", image:str=None, mask:str=None,**kwargs)->str:
105
+ """Genera una imagen a partir de una imagen
106
+
107
+ args:
108
+ task (str) : Modelo a utilizar: MSLD, DEEP, SCRIBLE, etc..
109
+ image (str) : Input Image
110
+ mask (str) : Mask Image
111
+ **kwargs (str) : Argumentos adicionales: inference, strnght, guidance...
112
+ return:
113
+ _image (str) : Imagen en BITARRAY
114
+ """
115
+ _image = str()
116
+ return _image
117
+
118
+
api/main.py CHANGED
@@ -5,7 +5,7 @@ api = __main.api()
5
  def home() -> dict:
6
  __response=dict({"request_data":None})
7
  try:
8
- __response['texto']= "hola"
9
  except Exception as e:
10
  print(e)
11
  #To-do ->agregar mas información en el error fecha, usuario, reqs
@@ -13,7 +13,7 @@ def home() -> dict:
13
  finally:
14
  return __response
15
 
16
- @api.post("/obtener_texto/", status_code=201)
17
  def get_text_from_url(data:dict) -> dict:
18
  __response=dict({"request_data":data})
19
  try:
@@ -26,4 +26,117 @@ def get_text_from_url(data:dict) -> dict:
26
  #To-do ->agregar mas información en el error fecha, usuario, reqs
27
  raise __main.exception(status_code = 403, datail=e)
28
  finally:
29
- return __response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def home() -> dict:
6
  __response=dict({"request_data":None})
7
  try:
8
+ __response['message']= "Bienvenido"
9
  except Exception as e:
10
  print(e)
11
  #To-do ->agregar mas información en el error fecha, usuario, reqs
 
13
  finally:
14
  return __response
15
 
16
+ @api.post("/texto_desde_web/", status_code=201)
17
  def get_text_from_url(data:dict) -> dict:
18
  __response=dict({"request_data":data})
19
  try:
 
26
  #To-do ->agregar mas información en el error fecha, usuario, reqs
27
  raise __main.exception(status_code = 403, datail=e)
28
  finally:
29
+ return __response
30
+
31
+ @api.post("/texto_desde_pdf/", status_code=201)
32
+ def get_text_from_pdf(data:dict) -> dict:
33
+ __response=dict({"request_data":data})
34
+ try:
35
+ if data:
36
+ __response['texto']=__main.obtener_texto(from_pdf=data.get('pdf'))
37
+ else:
38
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
39
+ except Exception as e:
40
+ print(e)
41
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
42
+ raise __main.exception(status_code = 403, datail=e)
43
+ finally:
44
+ return __response
45
+
46
+ @api.post("/generar_bloques/", status_code=201)
47
+ def get_blocks(data:dict) -> dict:
48
+ __response=dict({"request_data":data})
49
+ try:
50
+ if data:
51
+ __response['original']=data.get('texto')
52
+ __response['bloques']=__main.generar_bloques(texto=data.get('texto'),
53
+ s=data.get('size'))
54
+ else:
55
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
56
+ except Exception as e:
57
+ print(e)
58
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
59
+ raise __main.exception(status_code = 403, datail=e)
60
+ finally:
61
+ return __response
62
+
63
+ @api.post("/traducir/", status_code=201)
64
+ def get_traduccion(data:dict) -> dict:
65
+ __response=dict({"request_data":data})
66
+ try:
67
+ if data:
68
+ __response['original']= data.get('texto')
69
+ __response['traduccion']= __main.traducir(texto=data.get('texto'),
70
+ idioma="EN/ES")
71
+ else:
72
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
73
+ except Exception as e:
74
+ print(e)
75
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
76
+ raise __main.exception(status_code = 403, datail=e)
77
+ finally:
78
+ return __response
79
+
80
+ @api.post("/resumir/", status_code=201)
81
+ def get_resumen(data:dict) -> dict:
82
+ __response=dict({"request_data":data})
83
+ try:
84
+ if data:
85
+ __response['original']= data.get('texto')
86
+ __response['resumen']= __main.resumir(texto=data.get('texto'))
87
+ else:
88
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
89
+ except Exception as e:
90
+ print(e)
91
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
92
+ raise __main.exception(status_code = 403, datail=e)
93
+ finally:
94
+ return __response
95
+
96
+ @api.post("/texto_a_imagen/", status_code=201)
97
+ def get_text2img(data:dict) -> dict:
98
+ __response=dict({"request_data":data})
99
+ try:
100
+ if data:
101
+ __response['original']= data.get('texto')
102
+ __response['image']= __main.text_to_img(texto=data.get('texto'))
103
+ else:
104
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
105
+ except Exception as e:
106
+ print(e)
107
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
108
+ raise __main.exception(status_code = 403, datail=e)
109
+ finally:
110
+ return __response
111
+
112
+ @api.post("/texto_a_video/", status_code=201)
113
+ def get_text2video(data:dict) -> dict:
114
+ __response=dict({"request_data":data})
115
+ try:
116
+ if data:
117
+ __response['original']= data.get('texto')
118
+ __response['video']= __main.text_to_video(texto=data.get('texto'))
119
+ else:
120
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
121
+ except Exception as e:
122
+ print(e)
123
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
124
+ raise __main.exception(status_code = 403, datail=e)
125
+ finally:
126
+ return __response
127
+
128
+ @api.post("/texto_a_audio/", status_code=201)
129
+ def get_text2speach(data:dict) -> dict:
130
+ __response=dict({"request_data":data})
131
+ try:
132
+ if data:
133
+ __response['original']= data.get('texto')
134
+ __response['audio']= __main.text_to_speach(texto=data.get('texto'))
135
+ else:
136
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
137
+ except Exception as e:
138
+ print(e)
139
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
140
+ raise __main.exception(status_code = 403, datail=e)
141
+ finally:
142
+ return __response