Manjushri commited on
Commit
c4b5d77
1 Parent(s): fdf21aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -108
app.py CHANGED
@@ -26,30 +26,11 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, re
26
  int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
27
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
28
  torch.cuda.empty_cache()
29
- if upscale == "Yes":
30
- refiner = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
31
- refiner.enable_xformers_memory_efficient_attention()
32
- refiner = refiner.to(device)
33
- torch.cuda.empty_cache()
34
- upscaled = refiner(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=15, guidance_scale=0).images[0]
35
- torch.cuda.empty_cache()
36
- return upscaled
37
- else:
38
- return image
39
  else:
40
- if upscale == "Yes":
41
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
42
- upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
43
- upscaler.enable_xformers_memory_efficient_attention()
44
- upscaler = upscaler.to(device)
45
- torch.cuda.empty_cache()
46
- upscaled = upscaler(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=15, guidance_scale=0).images[0]
47
- torch.cuda.empty_cache()
48
- return upscaled
49
- else:
50
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
51
- torch.cuda.empty_cache()
52
- return image
53
 
54
  if Model == "Animagine XL 3.0":
55
  animagine = DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0")
@@ -67,33 +48,11 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, re
67
  torch.cuda.empty_cache()
68
  image = animagine(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
69
  torch.cuda.empty_cache()
70
-
71
- if upscale == "Yes":
72
- animagine = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
73
- animagine.enable_xformers_memory_efficient_attention()
74
- animagine = animagine.to(device)
75
- torch.cuda.empty_cache()
76
- upscaled = animagine(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
77
- torch.cuda.empty_cache()
78
- return upscaled
79
- else:
80
- return image
81
  else:
82
- if upscale == "Yes":
83
- image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
84
-
85
- upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
86
- upscaler.enable_xformers_memory_efficient_attention()
87
- upscaler = upscaler.to(device)
88
- torch.cuda.empty_cache()
89
- upscaled = upscaler(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
90
- torch.cuda.empty_cache()
91
- return upscaled
92
- else:
93
-
94
- image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
95
- torch.cuda.empty_cache()
96
- return image
97
 
98
  if Model == "SDXL 1.0":
99
 
@@ -115,33 +74,11 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, re
115
  torch.cuda.empty_cache()
116
  refined = sdxl(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
117
  torch.cuda.empty_cache()
118
-
119
- if upscale == "Yes":
120
- sdxl = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
121
- sdxl.enable_xformers_memory_efficient_attention()
122
- sdxl = sdxl.to(device)
123
- torch.cuda.empty_cache()
124
- upscaled = sdxl(prompt=Prompt, negative_prompt=negative_prompt, image=refined, num_inference_steps=5, guidance_scale=0).images[0]
125
- torch.cuda.empty_cache()
126
- return upscaled
127
- else:
128
- return refined
129
- else:
130
- if upscale == "Yes":
131
- image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
132
- torch.cuda.empty_cache()
133
- torch.cuda.max_memory_allocated(device=device)
134
- upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
135
- upscaler.enable_xformers_memory_efficient_attention()
136
- upscaler = upscaler.to(device)
137
- torch.cuda.empty_cache()
138
- upscaled = upscaler(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
139
- torch.cuda.empty_cache()
140
- return upscaled
141
- else:
142
-
143
- image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
144
- torch.cuda.empty_cache()
145
 
146
  if Model == 'FusionXL':
147
  torch.cuda.empty_cache()
@@ -160,36 +97,11 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, re
160
  torch.cuda.empty_cache()
161
  image = pipe(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
162
  torch.cuda.empty_cache()
163
- if upscale == "Yes":
164
- torch.cuda.empty_cache()
165
- torch.cuda.max_memory_allocated(device=device)
166
- upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
167
- upscaler.enable_xformers_memory_efficient_attention()
168
- upscaler = upscaler.to(device)
169
- torch.cuda.empty_cache()
170
- upscaled = upscaler(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
171
- torch.cuda.empty_cache()
172
- return upscaled
173
- else:
174
- return image
175
  else:
176
- if upscale == "Yes":
177
-
178
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
179
- torch.cuda.empty_cache()
180
- torch.cuda.max_memory_allocated(device=device)
181
-
182
- upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
183
- upscaler.enable_xformers_memory_efficient_attention()
184
- upscaler = upscaler.to(device)
185
- torch.cuda.empty_cache()
186
- upscaled = upscaler(prompt=Prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
187
- torch.cuda.empty_cache()
188
- return upscaled
189
- else:
190
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
191
- torch.cuda.empty_cache()
192
- return image
193
 
194
  return image
195
 
@@ -202,9 +114,8 @@ gr.Interface(fn=genie, inputs=[gr.Radio(['PhotoReal', 'Animagine XL 3.0', 'SDXL
202
  gr.Slider(5, maximum=100, value=50, step=5, label='Number of Iterations'),
203
  gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random'),
204
  gr.Radio(["Yes", "No"], label='SDXL 1.0 Refiner: Use if the Image has too much Noise', value='No'),
205
- gr.Slider(minimum=.9, maximum=.99, value=.95, step=.01, label='Refiner Denoise Start %'),
206
- gr.Radio(["Yes", "No"], label = 'SD X2 Latent Upscaler?', value="No")],
207
  outputs=gr.Image(label='Generated Image'),
208
- title="Manju Dream Booth V2.0 with SDXL 1.0 Refiner and SD X2 Latent Upscaler - GPU",
209
  description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
210
  article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE: D9QdVPtcU1EFH8jDC8jhU9uBcSTqUiA8h6<br><br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)
 
26
  int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
27
  image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
28
  torch.cuda.empty_cache()
29
+ return image
 
 
 
 
 
 
 
 
 
30
  else:
31
+ image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
32
+ torch.cuda.empty_cache()
33
+ return image
 
 
 
 
 
 
 
 
 
 
34
 
35
  if Model == "Animagine XL 3.0":
36
  animagine = DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0")
 
48
  torch.cuda.empty_cache()
49
  image = animagine(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
50
  torch.cuda.empty_cache()
51
+ return image
 
 
 
 
 
 
 
 
 
 
52
  else:
53
+ image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
54
+ torch.cuda.empty_cache()
55
+ return image
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  if Model == "SDXL 1.0":
58
 
 
74
  torch.cuda.empty_cache()
75
  refined = sdxl(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
76
  torch.cuda.empty_cache()
77
+ return refined
78
+ else:
79
+ image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
80
+ torch.cuda.empty_cache()
81
+ return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  if Model == 'FusionXL':
84
  torch.cuda.empty_cache()
 
97
  torch.cuda.empty_cache()
98
  image = pipe(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
99
  torch.cuda.empty_cache()
100
+ return image
 
 
 
 
 
 
 
 
 
 
 
101
  else:
102
+ image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
103
+ torch.cuda.empty_cache()
104
+ return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  return image
107
 
 
114
  gr.Slider(5, maximum=100, value=50, step=5, label='Number of Iterations'),
115
  gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random'),
116
  gr.Radio(["Yes", "No"], label='SDXL 1.0 Refiner: Use if the Image has too much Noise', value='No'),
117
+ gr.Slider(minimum=.9, maximum=.99, value=.95, step=.01, label='Refiner Denoise Start %')],
 
118
  outputs=gr.Image(label='Generated Image'),
119
+ title="Manju Dream Booth V2.1 with SDXL 1.0 Refiner - GPU",
120
  description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
121
  article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE: D9QdVPtcU1EFH8jDC8jhU9uBcSTqUiA8h6<br><br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)