LuChengTHU commited on
Commit
11a403f
β€’
1 Parent(s): f19f05b

omit some models

Browse files
Files changed (2) hide show
  1. app.py +9 -19
  2. requirements.txt +0 -1
app.py CHANGED
@@ -36,17 +36,15 @@ class Model:
36
  self.pipe_i2i = None
37
 
38
  models = [
39
- Model("Custom model", "", ""),
40
- # Model("Stable-Diffusion-v1.5", "../stable-diffusion-v1-5", "The 1.5 version of official stable-diffusion"),
41
  Model("Stable-Diffusion-v1.4", "CompVis/stable-diffusion-v1-4", "The 1.4 version of official stable-diffusion"),
42
  # Model("Stable-Diffusion-v1.5", "runwayml/stable-diffusion-v1-5", "The 1.5 version of official stable-diffusion"),
43
  # Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style "),
44
  # Model("Archer", "nitrosocke/archer-diffusion", "archer style "),
45
- Model("Elden Ring", "nitrosocke/elden-ring-diffusion", "elden ring style "),
46
  # Model("Spider-Verse", "nitrosocke/spider-verse-diffusion", "spiderverse style "),
47
  # Model("Modern Disney", "nitrosocke/mo-di-diffusion", "modern disney style "),
48
  # Model("Classic Disney", "nitrosocke/classic-anim-diffusion", "classic disney style "),
49
- Model("Waifu", "hakurei/waifu-diffusion", ""),
50
  # Model("PokΓ©mon", "lambdalabs/sd-pokemon-diffusers", ""),
51
  # Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", ""),
52
  # Model("Robo Diffusion", "nousr/robo-diffusion", ""),
@@ -55,7 +53,7 @@ models = [
55
  ]
56
 
57
  last_mode = "txt2img"
58
- current_model = models[1]
59
  current_model_path = current_model.path
60
 
61
  auth_token = os.getenv("HUGGING_FACE_HUB_TOKEN")
@@ -65,25 +63,20 @@ if is_colab:
65
 
66
  else: # download all models
67
  vae = AutoencoderKL.from_pretrained(current_model.path, subfolder="vae", torch_dtype=torch.float16, use_auth_token=auth_token)
68
- for model in models[1:]:
69
  try:
70
  unet = UNet2DConditionModel.from_pretrained(model.path, subfolder="unet", torch_dtype=torch.float16, use_auth_token=auth_token)
71
  model.pipe_t2i = StableDiffusionPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler, use_auth_token=auth_token)
72
  model.pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler, use_auth_token=auth_token)
73
  except:
74
  models.remove(model)
75
- pipe = models[1].pipe_t2i
76
 
77
  if torch.cuda.is_available():
78
  pipe = pipe.to("cuda")
79
 
80
  device = "GPU πŸ”₯" if torch.cuda.is_available() else "CPU πŸ₯Ά"
81
 
82
- def custom_model_changed(path):
83
- models[0].path = path
84
- global current_model
85
- current_model = models[0]
86
-
87
  def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
88
 
89
  global current_model
@@ -221,7 +214,7 @@ with gr.Blocks(css=css) as demo:
221
  <br>
222
  <p>
223
  Demo for sampling by DPM-Solver with several fine-tuned Stable Diffusion models, trained on different styles: <br>
224
- <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4">Stable-Diffusion-v1.4</a>, <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5">Stable-Diffusion-v1.5</a>, <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/modern-disney-diffusion">Modern Disney</a>, <a href="https://huggingface.co/nitrosocke/classic-anim-diffusion">Classic Disney</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> + any other custom Diffusers 🧨 SD model hosted on HuggingFace πŸ€—.
225
  </p>
226
  </div>
