Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
-
from diffusers import AutoencoderKL, UNet2DConditionModel
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
-
from diffusers import StableDiffusionImg2ImgPipeline
|
| 4 |
import gradio as gr
|
| 5 |
import torch
|
| 6 |
from PIL import Image
|
|
@@ -20,22 +18,21 @@ models = [
|
|
| 20 |
Model("Custom model", "", ""),
|
| 21 |
Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style "),
|
| 22 |
Model("Archer", "nitrosocke/archer-diffusion", "archer style "),
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
]
|
| 34 |
|
| 35 |
last_mode = "txt2img"
|
| 36 |
current_model = models[1]
|
| 37 |
current_model_path = current_model.path
|
| 38 |
-
# pipe = None
|
| 39 |
|
| 40 |
if is_colab:
|
| 41 |
pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16)
|
|
@@ -87,7 +84,6 @@ def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, g
|
|
| 87 |
if is_colab or current_model == models[0]:
|
| 88 |
pipe = StableDiffusionPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16)
|
| 89 |
else:
|
| 90 |
-
# pipe = pipe.to("cpu")
|
| 91 |
pipe.to("cpu")
|
| 92 |
pipe = current_model.pipe_t2i
|
| 93 |
|
|
@@ -119,7 +115,6 @@ def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, w
|
|
| 119 |
if is_colab or current_model == models[0]:
|
| 120 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16)
|
| 121 |
else:
|
| 122 |
-
# pipe = pipe.to("cpu")
|
| 123 |
pipe.to("cpu")
|
| 124 |
pipe = current_model.pipe_i2i
|
| 125 |
|
|
@@ -192,7 +187,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 192 |
</div>
|
| 193 |
<p>
|
| 194 |
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
|
| 195 |
-
<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">
|
| 196 |
</p>
|
| 197 |
<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>
|
| 198 |
Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
|
@@ -205,7 +200,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 205 |
with gr.Column(scale=55):
|
| 206 |
with gr.Group():
|
| 207 |
model_name = gr.Dropdown(label="Model", choices=[m.name for m in models], value=current_model.name)
|
| 208 |
-
|
|
|
|
|
|
|
| 209 |
|
| 210 |
with gr.Row():
|
| 211 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="Enter prompt. Style applied automatically").style(container=False)
|
|
@@ -239,7 +236,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 239 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
| 240 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
| 241 |
|
| 242 |
-
model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=
|
| 243 |
custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
|
| 244 |
# n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
|
| 245 |
|
|
@@ -247,14 +244,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 247 |
prompt.submit(inference, inputs=inputs, outputs=image_out)
|
| 248 |
generate.click(inference, inputs=inputs, outputs=image_out)
|
| 249 |
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
# ex.dataset.headers = [""]
|
| 258 |
|
| 259 |
gr.Markdown('''
|
| 260 |
Models by [@nitrosocke](https://huggingface.co/nitrosocke), [@Helixngc7293](https://twitter.com/DGSpitzer) and others. ❤️<br>
|
|
|
|
| 1 |
+
from diffusers import AutoencoderKL, UNet2DConditionModel, StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
|
|
|
| 18 |
Model("Custom model", "", ""),
|
| 19 |
Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style "),
|
| 20 |
Model("Archer", "nitrosocke/archer-diffusion", "archer style "),
|
| 21 |
+
Model("Elden Ring", "nitrosocke/elden-ring-diffusion", "elden ring style "),
|
| 22 |
+
Model("Spider-Verse", "nitrosocke/spider-verse-diffusion", "spiderverse style "),
|
| 23 |
+
Model("Modern Disney", "nitrosocke/mo-di-diffusion", "modern disney style "),
|
| 24 |
+
Model("Classic Disney", "nitrosocke/classic-anim-diffusion", ""),
|
| 25 |
+
Model("Waifu", "hakurei/waifu-diffusion", ""),
|
| 26 |
+
Model("Pokémon", "lambdalabs/sd-pokemon-diffusers", ""),
|
| 27 |
+
Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", ""),
|
| 28 |
+
Model("Robo Diffusion", "nousr/robo-diffusion", ""),
|
| 29 |
+
Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "dgs illustration style "),
|
| 30 |
+
Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy ")
|
| 31 |
]
|
| 32 |
|
| 33 |
last_mode = "txt2img"
|
| 34 |
current_model = models[1]
|
| 35 |
current_model_path = current_model.path
|
|
|
|
| 36 |
|
| 37 |
if is_colab:
|
| 38 |
pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16)
|
|
|
|
| 84 |
if is_colab or current_model == models[0]:
|
| 85 |
pipe = StableDiffusionPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16)
|
| 86 |
else:
|
|
|
|
| 87 |
pipe.to("cpu")
|
| 88 |
pipe = current_model.pipe_t2i
|
| 89 |
|
|
|
|
| 115 |
if is_colab or current_model == models[0]:
|
| 116 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16)
|
| 117 |
else:
|
|
|
|
| 118 |
pipe.to("cpu")
|
| 119 |
pipe = current_model.pipe_i2i
|
| 120 |
|
|
|
|
| 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/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 🤗.
|
| 191 |
</p>
|
| 192 |
<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>
|
| 193 |
Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
|
|
|
|
| 200 |
with gr.Column(scale=55):
|
| 201 |
with gr.Group():
|
| 202 |
model_name = gr.Dropdown(label="Model", choices=[m.name for m in models], value=current_model.name)
|
| 203 |
+
with gr.Box(visible=False) as custom_model_group:
|
| 204 |
+
custom_model_path = gr.Textbox(label="Custom model path", placeholder="Path to model, e.g. nitrosocke/Arcane-Diffusion", interactive=True)
|
| 205 |
+
gr.HTML("<div><font size='2'>Custom models have to be downloaded first, so give it some time.</font></div>")
|
| 206 |
|
| 207 |
with gr.Row():
|
| 208 |
prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2,placeholder="Enter prompt. Style applied automatically").style(container=False)
|
|
|
|
| 236 |
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
| 237 |
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
| 238 |
|
| 239 |
+
model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
|
| 240 |
custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
|
| 241 |
# n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
|
| 242 |
|
|
|
|
| 244 |
prompt.submit(inference, inputs=inputs, outputs=image_out)
|
| 245 |
generate.click(inference, inputs=inputs, outputs=image_out)
|
| 246 |
|
| 247 |
+
ex = gr.Examples([
|
| 248 |
+
[models[1].name, "jason bateman disassembling the demon core", 7.5, 50],
|
| 249 |
+
[models[4].name, "portrait of dwayne johnson", 7.0, 75],
|
| 250 |
+
[models[5].name, "portrait of a beautiful alyx vance half life", 10, 50],
|
| 251 |
+
[models[6].name, "Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7.0, 45],
|
| 252 |
+
[models[5].name, "fantasy portrait painting, digital art", 4.0, 30],
|
| 253 |
+
], [model_name, prompt, guidance, steps, seed], image_out, inference, cache_examples=False)
|
|
|
|
| 254 |
|
| 255 |
gr.Markdown('''
|
| 256 |
Models by [@nitrosocke](https://huggingface.co/nitrosocke), [@Helixngc7293](https://twitter.com/DGSpitzer) and others. ❤️<br>
|