anzorq commited on
Commit
c675e7b
1 Parent(s): 91dd99d

Disable safety checker in colab

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -26,8 +26,9 @@ models = [
26
  Model("Midjourney v4 style", "prompthero/midjourney-v4-diffusion", "mdjrny-v4 style "),
27
  Model("Waifu", "hakurei/waifu-diffusion", ""),
28
  Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "dgs illustration style "),
29
- Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy ")
30
  ]
 
31
  #Model("Pokémon", "lambdalabs/sd-pokemon-diffusers", ""),
32
  #Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", ""),
33
  #Model("Robo Diffusion", "nousr/robo-diffusion", ""),
@@ -55,7 +56,7 @@ current_model = models[1] if is_colab else models[0]
55
  current_model_path = current_model.path
56
 
57
  if is_colab:
58
- pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16, scheduler=scheduler)
59
 
60
  else: # download all models
61
  vae = AutoencoderKL.from_pretrained(current_model.path, subfolder="vae", torch_dtype=torch.float16)
@@ -78,6 +79,12 @@ def custom_model_changed(path):
78
  global current_model
79
  current_model = models[0]
80
 
 
 
 
 
 
 
81
  def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
82
 
83
  global current_model
@@ -102,7 +109,7 @@ def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, g
102
  current_model_path = model_path
103
 
104
  if is_colab or current_model == custom_model:
105
- pipe = StableDiffusionPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler)
106
  else:
107
  pipe.to("cpu")
108
  pipe = current_model.pipe_t2i
@@ -133,7 +140,7 @@ def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, w
133
  current_model_path = model_path
134
 
135
  if is_colab or current_model == custom_model:
136
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler)
137
  else:
138
  pipe.to("cpu")
139
  pipe = current_model.pipe_i2i
@@ -160,6 +167,10 @@ def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, w
160
  return replace_nsfw_images(result)
161
 
162
  def replace_nsfw_images(results):
 
 
 
 
163
  for i in range(len(results.images)):
164
  if results.nsfw_content_detected[i]:
165
  results.images[i] = Image.open("nsfw.png")
@@ -176,7 +187,7 @@ with gr.Blocks(css=css) as demo:
176
  </div>
177
  <p>
178
  Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
179
- <a href="https://huggingface.co/nitrosocke/Arcane-Diffusion">Arcane</a>, <a href="https://huggingface.co/nitrosocke/archer-diffusion">Archer</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</a>, <a href="https://huggingface.co/nitrosocke/spider-verse-diffusion">Spider-Verse</a>, <a href="https://huggingface.co/nitrosocke/mo-di-diffusion">Modern Disney</a>, <a href="https://huggingface.co/nitrosocke/classic-anim-diffusion">Classic Disney</a>, <a href="https://huggingface.co/dallinmackay/Van-Gogh-diffusion">Loving Vincent (Van Gogh)</a>, <a href="https://huggingface.co/nitrosocke/redshift-diffusion">Redshift renderer (Cinema4D)</a>, <a href="https://huggingface.co/prompthero/midjourney-v4-diffusion">Midjourney v4 style</a>, <a href="https://huggingface.co/hakurei/waifu-diffusion">Waifu</a>, <a href="https://huggingface.co/lambdalabs/sd-pokemon-diffusers">Pokémon</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony Diffusion</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo Diffusion</a>, <a href="https://huggingface.co/DGSpitzer/Cyberpunk-Anime-Diffusion">Cyberpunk Anime</a>, <a href="https://huggingface.co/dallinmackay/Tron-Legacy-diffusion">Tron Legacy</a> + in colab notebook you can load any other Diffusers 🧨 SD model hosted on HuggingFace 🤗.
180
  </p>
181
  <p>You can skip the queue and load custom models in the colab: <a href="https://colab.research.google.com/gist/qunash/42112fb104509c24fd3aa6d1c11dd6e0/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
182
  Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
@@ -226,7 +237,7 @@ with gr.Blocks(css=css) as demo:
226
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
227
 
228
  if is_colab:
229
- model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
230
  custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
231
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
232
 
@@ -244,6 +255,7 @@ with gr.Blocks(css=css) as demo:
244
 
245
  gr.HTML("""
246
  <p>Models by <a href="https://huggingface.co/nitrosocke">@nitrosocke</a>, <a href="https://twitter.com/haruu1367">@haruu1367</a>, <a href="https://twitter.com/DGSpitzer">@Helixngc7293</a>, <a href="https://twitter.com/dal_mack">@dal_mack</a>, <a href="https://twitter.com/prompthero">@prompthero</a> and others. ❤️</p>
 
247
  <p>Space by: <a href="https://twitter.com/hahahahohohe"><img src="https://img.shields.io/twitter/follow/hahahahohohe?label=%40anzorq&style=social" alt="Twitter Follow"></a></p><br>
248
  <p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.finetuned_diffusion" alt="visitors"></p>
249
  """)
 
26
  Model("Midjourney v4 style", "prompthero/midjourney-v4-diffusion", "mdjrny-v4 style "),
27
  Model("Waifu", "hakurei/waifu-diffusion", ""),
28
  Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "dgs illustration style "),
