Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
|
@@ -37,13 +38,20 @@ if torch.cuda.is_available():
|
|
| 37 |
|
| 38 |
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
|
| 39 |
|
| 40 |
-
def inference(model, prompt, guidance, steps):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
global current_model
|
| 43 |
global pipe
|
| 44 |
if model != current_model:
|
| 45 |
current_model = model
|
| 46 |
pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torch.float16)
|
|
|
|
| 47 |
if torch.cuda.is_available():
|
| 48 |
pipe = pipe.to("cuda")
|
| 49 |
|
|
@@ -51,30 +59,64 @@ def inference(model, prompt, guidance, steps):
|
|
| 51 |
image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0]
|
| 52 |
return image
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
css = """
|
| 55 |
<style>
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
</style>
|
| 60 |
"""
|
| 61 |
with gr.Blocks(css=css) as demo:
|
| 62 |
gr.HTML(
|
| 63 |
"""
|
| 64 |
-
<div
|
| 65 |
-
<div
|
| 66 |
-
|
| 67 |
-
display: inline-flex;
|
| 68 |
-
align-items: center;
|
| 69 |
-
gap: 0.8rem;
|
| 70 |
-
font-size: 1.75rem;
|
| 71 |
-
"
|
| 72 |
-
>
|
| 73 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 74 |
-
Finetuned Diffusion
|
| 75 |
-
</h1>
|
| 76 |
</div>
|
| 77 |
-
<p
|
| 78 |
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
|
| 79 |
<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">Spiderverse</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">Pokemon</a>, <a href="https://huggingface.co/yuk/fuyuko-waifu-diffusion">Fuyuko Waifu</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony</a>, <a href="https://huggingface.co/IfanSnek/JohnDiffusion">John</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo</a>.
|
| 80 |
</p>
|
|
@@ -86,6 +128,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 86 |
with gr.Column():
|
| 87 |
model = gr.Dropdown(label="Model", choices=models, value=models[0])
|
| 88 |
prompt = gr.Textbox(label="Prompt", placeholder="Style prefix is applied automatically")
|
|
|
|
| 89 |
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
| 90 |
steps = gr.Slider(label="Steps", value=50, maximum=100, minimum=2)
|
| 91 |
run = gr.Button(value="Run")
|
|
@@ -93,14 +136,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 93 |
with gr.Column():
|
| 94 |
image_out = gr.Image(height=512)
|
| 95 |
|
| 96 |
-
run.click(inference, inputs=[model, prompt, guidance, steps], outputs=image_out)
|
| 97 |
gr.Examples([
|
| 98 |
[models[0], "jason bateman disassembling the demon core", 7.5, 50],
|
| 99 |
[models[3], "portrait of dwayne johnson", 7.0, 75],
|
| 100 |
[models[4], "portrait of a beautiful alyx vance half life", 10, 50],
|
| 101 |
[models[5], "Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7, 45],
|
| 102 |
[models[4], "fantasy portrait painting, digital art", 4, 30],
|
| 103 |
-
], [prompt, guidance, steps], image_out,
|
| 104 |
gr.HTML('''
|
| 105 |
<div>
|
| 106 |
<p>Model by <a href="https://huggingface.co/nitrosocke" target="_blank">@nitrosocke</a> ❤️</p>
|
|
@@ -113,4 +156,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 113 |
''')
|
| 114 |
|
| 115 |
demo.queue()
|
| 116 |
-
demo.launch()
|
|
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
| 2 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
|
|
|
|
| 38 |
|
| 39 |
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
|
| 40 |
|
| 41 |
+
def inference(model, prompt, img, guidance, steps):
|
| 42 |
+
if img is not None:
|
| 43 |
+
return img_inference(model, prompt, img, guidance, steps)
|
| 44 |
+
else:
|
| 45 |
+
return text_inference(model, prompt, guidance, steps)
|
| 46 |
+
|
| 47 |
+
def text_inference(model, prompt, guidance, steps):
|
| 48 |
|
| 49 |
global current_model
|
| 50 |
global pipe
|
| 51 |
if model != current_model:
|
| 52 |
current_model = model
|
| 53 |
pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torch.float16)
|
| 54 |
+
|
| 55 |
if torch.cuda.is_available():
|
| 56 |
pipe = pipe.to("cuda")
|
| 57 |
|
|
|
|
| 59 |
image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0]
|
| 60 |
return image
|
| 61 |
|
| 62 |
+
def img_inference(model, prompt, img, guidance, steps):
|
| 63 |
+
|
| 64 |
+
global current_model
|
| 65 |
+
global pipe
|
| 66 |
+
if model != current_model:
|
| 67 |
+
current_model = model
|
| 68 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model, torch_dtype=torch.float16)
|
| 69 |
+
|
| 70 |
+
if torch.cuda.is_available():
|
| 71 |
+
pipe = pipe.to("cuda")
|
| 72 |
+
|
| 73 |
+
prompt = prompt_prefixes[current_model] + prompt
|
| 74 |
+
img.resize((512, 512))
|
| 75 |
+
image = pipe(
|
| 76 |
+
prompt,
|
| 77 |
+
init_image=img,
|
| 78 |
+
num_inference_steps=int(steps),
|
| 79 |
+
strength=0.75,
|
| 80 |
+
guidance_scale=guidance,
|
| 81 |
+
width=512,
|
| 82 |
+
height=512).images[0]
|
| 83 |
+
return image
|
| 84 |
+
|
| 85 |
+
|
| 86 |
css = """
|
| 87 |
<style>
|
| 88 |
+
.finetuned-diffusion-div {
|
| 89 |
+
text-align: center;
|
| 90 |
+
max-width: 700px;
|
| 91 |
+
margin: 0 auto;
|
| 92 |
+
}
|
| 93 |
+
.finetuned-diffusion-div div {
|
| 94 |
+
display: inline-flex;
|
| 95 |
+
align-items: center;
|
| 96 |
+
gap: 0.8rem;
|
| 97 |
+
font-size: 1.75rem;
|
| 98 |
+
}
|
| 99 |
+
.finetuned-diffusion-div div h1 {
|
| 100 |
+
font-weight: 900;
|
| 101 |
+
margin-bottom: 7px;
|
| 102 |
+
}
|
| 103 |
+
.finetuned-diffusion-div p {
|
| 104 |
+
margin-bottom: 10px;
|
| 105 |
+
font-size: 94%;
|
| 106 |
+
}
|
| 107 |
+
.finetuned-diffusion-div p a {
|
| 108 |
+
text-decoration: underline;
|
| 109 |
+
}
|
| 110 |
</style>
|
| 111 |
"""
|
| 112 |
with gr.Blocks(css=css) as demo:
|
| 113 |
gr.HTML(
|
| 114 |
"""
|
| 115 |
+
<div class="finetuned-diffusion-div">
|
| 116 |
+
<div>
|
| 117 |
+
<h1>Finetuned Diffusion</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
</div>
|
| 119 |
+
<p>
|
| 120 |
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
|
| 121 |
<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">Spiderverse</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">Pokemon</a>, <a href="https://huggingface.co/yuk/fuyuko-waifu-diffusion">Fuyuko Waifu</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony</a>, <a href="https://huggingface.co/IfanSnek/JohnDiffusion">John</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo</a>.
|
| 122 |
</p>
|
|
|
|
| 128 |
with gr.Column():
|
| 129 |
model = gr.Dropdown(label="Model", choices=models, value=models[0])
|
| 130 |
prompt = gr.Textbox(label="Prompt", placeholder="Style prefix is applied automatically")
|
| 131 |
+
img = gr.Image(label="img2img (optional)", type="pil", height=256, tool="editor")
|
| 132 |
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
| 133 |
steps = gr.Slider(label="Steps", value=50, maximum=100, minimum=2)
|
| 134 |
run = gr.Button(value="Run")
|
|
|
|
| 136 |
with gr.Column():
|
| 137 |
image_out = gr.Image(height=512)
|
| 138 |
|
| 139 |
+
run.click(inference, inputs=[model, prompt, img, guidance, steps], outputs=image_out)
|
| 140 |
gr.Examples([
|
| 141 |
[models[0], "jason bateman disassembling the demon core", 7.5, 50],
|
| 142 |
[models[3], "portrait of dwayne johnson", 7.0, 75],
|
| 143 |
[models[4], "portrait of a beautiful alyx vance half life", 10, 50],
|
| 144 |
[models[5], "Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7, 45],
|
| 145 |
[models[4], "fantasy portrait painting, digital art", 4, 30],
|
| 146 |
+
], [model, prompt, guidance, steps], image_out, text_inference, cache_examples=torch.cuda.is_available())
|
| 147 |
gr.HTML('''
|
| 148 |
<div>
|
| 149 |
<p>Model by <a href="https://huggingface.co/nitrosocke" target="_blank">@nitrosocke</a> ❤️</p>
|
|
|
|
| 156 |
''')
|
| 157 |
|
| 158 |
demo.queue()
|
| 159 |
+
demo.launch(debug=True)
|