| from diffusers import DiffusionPipeline as Pipe | |
| import torch | |
| class Generador: | |
| def using_runway_sd_15(prompt:str)->list: | |
| try: | |
| _generador = Pipe.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16) | |
| _generador.to("cuda") | |
| _imagen = _generador(prompt).images[0] | |
| _response = list(_imagen.getdata()) | |
| except Exception as e: | |
| _response = list(str(e)) | |
| finally: | |
| return _response | |
| def using_stability_sd_21(prompt:str)->list: | |
| try: | |
| _generador = Pipe.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16) | |
| _generador.to("cuda") | |
| _imagen = _generador(prompt).images[0] | |
| _response = list(_imagen.getdata()) | |
| except Exception as e: | |
| _response = list(str(e)) | |
| finally: | |
| return _response | |
| def using_realistic_v14(prompt:str)->list: | |
| try: | |
| _generador = Pipe.from_pretrained("SG161222/Realistic_Vision_V1.4", torch_dtype=torch.float16) | |
| _generador.to("cuda") | |
| _imagen = _generador(prompt).images[0] | |
| _response = list(_imagen.getdata()) | |
| except Exception as e: | |
| _response = list(str(e)) | |
| finally: | |
| return _response | |
| def using_prompthero_openjourney(prompt:str)->list: | |
| try: | |
| _generador = Pipe.from_pretrained("prompthero/openjourney", torch_dtype=torch.float16) | |
| _generador.to("cuda") | |
| _imagen = _generador(prompt).images[0] | |
| _response = list(_imagen.getdata()) | |
| except Exception as e: | |
| _response = list(str(e)) | |
| finally: | |
| return _response | |