29
+ Model("Balloon Art", "Fictiverse/Stable_Diffusion_BalloonArt_Model", "BalloonArt "),
30
  ]
31
+ # Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy ")
32
  #Model("Pokémon", "lambdalabs/sd-pokemon-diffusers", ""),
33
  #Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", ""),
34
  #Model("Robo Diffusion", "nousr/robo-diffusion", ""),
 
56
  current_model_path = current_model.path
57
 
58
  if is_colab:
59
+ pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16, scheduler=scheduler, safety_checker=lambda images, clip_input: (images, False))
60
 
61
  else: # download all models
62
  vae = AutoencoderKL.from_pretrained(current_model.path, subfolder="vae", torch_dtype=torch.float16)
 
79
  global current_model
80
  current_model = models[0]
81
 
82
+ def on_model_change(model_name):
83
+
84
+ prefix = "Enter prompt. \"" + next((m.prefix for m in models if m.name == model_name), None) + "\" is prefixed automatically" if model_name != models[0].name else "Don't forget to use the custom model prefix in the prompt!"
85
+
86
+ return gr.update(visible = model_name == models[0].name), gr.update(placeholder=prefix)
87
+
88
  def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
89
 
90
  global current_model
 
109
  current_model_path = model_path
110
 
111
  if is_colab or current_model == custom_model:
112
+ pipe = StableDiffusionPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler, safety_checker=lambda images, clip_input: (images, False))
113
  else:
114
  pipe.to("cpu")
115
  pipe = current_model.pipe_t2i
 
140
  current_model_path = model_path
141
 
142
  if is_colab or current_model == custom_model:
143
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler, safety_checker=lambda images, clip_input: (images, False))
144
  else:
145
  pipe.to("cpu")
146
  pipe = current_model.pipe_i2i
 
167
  return replace_nsfw_images(result)
168
 
169
  def replace_nsfw_images(results):
170
+
171
+ if is_colab:
172
+ return results.images[0]
173
+
174
  for i in range(len(results.images)):
175
  if results.nsfw_content_detected[i]:
176
  results.images[i] = Image.open("nsfw.png")
 
187
  </div>
188
  <p>
189
  Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
190
+ <a href="https://huggingface.co/nitrosocke/Arcane-Diffusion">Arcane</a>, <a href="https://huggingface.co/nitrosocke/archer-diffusion">Archer</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</a>, <a href="https://huggingface.co/nitrosocke/spider-verse-diffusion">Spider-Verse</a>, <a href="https://huggingface.co/nitrosocke/mo-di-diffusion">Modern Disney</a>, <a href="https://huggingface.co/nitrosocke/classic-anim-diffusion">Classic Disney</a>, <a href="https://huggingface.co/dallinmackay/Van-Gogh-diffusion">Loving Vincent (Van Gogh)</a>, <a href="https://huggingface.co/nitrosocke/redshift-diffusion">Redshift renderer (Cinema4D)</a>, <a href="https://huggingface.co/prompthero/midjourney-v4-diffusion">Midjourney v4 style</a>, <a href="https://huggingface.co/hakurei/waifu-diffusion">Waifu</a>, <a href="https://huggingface.co/lambdalabs/sd-pokemon-diffusers">Pokémon</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony Diffusion</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo Diffusion</a>, <a href="https://huggingface.co/DGSpitzer/Cyberpunk-Anime-Diffusion">Cyberpunk Anime</a>, <a href="https://huggingface.co/dallinmackay/Tron-Legacy-diffusion">Tron Legacy</a>, <a href="https://huggingface.co/Fictiverse/Stable_Diffusion_BalloonArt_Model">Balloon Art</a> + in colab notebook you can load any other Diffusers 🧨 SD model hosted on HuggingFace 🤗.
191
  </p>
192
  <p>You can skip the queue and load custom models in the colab: <a href="https://colab.research.google.com/gist/qunash/42112fb104509c24fd3aa6d1c11dd6e0/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
193
  Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
 
237
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
238
 
239
  if is_colab:
240
+ model_name.change(on_model_change, inputs=model_name, outputs=[custom_model_group, prompt], queue=False)
241
  custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
242
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
243
 
 
255
 
256
  gr.HTML("""
257
  <p>Models by <a href="https://huggingface.co/nitrosocke">@nitrosocke</a>, <a href="https://twitter.com/haruu1367">@haruu1367</a>, <a href="https://twitter.com/DGSpitzer">@Helixngc7293</a>, <a href="https://twitter.com/dal_mack">@dal_mack</a>, <a href="https://twitter.com/prompthero">@prompthero</a> and others. ❤️</p>
258
+ <p>This space uses the <a href="https://github.com/LuChengTHU/dpm-solver">DPM-Solver++</a> sampler by <a href="https://arxiv.org/abs/2206.00927">Cheng Lu, et al.</a>.</p>
259
  <p>Space by: <a href="https://twitter.com/hahahahohohe"><img src="https://img.shields.io/twitter/follow/hahahahohohe?label=%40anzorq&style=social" alt="Twitter Follow"></a></p><br>
260
  <p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.finetuned_diffusion" alt="visitors"></p>
261
  """)