File size: 2,988 Bytes
88c7280
 
 
 
 
 
 
 
 
 
 
 
 
 
5ab3c38
 
 
 
 
 
 
 
 
 
 
 
 
 
876c835
5ab3c38
 
12cee56
876c835
5ab3c38
 
12cee56
876c835
5ab3c38
 
 
 
 
 
 
 
21f0079
5ab3c38
21f0079
5ab3c38
21f0079
5ab3c38
88c7280
 
876c835
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
from core.controller import Page, WebHandler, Generator
class Textia(Page):
    def __init__(self, title:str, icon:str=None):
        super().__init__(title=title,icon=icon)
    def _init_globals(self):
        self.__hf = self.get_global(key="hf_key", default=None)
        self.__modelos = self.get_global(key="modelos_txt",default =list([]))
    def _get_hf(self):
        return self.__hf
    def _get_modelos(self):
        return self.__modelos
    def build(self):
        self._init_globals()
        self.get_body().text("Traduce, Resume o Sintetiza tu información para una mejor comprensión.")
        _url = self.get_body().text_input("URL")
        _traducir = self.get_body().checkbox('Traducir')
        _resumir = self.get_body().checkbox('Resumir')
        _boton = self.get_body().button("texTia")
        if _boton:
            with WebHandler(url=_url) as web_content:
                _content = web_content.get_raw().get_text() if web_content.is_ok() else "None"
                _printable = list()
                _bloques = Generator.get_bloques(texto = _content)
                for _bloque in _bloques:
                    _response={"original":_bloque}
                    if _traducir is True and _resumir is False:
                        _response["traduccion"] = Generator.traducir(texto = _response.get('original'))
                        _response["resumen"] = str()
                        self.get_body().markdown(_response.get('traduccion'), help="Resumen")
                    elif _traducir is False and _resumir is True:
                        _response["traduccion"] = str()
                        _response["resumen"] = Generator.resumir(texto = _response.get('original'))
                        self.get_body().markdown(_response.get('resumen'), help="Resumen")
                    elif _traducir is True and _resumir is True:
                        _response["traduccion"] = Generator.traducir(texto = _response.get('original'))
                        _response["resumen"] = Generator.resumir(texto = _response.get('traduccion'))
                        self.get_body().markdown(_response.get('resumen'), help="Resumen")
                    _printable.append(_response)
            _original=str()
            _traduccion=str()
            _resumen=str()
            for _p in _printable:
                _original = _original + _p.get('original')
                _traduccion = _traduccion + _p.get('traduccion')
                _resumen = _resumen + _p.get('resumen')
            self.get_body().success("Contenido Original:")
            self.get_body().markdown(_original, help="Original")
            self.get_body().success("Contenido Traducido:")
            self.get_body().markdown(_traduccion, help="Traduccion")
            self.get_body().success("Contenido Resumido:")
            self.get_body().markdown(_resumen, help="Resumen")
            
if __name__ == "__main__":
    Textia(title="Textia - PDF",icon="🖼️").build()