File size: 3,312 Bytes
1280b99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from api.core.app import Demos
__main = Demos()
api = __main.api()

@api.post("/texto_desde_web/", status_code=201)
def get_text_from_url(data:dict) -> dict:
    __response=dict({"request_data":data})
    try:
        if data and 'url' in data:
            __response['texto']=__main.obtener_texto(from_url=data.get('url'))
        else:
            raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
    except Exception as e:
        print(e)
        #To-do ->agregar mas información en el error fecha, usuario, reqs
        raise __main.exception(status_code = 403, datail=e)
    finally:
        return __response

@api.post("/texto_desde_pdf/", status_code=201)
def get_text_from_pdf(data:dict) -> dict:
    __response=dict({"request_data":data})
    try:
        if data and 'pdf' in data:
            __response['texto']=__main.obtener_texto(from_pdf=data.get('pdf'))
        else:
            raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
    except Exception as e:
        print(e)
        #To-do ->agregar mas información en el error fecha, usuario, reqs
        raise __main.exception(status_code = 403, datail=e)
    finally:
        return __response

@api.post("/generar_bloques/", status_code=201)
def get_blocks(data:dict) -> dict:
    __response=dict({"request_data":data})
    try:
        if data and 'texto' in data and 'size' in data:
            __response['original']=data.get('texto')
            __response['bloques']=__main.generar_bloques(texto=data.get('texto'),
                                                         size=data.get('size'))
        else:
            raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
    except Exception as e:
        print(e)
        #To-do ->agregar mas información en el error fecha, usuario, reqs
        raise __main.exception(status_code = 403, datail=e)
    finally:
        return __response

@api.post("/traducir/", status_code=201)
def get_traduccion(data:dict) -> dict:
    __response=dict({"request_data":data})
    try:
        if data and 'texto' in data and 'idioma' in data:
            __response['original']= data.get('texto')
            __response['traduccion']= __main.traducir(texto=data.get('texto'),
                                                      idioma=data.get('idioma'))
        else:
            raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
    except Exception as e:
        print(e)
        #To-do ->agregar mas información en el error fecha, usuario, reqs
        raise __main.exception(status_code = 403, datail=e)
    finally:
        return __response

@api.post("/resumir/", status_code=201)
def get_resumen(data:dict) -> dict:
    __response=dict({"request_data":data})
    try:
        if data and 'texto' in data:
            __response['original']= data.get('texto')
            __response['resumen']= __main.resumir(texto=data.get('texto'))
        else:
            raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
    except Exception as e:
        print(e)
        #To-do ->agregar mas información en el error fecha, usuario, reqs
        raise __main.exception(status_code = 403, datail=e)
    finally:
        return __response