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