LuChengTHU commited on
Commit
c9b0019
β€’
1 Parent(s): d461b4f

change styles

Browse files
Files changed (1) hide show
  1. app.py +33 -49
app.py CHANGED
@@ -17,16 +17,6 @@ scheduler = DPMSolverMultistepScheduler(
17
  lower_order_final=True,
18
  )
19
 
20
- def is_google_colab():
21
- try:
22
- import google.colab
23
- return True
24
- except:
25
- return False
26
-
27
- is_colab = is_google_colab()
28
-
29
-
30
  class Model:
31
  def __init__(self, name, path, prefix):
32
  self.name = name
@@ -37,19 +27,9 @@ class Model:
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", ""),
51
- # Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "dgs illustration style "),
52
- # Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy ")
53
  ]
54
 
55
  last_mode = "txt2img"
@@ -173,6 +153,7 @@ css = """
173
  text-align: center;
174
  max-width: 700px;
175
  margin: 0 auto;
 
176
  }
177
  .finetuned-diffusion-div div {
178
  display: inline-flex;
@@ -182,7 +163,9 @@ css = """
182
  }
183
  .finetuned-diffusion-div div h1 {
184
  font-weight: 900;
185
- margin-bottom: 7px;
 
 
186
  }
187
  .finetuned-diffusion-div p {
188
  margin-bottom: 10px;
@@ -198,6 +181,11 @@ css = """
198
  #gallery {
199
  min-height: 20rem;
200
  }
 
 
 
 
 
201
  </style>
202
  """
203
  with gr.Blocks(css=css) as demo:
@@ -205,29 +193,36 @@ with gr.Blocks(css=css) as demo:
205
  f"""
206
  <div class="finetuned-diffusion-div">
207
  <div>
208
- <h1>Finetuned Diffusion with DPM-Solver (fastest sampler for diffusion models) </h1>
209
  </div>
210
  <br>
 
 
 
 
 
 
 
 
 
211
  <p>
212
  <a href="https://github.com/LuChengTHU/dpm-solver">DPM-Solver</a> (Neurips 2022 Oral) is a fast high-order solver customized for diffusion ODEs, which can generate high-quality samples by diffusion models within only 10-25 steps. DPM-Solver has an analytical formulation and is very easy to use for all types of Gaussian diffusion models, and includes <a href="https://arxiv.org/abs/2010.02502">DDIM</a> as a first-order special case.
213
  </p>
214
  <p>
215
- We use <a href="https://github.com/huggingface/diffusers">Diffusers</a> to implement this demo, which currently supports the multistep DPM-Solver scheduler. For more details of DPM-Solver with Diffusers, check <a href="https://github.com/huggingface/diffusers/pull/1132">this pull request</a>.
216
  </p>
217
  <br>
218
  <p>
219
- Demo for sampling by DPM-Solver with several fine-tuned Stable Diffusion models, trained on different styles: <br>
220
- <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 πŸ€—.
 
 
 
221
  </p>
222
  </div>
223
  """
224
  )
225
- # TODO: the colab version is wrong.
226
- # <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>
227
- # Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
228
- # </p>
229
 
230
- # TODO: do not support the custom model
231
  with gr.Row():
232
 
233
  with gr.Column(scale=55):
@@ -266,30 +261,19 @@ with gr.Blocks(css=css) as demo:
266
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
267
 
268
  # model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
269
- # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
270
 
271
  inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
272
  prompt.submit(inference, inputs=inputs, outputs=image_out)
273
- generate.click(inference, inputs=inputs, outputs=image_out)
274
 
 
275
 
276
- # TODO: the docs here are wrong.
277
- # ex = gr.Examples([
278
- # [models[1].name, "jason bateman disassembling the demon core", 7.5, 50],
279
- # # [models[1+2].name, "jason bateman disassembling the demon core", 7.5, 50],
280
- # # [models[4+2].name, "portrait of dwayne johnson", 7.0, 75],
281
- # # [models[5+2].name, "portrait of a beautiful alyx vance half life", 10, 50],
282
- # # [models[6+2].name, "Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7.0, 45],
283
- # # [models[5+2].name, "fantasy portrait painting, digital art", 4.0, 30],
284
- # ], [model_name, prompt, guidance, steps, seed], image_out, inference, cache_examples=False)
285
 
286
  gr.Markdown('''
287
- Models by [@nitrosocke](https://huggingface.co/nitrosocke), [@haruu1367](https://twitter.com/haruu1367), [@Helixngc7293](https://twitter.com/DGSpitzer) and others. Code are copied from [@anzorq's fintuned_diffusion](https://huggingface.co/spaces/anzorq/finetuned_diffusion/tree/main) ❀️<br>
288
- Space by: [![Twitter Follow](https://img.shields.io/twitter/follow/ChengLu05671218?label=%40ChengLu&style=social)](https://twitter.com/ChengLu05671218)
289
 
290
  ![visitors](https://visitor-badge.glitch.me/badge?page_id=LuChengTHU.dpmsolver_sdm)
291
  ''')
292
 
293
- if not is_colab:
294
- demo.queue(concurrency_count=1)
295
- demo.launch(debug=is_colab, share=is_colab)
 
17
  lower_order_final=True,
18
  )
19
 
 
 
 
 
 
 
 
 
 
 