227
  """
@@ -230,15 +223,13 @@ with gr.Blocks(css=css) as demo:
230
  # <p>Don't want to wait in queue? <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>
231
  # Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
232
  # </p>
 
 
233
  with gr.Row():
234
 
235
  with gr.Column(scale=55):
236
  with gr.Group():
237
  model_name = gr.Dropdown(label="Model", choices=[m.name for m in models], value=current_model.name)
238
- with gr.Box(visible=False) as custom_model_group:
239
- custom_model_path = gr.Textbox(label="Custom model path", placeholder="Path to model, e.g. nitrosocke/Arcane-Diffusion", interactive=True)
240
- gr.HTML("<div><font size='2'>Custom models have to be downloaded first, so give it some time.</font></div>")
241
-
242
  with gr.Row():
243
  prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="Enter prompt. Style applied automatically").style(container=False)
244
  generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
@@ -271,8 +262,7 @@ with gr.Blocks(css=css) as demo:
271
  image = gr.Image(label="Image", height=256, tool="editor", type="pil")
272
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
273
 
274
- model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
275
- custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
276
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
277
 
278
  inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
 
36
  self.pipe_i2i = None
37
 
38
  models = [
 
 
39
  Model("Stable-Diffusion-v1.4", "CompVis/stable-diffusion-v1-4", "The 1.4 version of official stable-diffusion"),
40
  # Model("Stable-Diffusion-v1.5", "runwayml/stable-diffusion-v1-5", "The 1.5 version of official stable-diffusion"),
41
  # Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style "),
42
  # Model("Archer", "nitrosocke/archer-diffusion", "archer style "),
43
+ # Model("Elden Ring", "nitrosocke/elden-ring-diffusion", "elden ring style "),
44
  # Model("Spider-Verse", "nitrosocke/spider-verse-diffusion", "spiderverse style "),
45
  # Model("Modern Disney", "nitrosocke/mo-di-diffusion", "modern disney style "),
46
  # Model("Classic Disney", "nitrosocke/classic-anim-diffusion", "classic disney style "),
47
+ # Model("Waifu", "hakurei/waifu-diffusion", ""),
48
  # Model("PokΓ©mon", "lambdalabs/sd-pokemon-diffusers", ""),
49
  # Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", ""),
50
  # Model("Robo Diffusion", "nousr/robo-diffusion", ""),
 
53
  ]
54
 
55
  last_mode = "txt2img"
56
+ current_model = models[0]
57
  current_model_path = current_model.path
58
 
59
  auth_token = os.getenv("HUGGING_FACE_HUB_TOKEN")
 
63
 
64
  else: # download all models
65
  vae = AutoencoderKL.from_pretrained(current_model.path, subfolder="vae", torch_dtype=torch.float16, use_auth_token=auth_token)
66
+ for model in models:
67
  try:
68
  unet = UNet2DConditionModel.from_pretrained(model.path, subfolder="unet", torch_dtype=torch.float16, use_auth_token=auth_token)
69
  model.pipe_t2i = StableDiffusionPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler, use_auth_token=auth_token)
70
  model.pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler, use_auth_token=auth_token)
71
  except:
72
  models.remove(model)
73
+ pipe = models[0].pipe_t2i
74
 
75
  if torch.cuda.is_available():
76
  pipe = pipe.to("cuda")
77
 
78
  device = "GPU πŸ”₯" if torch.cuda.is_available() else "CPU πŸ₯Ά"
79
 
 
 
 
 
 
80
  def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
81
 
82
  global current_model
 
214
  <br>
215
  <p>
216
  Demo for sampling by DPM-Solver with several fine-tuned Stable Diffusion models, trained on different styles: <br>
217
+ <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4">Stable-Diffusion-v1.4</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</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> + any other custom Diffusers 🧨 SD model hosted on HuggingFace πŸ€—.
218
  </p>
219
  </div>
220
  """
 
223
  # <p>Don't want to wait in queue? <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>
224
  # Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
225
  # </p>
226
+
227
+ # TODO: do not support the custom model
228
  with gr.Row():
229
 
230
  with gr.Column(scale=55):
231
  with gr.Group():
232
  model_name = gr.Dropdown(label="Model", choices=[m.name for m in models], value=current_model.name)
 
 
 
 
233
  with gr.Row():
234
  prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="Enter prompt. Style applied automatically").style(container=False)
235
  generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
 
262
  image = gr.Image(label="Image", height=256, tool="editor", type="pil")
263
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
264
 
265
+ # model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
 
266
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
267
 
268
  inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- --extra-index-url https://download.pytorch.org/whl/cu113
2
  torch
3
  git+https://github.com/huggingface/diffusers.git
4
  transformers
 
 
1
  torch
2
  git+https://github.com/huggingface/diffusers.git
3
  transformers