Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,40 @@ from diffusers import StableDiffusionPipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
if torch.cuda.is_available():
|
| 9 |
pipe = pipe.to("cuda")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def inference(prompt, guidance, steps):
|
| 12 |
-
|
|
|
|
| 13 |
image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0]
|
| 14 |
return image
|
| 15 |
|
|
@@ -26,11 +52,11 @@ with gr.Blocks() as demo:
|
|
| 26 |
"
|
| 27 |
>
|
| 28 |
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 29 |
-
|
| 30 |
</h1>
|
| 31 |
</div>
|
| 32 |
<p style="margin-bottom: 10px; font-size: 94%">
|
| 33 |
-
Demo for
|
| 34 |
</p>
|
| 35 |
</div>
|
| 36 |
"""
|
|
@@ -38,20 +64,22 @@ with gr.Blocks() as demo:
|
|
| 38 |
with gr.Row():
|
| 39 |
|
| 40 |
with gr.Column():
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
run = gr.Button(value="Run")
|
| 45 |
gr.Markdown(f"Running on: {device}")
|
| 46 |
with gr.Column():
|
| 47 |
image_out = gr.Image(height=512)
|
| 48 |
|
|
|
|
| 49 |
run.click(inference, inputs=[prompt, guidance, steps], outputs=image_out)
|
| 50 |
gr.Examples([
|
| 51 |
["jason bateman disassembling the demon core", 7.5, 50],
|
| 52 |
["portrait of dwayne johnson", 7.0, 75],
|
| 53 |
-
["portrait of a beautiful alyx vance half life
|
| 54 |
-
["Aloy from Horizon: Zero Dawn, half body portrait,
|
| 55 |
["fantasy portrait painting, digital art", 4, 30],
|
| 56 |
], [prompt, guidance, steps], image_out, inference, cache_examples=torch.cuda.is_available())
|
| 57 |
gr.HTML('''
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
models = [
|
| 6 |
+
"nitrosocke/Arcane-Diffusion",
|
| 7 |
+
"nitrosocke/archer-diffusion",
|
| 8 |
+
"nitrosocke/elden-ring-diffusion",
|
| 9 |
+
"nitrosocke/spider-verse-diffusion"
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
prompt_prefixes = {
|
| 13 |
+
models[0]: "arcane style ",
|
| 14 |
+
models[1]: "archer style ",
|
| 15 |
+
models[2]: "elden ring style ",
|
| 16 |
+
models[3]: "spiderverse style "
|
| 17 |
+
}
|
| 18 |
|
| 19 |
+
current_model = models[0]
|
| 20 |
+
pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torch.float16)
|
| 21 |
if torch.cuda.is_available():
|
| 22 |
pipe = pipe.to("cuda")
|
| 23 |
|
| 24 |
+
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
|
| 25 |
+
|
| 26 |
+
def on_model_change(model):
|
| 27 |
+
|
| 28 |
+
global current_model
|
| 29 |
+
global pipe
|
| 30 |
+
if model != current_model:
|
| 31 |
+
current_model = model
|
| 32 |
+
pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torch.float16)
|
| 33 |
+
if torch.cuda.is_available():
|
| 34 |
+
pipe = pipe.to("cuda")
|
| 35 |
+
|
| 36 |
def inference(prompt, guidance, steps):
|
| 37 |
+
|
| 38 |
+
prompt = prompt_prefixes[current_model] + prompt
|
| 39 |
image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0]
|
| 40 |
return image
|
| 41 |
|
|
|
|
| 52 |
"
|
| 53 |
>
|
| 54 |
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 55 |
+
Finetuned Diffusion
|
| 56 |
</h1>
|
| 57 |
</div>
|
| 58 |
<p style="margin-bottom: 10px; font-size: 94%">
|
| 59 |
+
Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: Arcane, Archer, Elden Ring, Spiderverse.
|
| 60 |
</p>
|
| 61 |
</div>
|
| 62 |
"""
|
|
|
|
| 64 |
with gr.Row():
|
| 65 |
|
| 66 |
with gr.Column():
|
| 67 |
+
model = gr.Dropdown(label="Model", choices=models, value=models[0])
|
| 68 |
+
prompt = gr.Textbox(label="Prompt", placeholder="{} is added automatically".format(prompt_prefixes[current_model]))
|
| 69 |
+
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
| 70 |
+
steps = gr.Slider(label="Steps", value=50, maximum=100, minimum=2)
|
| 71 |
run = gr.Button(value="Run")
|
| 72 |
gr.Markdown(f"Running on: {device}")
|
| 73 |
with gr.Column():
|
| 74 |
image_out = gr.Image(height=512)
|
| 75 |
|
| 76 |
+
model.change(on_model_change, inputs=model, outputs=[])
|
| 77 |
run.click(inference, inputs=[prompt, guidance, steps], outputs=image_out)
|
| 78 |
gr.Examples([
|
| 79 |
["jason bateman disassembling the demon core", 7.5, 50],
|
| 80 |
["portrait of dwayne johnson", 7.0, 75],
|
| 81 |
+
["portrait of a beautiful alyx vance half life", 7, 50],
|
| 82 |
+
["Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7, 50],
|
| 83 |
["fantasy portrait painting, digital art", 4, 30],
|
| 84 |
], [prompt, guidance, steps], image_out, inference, cache_examples=torch.cuda.is_available())
|
| 85 |
gr.HTML('''
|