Team Ai
Apppublic

coder160/gpu_machine_learner

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py93 linesDownload Raw Back to core
1class Demos:2    def __init__(self):3        from fastapi import FastAPI, HTTPException, Response, File4        self.api = FastAPI5        self.exception = HTTPException6        self.api_response = Response7        self.fileupload = File8    def validate_apikey(self,api_key)->bool:9        __validation = True10        return __validation11    @staticmethod12    def text_to_img(texto:str=None, model:str="PROMPTHERO")->bytes:13        """Genera un Bytes de la imagen con el texto dado.14 15        args:16            texto           (str)   :   Texto para generar imagen17        return:18            _img            (bytes) :   Imagen en Bytes19        """20        from api.core.controllers.text2image import Generador21        _imagen = str()22        if "RUNWAY" in model.upper():23            _imagen = Generador.using_runway_sd_15(prompt=texto)24        elif "STABILITY" in model.upper():25            _imagen = Generador.using_stability_sd_21(prompt=texto)26        elif "REALISTIC" in model.upper():27            _imagen = Generador.using_realistic_v14(prompt=texto)28        elif "PROMPTHERO" in model.upper():29            _imagen = Generador.using_prompthero_openjourney(prompt=texto)30        else:31            _imagen = bytes("error", 'utf-8')32        return _imagen33    @staticmethod34    def text_to_video(texto:str=None)->str:35        """Genera un BITARRAY del video con el texto dado.36 37        args:38            texto           (str)   :   Texto para generar video39        return:40            _video          (str)   :   Video en BITARRAY41        """42        _video = str()43        return _video44    @staticmethod45    def text_to_speach(texto:str=None)->str:46        """Genera un BITARRAY del audio con el texto dado.47 48        args:49            texto           (str)   :   Texto para generar audio50        return:51            _speach         (str)   :   Audio en BITARRAY52        """53        _speach = str()54        return _speach55    @staticmethod56    def image_to_image(task:str="MSLD", image:str=None, mask:str=None,**kwargs)->str:57        """Genera una imagen a partir de una imagen58 59        args:60            task            (str)   :   Modelo a utilizar: MSLD, DEEP, SCRIBLE, etc..61            image           (str)   :   Input Image62            mask            (str)   :   Mask Image63            **kwargs        (str)   :   Argumentos adicionales: inference, strnght, guidance...64        return:65            _image          (str)   :   Imagen en BITARRAY66        """67        _image = str()68        return _image69    @staticmethod70    def img_to_img(texto:str=None, model:str="PROMPTHERO")->bytes:71        """Genera un Bytes de la imagen con el texto dado.72 73        args:74            texto           (str)   :   Texto para generar imagen75        return:76            _img            (bytes) :   Imagen en Bytes77        """78        from api.core.controllers.text2image import Generador79        _imagen = str()80        if "RUNWAY" in model.upper():81            _imagen = Generador.using_runway_sd_15(prompt=texto)82        elif "STABILITY" in model.upper():83            _imagen = Generador.using_stability_sd_21(prompt=texto)84        elif "REALISTIC" in model.upper():85            _imagen = Generador.using_realistic_v14(prompt=texto)86        elif "PROMPTHERO" in model.upper():87            _imagen = Generador.using_prompthero_openjourney(prompt=texto)88        else:89            _imagen = bytes("error", 'utf-8')90        return _imagen91    92 93