Norod78 commited on
Commit
7c052fc
1 Parent(s): d38714e

Upload GenerateExamples.py

Browse files
Files changed (1) hide show
  1. GenerateExamples.py +93 -0
GenerateExamples.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler, AutoencoderKL
2
+ import torch
3
+ import os
4
+
5
+
6
+ #////////////////////////////////////////////////////////////////
7
+ guidance_scale=7
8
+ steps=20
9
+ width=1024
10
+ height=1024
11
+ base_model_id_str = "SDXL-xmasize-Lora-Images"
12
+ prompt_prefix = ""
13
+ prompt_suffix = " xmasize, Very detailed, clean, high quality, sharp image"
14
+ neg_prompt = "text, watermark, grainy, blurry, unfocused, nsfw, naked, nude, noisy image, deformed, distorted, pixelated"
15
+ #////////////////////////////////////////////////////////////////
16
+ base = None
17
+ refiner = None
18
+ #////////////////////////////////////////////////////////////////
19
+
20
+
21
+ def load():
22
+ global base, refiner
23
+
24
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
25
+ base = DiffusionPipeline.from_pretrained(
26
+ "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
27
+ )
28
+ base.to("cuda")
29
+ base.load_lora_weights("Norod78/SDXL-xmasize-Lora")
30
+ base.enable_xformers_memory_efficient_attention()
31
+ refiner = DiffusionPipeline.from_pretrained(
32
+ "stabilityai/stable-diffusion-xl-refiner-1.0",
33
+ text_encoder_2=base.text_encoder_2,
34
+ vae=base.vae,
35
+ torch_dtype=torch.float16,
36
+ use_safetensors=True,
37
+ variant="fp16",
38
+ )
39
+ refiner.to("cuda")
40
+ refiner.enable_xformers_memory_efficient_attention()
41
+
42
+ def generate(prompt, file_prefix ,samples = 2, seed = 7777):
43
+ global base, refiner
44
+
45
+ torch.manual_seed(seed)
46
+ prompt = prompt_prefix + prompt
47
+ prompt += prompt_suffix
48
+ base_model_latents = base([prompt] * samples,
49
+ negative_prompt = [neg_prompt] * samples,
50
+ num_inference_steps=steps,
51
+ guidance_scale=guidance_scale,
52
+ height=height, width=width,
53
+ output_type="latent")["images"]
54
+ torch.manual_seed(seed)
55
+ refiner_model_images = refiner([prompt] * samples,
56
+ negative_prompt = [neg_prompt] * samples,
57
+ num_inference_steps=steps,
58
+ image=base_model_latents)["images"]
59
+ for idx, image in enumerate(refiner_model_images):
60
+ image.save(f"{base_model_id_str}/{file_prefix}-{idx}-{seed}--{width}x{height}--{guidance_scale}--{base_model_id_str}.jpg")
61
+
62
+ def main():
63
+ load()
64
+
65
+ os.mkdir(base_model_id_str)
66
+
67
+ generate("A livingroom", "01_LivingRoom")
68
+ generate("A nice town", "02_NiceTown")
69
+ generate("A scene in \"The Minions\" movie", "03_MinionsMovie")
70
+ generate("Wonderwoman", "04_Wonderwoman")
71
+ generate("Marge Simpson", "05_MargeSimpson")
72
+ generate("A beautiful woman", "06_BeautifulWoman")
73
+ generate("A magical landscape", "07_MagicalLandscape")
74
+ generate("Cute dog", "08_CuteDog")
75
+ generate("An oil on canvas portrait of Snoop Dogg, Mark Ryden", "09_SnoopDog")
76
+ generate("A flemish baroque painting of Kermit from the muppet show", "10_KermitFlemishBaroque")
77
+ generate("Gal Gadot in Avatar", "11_GalGadotAvatar")
78
+ generate("Ninja turtles, Naoto Hattori", "12_TMNT")
79
+ generate("A socially awkward potato", "13_AwkwardPotato")
80
+ generate("Pikachu as Rick and morty, Eric Wallis", "14_PikachuRnM")
81
+ generate("The girl with pearl earing", "15_PearlEaring")
82
+ generate("American Gothic ", "16_AmericanGothic")
83
+ generate("Miss. Piggy as the Mona Lisa", "17_MsPiggyMonaLisa")
84
+ generate("Rick Sanchez from the TV show \"Rick and Morty\"", "18_RickSanchez")
85
+ generate("A paiting of Southpark with rainbow", "19_Southpark")
86
+ generate("An oil painting of Phineas and Pherb hamering on a new machine, Eric Wallis", "20_PhineasPherb")
87
+ generate("Bender, Saturno Butto", "21_Bender")
88
+ generate("A psychedelic image of Bojack Horseman", "22_Bojack")
89
+ generate("A movie poster for Gravity Falls Cthulhu stories", "23_GravityFalls")
90
+ generate("A vibrant oil painting portrait of She-Ra", "24_Shira", 2, 512)
91
+
92
+ if __name__ == '__main__':
93
+ main()