20
  class Model:
21
  def __init__(self, name, path, prefix):
22
  self.name = name
 
27
 
28
  models = [
29
  Model("Stable-Diffusion-v1.4", "CompVis/stable-diffusion-v1-4", "The 1.4 version of official stable-diffusion"),
30
+ Model("Waifu", "hakurei/waifu-diffusion", "anime style"),
31
+ Model("PokΓ©mon", "lambdalabs/sd-pokemon-diffusers", "pokemon style"),
32
+ Model("Modern Disney", "nitrosocke/mo-di-diffusion", "modern disney style"),
 
 
 
 
 
 
 
 
 
 
33
  ]
34
 
35
  last_mode = "txt2img"
 
153
  text-align: center;
154
  max-width: 700px;
155
  margin: 0 auto;
156
+ font-family: 'IBM Plex Sans', sans-serif;
157
  }
158
  .finetuned-diffusion-div div {
159
  display: inline-flex;
 
163
  }
164
  .finetuned-diffusion-div div h1 {
165
  font-weight: 900;
166
+ margin-top: 15px;
167
+ margin-bottom: 15px;
168
+ text-align: center;
169
  }
170
  .finetuned-diffusion-div p {
171
  margin-bottom: 10px;
 
181
  #gallery {
182
  min-height: 20rem;
183
  }
184
+ .container {
185
+ max-width: 1000px;
186
+ margin: auto;
187
+ padding-top: 1.5rem;
188
+ }
189
  </style>
190
  """
191
  with gr.Blocks(css=css) as demo:
 
193
  f"""
194
  <div class="finetuned-diffusion-div">
195
  <div>
196
+ <h1>Stable-Diffusion with DPM-Solver (fastest sampler for diffusion models) </h1>
197
  </div>
198
  <br>
199
+ <p>
200
+ Acknowledgement: Hardware resources of this demo are supported by HuggingFace πŸ€— . Many thanks for the help!
201
+ </p>
202
+ <br>
203
+ <p>
204
+ This is a demo of sampling by DPM-Solver with several fine-tuned Stable Diffusion models, trained on different styles: <br>
205
+ <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4">Stable-Diffusion-v1.4</a>, <a href="https://huggingface.co/nitrosocke/modern-disney-diffusion">Modern Disney</a>, <a href="https://huggingface.co/hakurei/waifu-diffusion">Waifu</a>, <a href="https://huggingface.co/lambdalabs/sd-pokemon-diffusers">PokΓ©mon</a>.
206
+ </p>
207
+ <br>
208
  <p>
209
  <a href="https://github.com/LuChengTHU/dpm-solver">DPM-Solver</a> (Neurips 2022 Oral) is a fast high-order solver customized for diffusion ODEs, which can generate high-quality samples by diffusion models within only 10-25 steps. DPM-Solver has an analytical formulation and is very easy to use for all types of Gaussian diffusion models, and includes <a href="https://arxiv.org/abs/2010.02502">DDIM</a> as a first-order special case.
210
  </p>
211
  <p>
212
+ We use <a href="https://github.com/huggingface/diffusers">Diffusers</a> 🧨 to implement this demo, which currently supports the multistep DPM-Solver scheduler. For more details of DPM-Solver with Diffusers, check <a href="https://github.com/huggingface/diffusers/pull/1132">this pull request</a>.
213
  </p>
214
  <br>
215
  <p>
216
+ Currently, the default sampler of stable-diffusion is <a href="https://arxiv.org/abs/2202.09778">PNDM</a>, which needs 50 steps to generate high-quality samples. However, DPM-Solver can generate high-quality samples within only <span style="font-weight: bold;">20-25</span> steps, and for some samples even within <span style="font-weight: bold;">10-15</span> steps.
217
+ </p>
218
+ <br>
219
+ <p>
220
+ Running on <b>{device}</b>
221
  </p>
222
  </div>
223
  """
224
  )
 
 
 
 
225
 
 
226
  with gr.Row():
227
 
228
  with gr.Column(scale=55):
 
261
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
262
 
263
  # model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
 
264
 
265
  inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
266
  prompt.submit(inference, inputs=inputs, outputs=image_out)
 
267
 
268
+ generate.click(inference, inputs=inputs, outputs=image_out)
269
 
 
 
 
 
 
 
 
 
 
270
 
271
  gr.Markdown('''
272
+ Models by [@nitrosocke](https://huggingface.co/nitrosocke), [@haruu1367](https://twitter.com/haruu1367), [@Helixngc7293](https://twitter.com/DGSpitzer) and others. Most of the code of this demo are copied from [@anzorq's fintuned-diffusion](https://huggingface.co/spaces/anzorq/finetuned_diffusion/tree/main) ❀️<br>
273
+ Space by [Cheng Lu](https://github.com/LuChengTHU). [![Twitter Follow](https://img.shields.io/twitter/follow/ChengLu05671218?label=%40ChengLu&style=social)](https://twitter.com/ChengLu05671218)
274
 
275
  ![visitors](https://visitor-badge.glitch.me/badge?page_id=LuChengTHU.dpmsolver_sdm)
276
  ''')
277
 
278
+ demo.queue(concurrency_count=1)
279
+ demo.launch(debug=False, share=False)