| class Demos: |
| def __init__(self): |
| from fastapi import FastAPI, HTTPException, Response |
| self.api = FastAPI |
| self.exception = HTTPException |
| self.api_response = Response |
| def validate_apikey(self,api_key)->bool: |
| __validation = True |
| return __validation |
| @staticmethod |
| def obtener_texto(from_url:str=None,from_pdf:str=None)->str: |
| """Obtiene texto a partir de una fuente de información: desde url o desde pdf. |
| |
| args: |
| from_url (str) : Url desde la que se desea obtener información. |
| from_pdf (str) : Pdf desde el que se desea obtener información. |
| return: |
| _texto (str) : Texto extraído desde la fuente dada. |
| """ |
| from api.core.controllers.extractor import TextFromURL |
| if from_url: |
| with TextFromURL(url=from_url) as web_content: |
| _texto = web_content.get_raw().get_text() if web_content.is_ok() else web_content.get_error() |
| elif from_pdf: |
| _texto = str("PDF") |
| else: |
| _texto = str("Ninguna opción seleccionada") |
| return _texto |
| @staticmethod |
| def generar_bloques(texto:str=None,size:int=1500)->list: |
| """Genera bloques de texto de longitud S, a partir de un texto plano. |
| |
| args: |
| texto (str) : Texto para generar bloques. |
| s (int) : Longitud de los bloques de texto, default 1500 caracteres. |
| return: |
| _bloques (list) : Lista de bloques de textos de longitud s. |
| """ |
| from api.core.controllers.handlers import Generator |
| _bloques = Generator.get_bloques(from_text=texto,size=size) |
| return _bloques |
| @staticmethod |
| def traducir(texto:str=None, idioma:str="EN/ES")->str: |
| """Genera una traducción del texto dado. |
| |
| args: |
| texto (str) : Texto para traducir |
| idioma (str) : Idioma, default "EN/ES" |
| return: |
| _traduccion (str) : Traducción del texto |
| """ |
| from api.core.controllers.text2text import Traductor |
| _traduccion = str() |
| if "EN/ES" in idioma.upper(): |
| _traduccion = Traductor.EN_ES(texto=texto) |
| elif "ES/EN" in idioma.upper(): |
| _traduccion = Traductor.ES_EN(texto=texto) |
| elif "AR/ES" in idioma.upper(): |
| _traduccion = Traductor.AR_ES(texto=texto) |
| else: |
| _traduccion = "Idioma no válido" |
| return _traduccion |
| @staticmethod |
| def resumir(texto:str=None)->str: |
| """Genera un resumen del texto dado. |
| |
| args: |
| texto (str) : Texto para generar resumen |
| return: |
| _resumen (str) : Resumen generado |
| """ |
| from api.core.controllers.text2text import Abstractor |
| _resumen = Abstractor.resumen(texto=texto) |
| return _resumen |
| @staticmethod |
| def text_to_img(texto:str=None, model:str="PROMPTHERO")->bytes: |
| """Genera un BITARRAY de la imagen con el texto dado. |
| |
| args: |
| texto (str) : Texto para generar imagen |
| return: |
| _img (str) : Imagen en BITARRAY |
| """ |
| |
| from api.core.controllers.text2image import Generador |
| _imagen = str() |
| if "RUNWAY" in model.upper(): |
| _imagen = Generador.using_runway_sd_15(prompt=texto) |
| elif "STABILITY" in model.upper(): |
| _imagen = Generador.using_stability_sd_21(prompt=texto) |
| elif "REALISTIC" in model.upper(): |
| _imagen = Generador.using_realistic_v14(prompt=texto) |
| elif "PROMPTHERO" in model.upper(): |
| _imagen = Generador.using_prompthero_openjourney(prompt=texto) |
| else: |
| _imagen = bytes("error", 'utf-8') |
| return _imagen |
| @staticmethod |
| def text_to_video(texto:str=None)->str: |
| """Genera un BITARRAY del video con el texto dado. |
| |
| args: |
| texto (str) : Texto para generar video |
| return: |
| _video (str) : Video en BITARRAY |
| """ |
| _video = str() |
| return _video |
| @staticmethod |
| def text_to_speach(texto:str=None)->str: |
| """Genera un BITARRAY del audio con el texto dado. |
| |
| args: |
| texto (str) : Texto para generar audio |
| return: |
| _speach (str) : Audio en BITARRAY |
| """ |
| _speach = str() |
| return _speach |
| @staticmethod |
| def image_to_image(task:str="MSLD", image:str=None, mask:str=None,**kwargs)->str: |
| """Genera una imagen a partir de una imagen |
| |
| args: |
| task (str) : Modelo a utilizar: MSLD, DEEP, SCRIBLE, etc.. |
| image (str) : Input Image |
| mask (str) : Mask Image |
| **kwargs (str) : Argumentos adicionales: inference, strnght, guidance... |
| return: |
| _image (str) : Imagen en BITARRAY |
| """ |
| _image = str() |
| return _image |
| |
|
|
|
|