import gradio as gr import torch from PIL import Image from lambda_diffusers import StableDiffusionImageEmbedPipeline def ask(input_im, scale, steps, seed, images): images = images generator = torch.Generator(device=device).manual_seed(int(seed)) images_list = pipe( 2*[input_im], guidance_scale=scale, num_inference_steps=steps, generator=generator, ) for i, image in enumerate(images_list["sample"]): if(images_list["nsfw_content_detected"][i]): safe_image = Image.open(r"unsafe.png") images.append(safe_image) else: images.append(image) return images def main(input_im, n_pairs, scale, steps, seed): print('Start the magic !') images = [] for i in range(n_pairs): print('Asking for a new pair of image [' + str(i + 1) + '/' + str(n_pairs) + ']') seed = seed+i images = ask(input_im, scale, steps, seed, images) print('Thanks to Sylvain, it worked like a charm!') return images device = "cuda" if torch.cuda.is_available() else "cpu" pipe = StableDiffusionImageEmbedPipeline.from_pretrained( "lambdalabs/sd-image-variations-diffusers", revision="273115e88df42350019ef4d628265b8c29ef4af5", ) pipe = pipe.to(device) inputs = [ gr.Image(), gr.Slider(0, 3, value=2, step=1, label="Pairs of images to ask"), gr.Slider(0, 25, value=3, step=1, label="Guidance scale"), gr.Slider(5, 50, value=25, step=5, label="Steps"), gr.Slider(label = "Seed", minimum = 0, maximum = 2147483647, step = 1, randomize = True) ] output = gr.Gallery(label="Generated variations") output.style(grid=2, height="") description = \ """
This demo is running on CPU. Working version fixed by Sylvain @fffiloni. You'll get n pairs of images variations.
Asking for pairs of images instead of more than 2 images in a row helps us to avoid heavy CPU load and connection error out ;)
Waiting time (for 2 pairs): ~5/10 minutes • NSFW filters enabled •
Generate variations on an input image using a fine-tuned version of Stable Diffusion.
Trained by Justin Pinkney (@Buntworthy) at Lambda
This version has been ported to 🤗 Diffusers library, see more details on how to use this version in the Lambda Diffusers repo.
For the original training code see this repo.