Manjushri commited on
Commit
c4f2418
·
verified ·
1 Parent(s): b7b4dfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -11,19 +11,17 @@ torch.cuda.empty_cache()
11
 
12
  def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, upscale, high_noise_frac):
13
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
14
-
15
- if upscale == "Yes":
16
- refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
17
- refiner.enable_xformers_memory_efficient_attention()
18
- refiner = refiner.to(device)
19
- torch.cuda.empty_cache()
20
-
21
  if Model == "PhotoReal":
22
  pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
23
  pipe.enable_xformers_memory_efficient_attention()
24
  pipe = pipe.to(device)
25
  torch.cuda.empty_cache()
26
  if upscale == "Yes":
 
 
 
 
27
  int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
28
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
29
  torch.cuda.empty_cache()
@@ -39,6 +37,10 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
39
  anime = anime.to(device)
40
  torch.cuda.empty_cache()
41
  if upscale == "Yes":
 
 
 
 
42
  int_image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
43
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
44
  torch.cuda.empty_cache()
@@ -54,6 +56,10 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
54
  disney = disney.to(device)
55
  torch.cuda.empty_cache()
56
  if upscale == "Yes":
 
 
 
 
57
  int_image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
58
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
59
  torch.cuda.empty_cache()
@@ -69,6 +75,10 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
69
  story = story.to(device)
70
  torch.cuda.empty_cache()
71
  if upscale == "Yes":
 
 
 
 
72
  int_image = story(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
73
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
74
  torch.cuda.empty_cache()
@@ -84,6 +94,10 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
84
  semi = semi.to(device)
85
  torch.cuda.empty_cache()
86
  if upscale == "Yes":
 
 
 
 
87
  image = semi(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
88
  image = refiner(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
89
  torch.cuda.empty_cache()
@@ -99,6 +113,10 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
99
  animagine = animagine.to(device)
100
  torch.cuda.empty_cache()
101
  if upscale == "Yes":
 
 
 
 
102
  int_image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
103
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
104
  torch.cuda.empty_cache()
@@ -117,8 +135,12 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, up
117
  torch.cuda.empty_cache()
118
 
119
  if upscale == "Yes":
120
- torch.cuda.empty_cache()
121
  torch.cuda.max_memory_allocated(device=device)
 
 
 
 
 
122
  image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
123
  torch.cuda.empty_cache()
124
  refined = refiner(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
 
11
 
12
  def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, upscale, high_noise_frac):
13
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
14
+
 
 
 
 
 
 
15
  if Model == "PhotoReal":
16
  pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
17
  pipe.enable_xformers_memory_efficient_attention()
18
  pipe = pipe.to(device)
19
  torch.cuda.empty_cache()
20
  if upscale == "Yes":
21
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
22
+ refiner.enable_xformers_memory_efficient_attention()
23
+ refiner = refiner.to(device)
24
+ torch.cuda.empty_cache()
25
  int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
26
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
27
  torch.cuda.empty_cache()
 
37
  anime = anime.to(device)
38
  torch.cuda.empty_cache()
39
  if upscale == "Yes":
40
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
41
+ refiner.enable_xformers_memory_efficient_attention()
42
+ refiner = refiner.to(device)
43
+ torch.cuda.empty_cache()
44
  int_image = anime(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
45
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
46
  torch.cuda.empty_cache()
 
56
  disney = disney.to(device)
57
  torch.cuda.empty_cache()
58
  if upscale == "Yes":
59
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
60
+ refiner.enable_xformers_memory_efficient_attention()
61
+ refiner = refiner.to(device)
62
+ torch.cuda.empty_cache()
63
  int_image = disney(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
64
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
65
  torch.cuda.empty_cache()
 
75
  story = story.to(device)
76
  torch.cuda.empty_cache()
77
  if upscale == "Yes":
78
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
79
+ refiner.enable_xformers_memory_efficient_attention()
80
+ refiner = refiner.to(device)
81
+ torch.cuda.empty_cache()
82
  int_image = story(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
83
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
84
  torch.cuda.empty_cache()
 
94
  semi = semi.to(device)
95
  torch.cuda.empty_cache()
96
  if upscale == "Yes":
97
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
98
+ refiner.enable_xformers_memory_efficient_attention()
99
+ refiner = refiner.to(device)
100
+ torch.cuda.empty_cache()
101
  image = semi(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
102
  image = refiner(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
103
  torch.cuda.empty_cache()
 
113
  animagine = animagine.to(device)
114
  torch.cuda.empty_cache()
115
  if upscale == "Yes":
116
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
117
+ refiner.enable_xformers_memory_efficient_attention()
118
+ refiner = refiner.to(device)
119
+ torch.cuda.empty_cache()
120
  int_image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
121
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
122
  torch.cuda.empty_cache()
 
135
  torch.cuda.empty_cache()
136
 
137
  if upscale == "Yes":
 
138
  torch.cuda.max_memory_allocated(device=device)
139
+ torch.cuda.empty_cache()
140
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
141
+ refiner.enable_xformers_memory_efficient_attention()
142
+ refiner = refiner.to(device)
143
+ torch.cuda.empty_cache()
144
  image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
145
  torch.cuda.empty_cache()
146
  refined = refiner(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]