Spaces:
Running
on
Zero
Running
on
Zero
import imagen_hub | |
class ImagenHubModel(): | |
def __init__(self, model_name): | |
self.model = imagen_hub.load(model_name) | |
def __call__(self, *args, **kwargs): | |
return self.model.infer_one_image(*args, **kwargs) | |
class PNP(ImagenHubModel): | |
def __init__(self): | |
super().__init__('PNP') | |
def __call__(self, *args, **kwargs): | |
if "num_inversion_steps" not in kwargs: | |
kwargs["num_inversion_steps"] = 200 | |
return super().__call__(*args, **kwargs) | |
class Prompt2prompt(ImagenHubModel): | |
def __init__(self): | |
super().__init__('Prompt2prompt') | |
def __call__(self, *args, **kwargs): | |
if "num_inner_steps" not in kwargs: | |
kwargs["num_inner_steps"] = 3 | |
return super().__call__(*args, **kwargs) | |
def load_imagenhub_model(model_name, model_type=None): | |
if model_name == 'PNP': | |
return PNP() | |
if model_name == 'Prompt2prompt': | |
return Prompt2prompt() | |
return ImagenHubModel(model_name) | |
# for name in ['DeepFloydIF', 'PixArtAlpha', 'Kandinsky']: #, 'OpenJourney', 'LCM', 'SD' 'SDXL' | |
# # | |
# pipe = ImagenHubModel(name) | |
# result = pipe(prompt='a cute dog is playing a ball') | |
# print(result) | |
# for name in ['SD']: | |
# from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler | |
# import torch | |
# pipe = DiffusionPipeline.from_pretrained( | |
# "stabilityai/stable-diffusion-2-base", | |
# torch_dtype=torch.float16, | |
# safety_checker=None, | |
# ).to("cuda") | |
# pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) |