InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

Invoking dream directly through Python

Open veprogames opened this issue 4 years ago • 2 comments

I don't know if it's possible or not, but what if dream could be directly invoked in python? It would have the form of

def dream(prompt, **config) -> PIL.Image[]

where the config kwargs take the same name as in the dream console. config.init_img or config.I would be of instance PIL.Image.

example:

images = dream("A tasty burger", s=100, S=42, C=10, n=4)
new_images = dream("A tasty burger with fries", I=images[0], f=0.6, n=4)
final_image = new_images[0]
final_image.save("out.png")

This can help developers who are interested in automating stuff or using Stable Diffusion as part of another project. From quickly looking over the code, my guess is that T2I.prompt_to_image() needs to be called, which leads me to the guess that:

the module dream_api contains the following functions:

def load_model() # do the things that are done when starting scripts/dream.py until the dream cli is ready
def dream(prompt, **config) -> PIL.Image[]

veprogames avatar Aug 26 '22 18:08 veprogames

Yeah prompt2image does exactly this. It's pretty straightforward to use:

t2i = T2I()
t2i.load_model()
images = t2i.prompt2image( whatever )

What else are you looking for?

bakkot avatar Aug 26 '22 18:08 bakkot

so I guess this can be closed. No need to wrap that

veprogames avatar Aug 26 '22 18:08 veprogames