| 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.") | |
| self.get_body().success(f"¡Todo listo!\nhk-{self._get_hf()}") | |
| _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() | |
| elif _traducir is False and _resumir is True: | |
| _response["traduccion"] = str() | |
| _response["resumen"] = Generator.resumir(texto = _response.get('original')) | |
| elif _traducir is True and _resumir is True: | |
| _response["traduccion"] = Generator.traducir(texto = _response.get('original')) | |
| _response["resumen"] = Generator.resumir(texto = _response.get('traduccion')) | |
| _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().markdown(_original, help="Original") | |
| self.get_body().markdown(_traduccion, help="Traduccion") | |
| self.get_body().markdown(_resumen, help="Resumen") | |
| if __name__ == "__main__": | |
| Textia(title="Textia - PDF",icon="🖼️").build() | |