Base Models

Let’s first see how we can generate images with Stable Diffusion XL:

from flushai.models.img2img import StableDiffusionXL

model = StableDiffusionXL(api_key="YOUR_API_KEY")

model.generate(
    prompt = 'A basketball player dunking, realistic, 4k, outer space', 
    image = 'https://flush-user-images.s3.amazonaws.com/generated_images/f1faf821-367f-4cdd-92bb-d50e5df7efde/image_199.jpg'
    negative_prompt = 'blurry, low quality', 
    num_images = 4, 
    height = 512, 
    width = 512, 
    steps = 25, 
    prompt_strength = 7.5, 
    seed = 5, 
)

All parameters are optional other than prompt. For more information on base models offered, see here.

Custom Models

Next, let’s see how we can generate images with custom models made on Flush:

from flushai.models.img2img import StableDiffusionXL

model = StableDiffusionXL(api_key="YOUR_API_KEY")

model.generate(
    prompt = 'A basketball player dunking, realistic, 4k, outer space', 
    model_id = "c50c49b4-14ae-4812-9bae-7e8be651baa8", 
    image = 'https://flush-user-images.s3.amazonaws.com/generated_images/f1faf821-367f-4cdd-92bb-d50e5df7efde/image_199.jpg'
    negative_prompt = 'blurry, low quality', 
    num_images = 4, 
    height = 512, 
    width = 512, 
    steps = 25, 
    prompt_strength = 7.5, 
    seed = 5, 
)

We get an array of image links as output. All parameters are optional other than prompt and model_id. For more information on how to create custom models to deploy, see here.

Upscalers

Now, let’s see how we can use upscalers to improve the quality of images in Flush. Currently, we only support the REALEsrgan upscaler. This can be initialized as follows:

from flushai.models.img2img.upscalers import RealESRGAN

upscaler = RealESRGAN(api_key="YOUR_API_KEY", scale=4)

The RealESRGAN upscaler supports scales of either 2, 4, or 8. We can then call the model with the following:

upscaler.generate(
    image = 'https://flush-user-images.s3.amazonaws.com/generated_images/f1faf821-367f-4cdd-92bb-d50e5df7efde/image_199.jpg'
)

We get an array of one image as output (to keep consistency). image is the only parameter in the generate function for upscalers.

DALLE

Flush also supports interaction with DALLE-2. In this case, we use DALLE’s image generation endpoint. We show an example of this below:

from flushai.models.txt2img import DALLE

model = DALLE()

model.generate(
    prompt = 'A photo of a tiger', 
    num_images = 4, 
    size = 512
)

It is important to note that DALLE only supports image sizes 256x256, 512x512, or 1024x1024. All parameters are optional other than prompt.