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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from contextlib import nullcontext
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from torch import autocast
|
| 5 |
+
from diffusers import StableDiffusionPipeline
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
+
context = autocast if device == "cuda" else nullcontext
|
| 10 |
+
dtype = torch.float16 if device == "cuda" else torch.float32
|
| 11 |
+
|
| 12 |
+
pipe = StableDiffusionPipeline.from_pretrained("ringhyacinth/nail-set-diffuser", torch_dtype=dtype)
|
| 13 |
+
pipe = pipe.to(device)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Disable nsfw checker
|
| 17 |
+
disable_safety = True
|
| 18 |
+
|
| 19 |
+
if disable_safety:
|
| 20 |
+
def null_safety(images, **kwargs):
|
| 21 |
+
return images, False
|
| 22 |
+
pipe.safety_checker = null_safety
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def infer(prompt, n_samples, steps, scale):
|
| 26 |
+
|
| 27 |
+
with context("cuda"):
|
| 28 |
+
images = pipe(n_samples*[prompt], guidance_scale=scale, num_inference_steps=steps).images
|
| 29 |
+
|
| 30 |
+
return images
|
| 31 |
+
|
| 32 |
+
css = """
|
| 33 |
+
a {
|
| 34 |
+
color: inherit;
|
| 35 |
+
text-decoration: underline;
|
| 36 |
+
}
|
| 37 |
+
.gradio-container {
|
| 38 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 39 |
+
}
|
| 40 |
+
.gr-button {
|
| 41 |
+
color: white;
|
| 42 |
+
border-color: #9d66e5;
|
| 43 |
+
background: #9d66e5;
|
| 44 |
+
}
|
| 45 |
+
input[type='range'] {
|
| 46 |
+
accent-color: #9d66e5;
|
| 47 |
+
}
|
| 48 |
+
.dark input[type='range'] {
|
| 49 |
+
accent-color: #dfdfdf;
|
| 50 |
+
}
|
| 51 |
+
.container {
|
| 52 |
+
max-width: 730px;
|
| 53 |
+
margin: auto;
|
| 54 |
+
padding-top: 1.5rem;
|
| 55 |
+
}
|
| 56 |
+
#gallery {
|
| 57 |
+
min-height: 22rem;
|
| 58 |
+
margin-bottom: 15px;
|
| 59 |
+
margin-left: auto;
|
| 60 |
+
margin-right: auto;
|
| 61 |
+
border-bottom-right-radius: .5rem !important;
|
| 62 |
+
border-bottom-left-radius: .5rem !important;
|
| 63 |
+
}
|
| 64 |
+
#gallery>div>.h-full {
|
| 65 |
+
min-height: 20rem;
|
| 66 |
+
}
|
| 67 |
+
.details:hover {
|
| 68 |
+
text-decoration: underline;
|
| 69 |
+
}
|
| 70 |
+
.gr-button {
|
| 71 |
+
white-space: nowrap;
|
| 72 |
+
}
|
| 73 |
+
.gr-button:focus {
|
| 74 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 75 |
+
outline: none;
|
| 76 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 77 |
+
--tw-border-opacity: 1;
|
| 78 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 79 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 80 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 81 |
+
--tw-ring-opacity: .5;
|
| 82 |
+
}
|
| 83 |
+
#advanced-options {
|
| 84 |
+
margin-bottom: 20px;
|
| 85 |
+
}
|
| 86 |
+
.footer {
|
| 87 |
+
margin-bottom: 45px;
|
| 88 |
+
margin-top: 35px;
|
| 89 |
+
text-align: center;
|
| 90 |
+
border-bottom: 1px solid #e5e5e5;
|
| 91 |
+
}
|
| 92 |
+
.footer>p {
|
| 93 |
+
font-size: .8rem;
|
| 94 |
+
display: inline-block;
|
| 95 |
+
padding: 0 10px;
|
| 96 |
+
transform: translateY(10px);
|
| 97 |
+
background: white;
|
| 98 |
+
}
|
| 99 |
+
.dark .logo{ filter: invert(1); }
|
| 100 |
+
.dark .footer {
|
| 101 |
+
border-color: #303030;
|
| 102 |
+
}
|
| 103 |
+
.dark .footer>p {
|
| 104 |
+
background: #0b0f19;
|
| 105 |
+
}
|
| 106 |
+
.acknowledgments h4{
|
| 107 |
+
margin: 1.25em 0 .25em 0;
|
| 108 |
+
font-weight: bold;
|
| 109 |
+
font-size: 115%;
|
| 110 |
+
}
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
block = gr.Blocks(css=css)
|
| 114 |
+
|
| 115 |
+
examples = [
|
| 116 |
+
[
|
| 117 |
+
'Nail Set, hamilton nail, broadway musical theme nail.',
|
| 118 |
+
2,
|
| 119 |
+
7,
|
| 120 |
+
],
|
| 121 |
+
[
|
| 122 |
+
'Nail Set, chinese new year nail, super detailed',
|
| 123 |
+
2,
|
| 124 |
+
7,
|
| 125 |
+
],
|
| 126 |
+
[
|
| 127 |
+
'Nail Set, thanksgiving nail, super detailed',
|
| 128 |
+
2,
|
| 129 |
+
7,
|
| 130 |
+
],
|
| 131 |
+
]
|
| 132 |
+
|
| 133 |
+
with block:
|
| 134 |
+
gr.HTML(
|
| 135 |
+
"""
|
| 136 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
| 137 |
+
<div>
|
| 138 |
+
<img class="logo" src="https://cdn.discordapp.com/attachments/973596613933146123/1043954179481276416/747251668968350_.pic.jpg" alt="Weekend and Hyacinth Logo"
|
| 139 |
+
style="margin: auto; max-width: 7rem;">
|
| 140 |
+
<h1 style="font-weight: 900; font-size: 3rem; margin-top: 25px; margin-bottom: 25px;">
|
| 141 |
+
Text to Nail set
|
| 142 |
+
</h1>
|
| 143 |
+
</div>
|
| 144 |
+
<p style="margin-bottom: 5px; font-size: 94%">
|
| 145 |
+
Generate a new Nail Set from a text description. Use the token {Nail Set} in your prompts for the effect.
|
| 146 |
+
</p>
|
| 147 |
+
</div>
|
| 148 |
+
"""
|
| 149 |
+
)
|
| 150 |
+
with gr.Group():
|
| 151 |
+
with gr.Box():
|
| 152 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 153 |
+
text = gr.Textbox(
|
| 154 |
+
label="Enter your prompt",
|
| 155 |
+
show_label=False,
|
| 156 |
+
max_lines=1,
|
| 157 |
+
placeholder="Enter your prompt",
|
| 158 |
+
).style(
|
| 159 |
+
border=(True, False, True, True),
|
| 160 |
+
rounded=(True, False, False, True),
|
| 161 |
+
container=False,
|
| 162 |
+
)
|
| 163 |
+
btn = gr.Button("Generate image").style(
|
| 164 |
+
margin=False,
|
| 165 |
+
rounded=(False, True, True, False),
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
gallery = gr.Gallery(
|
| 169 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
| 170 |
+
).style(grid=[2], height="auto")
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
with gr.Row(elem_id="advanced-options"):
|
| 174 |
+
samples = gr.Slider(label="Images", minimum=1, maximum=4, value=2, step=1)
|
| 175 |
+
steps = gr.Slider(label="Steps", minimum=50, maximum=100, value=50, step=5)
|
| 176 |
+
scale = gr.Slider(
|
| 177 |
+
label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
ex = gr.Examples(examples=examples, fn=infer, inputs=[text, samples, scale], outputs=gallery, cache_examples=False)
|
| 182 |
+
ex.dataset.headers = [""]
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
text.submit(infer, inputs=[text, samples, steps, scale], outputs=gallery)
|
| 186 |
+
btn.click(infer, inputs=[text, samples, steps, scale], outputs=gallery)
|
| 187 |
+
gr.HTML(
|
| 188 |
+
"""
|
| 189 |
+
<div class="footer">
|
| 190 |
+
<p> Nail Diffuser by 💅 Weekend and Hyacinth
|
| 191 |
+
</p>
|
| 192 |
+
</div>
|
| 193 |
+
<div class="acknowledgments">
|
| 194 |
+
<p> Use the tokens {Nail Set} in your prompts for the effect.
|
| 195 |
+
<p> Put in a text prompt and generate your own nail set!
|
| 196 |
+
<p> Trained by Weekend and Hyacinth </p>
|
| 197 |
+
</div>
|
| 198 |
+
"""
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
block.launch()
|