File size: 1,646 Bytes
4f48282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
##### GOT IT FROM https://github.com/huggingface/diffusers/issues/3579


import torch
import torchvision
from PIL import Image
from diffusers import EulerDiscreteScheduler, StableDiffusionPipeline

device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = StableDiffusionPipeline.from_pretrained(
    "prompthero/openjourney-v4", torch_dtype=torch.float16, safety_checker=None)
pipe = pipe.to(device)
pipe.enable_attention_slicing()
pipe.scheduler = EulerDiscreteScheduler.from_config(
    pipe.scheduler.config, use_karras_sigmas=True
)

prompt = "A futuristic cityscape at sunset"

negative_prompt = "low quality"

# num_images_per_prompt=4,

def progress(step, timestep, latents):
    print(step, timestep, latents[0][0][0][0])

    with torch.no_grad():

        latents = 1 / 0.18215 * latents
        image = pipe.vae.decode(latents).sample

        image = (image / 2 + 0.5).clamp(0, 1)

        # we always cast to float32 as this does not cause significant overhead and is compatible with bfloa16
        image = image.cpu().permute(0, 2, 3, 1).float().numpy()

        # convert to PIL Images
        image = pipe.numpy_to_pil(image)

        # do something with the Images
        for i, img in enumerate(image):
            img.save(f"step_{step}_img{i}.png")


result = pipe(prompt=prompt,
              num_inference_steps=20,
              height=512, width=512,
              guidance_scale=7,
              negative_prompt=negative_prompt,
              callback=progress,
              callback_steps=5
              )

image = result.images[0]

image.save(f"outputs/cikar goster.png")
print(result.nsfw_content_detected)