Spaces:
Runtime error
Runtime error
from contextlib import nullcontext | |
import gradio as gr | |
import torch | |
from torch import autocast | |
from diffusers import StableDiffusionPipeline | |
device = "cuda" if torch.cuda.is_available() else "cpu" | |
context = autocast if device == "cuda" else nullcontext | |
dtype = torch.float16 if device == "cuda" else torch.float32 | |
pipe = StableDiffusionPipeline.from_pretrained("ringhyacinth/nail-set-diffuser", torch_dtype=dtype) | |
pipe = pipe.to(device) | |
# Disable nsfw checker | |
disable_safety = True | |
if disable_safety: | |
def null_safety(images, **kwargs): | |
return images, False | |
pipe.safety_checker = null_safety | |
def infer(prompt, n_samples, steps, scale): | |
with context("cuda"): | |
images = pipe(n_samples*[prompt], guidance_scale=scale, num_inference_steps=steps).images | |
return images | |
examples = [ | |
[ | |
'Nail Set, hamilton nail, broadway musical theme nail.', | |
2, | |
7, | |
], | |
[ | |
'Nail Set, chinese new year nail, super detailed', | |
2, | |
7, | |
], | |
[ | |
'Nail Set, thanksgiving nail, super detailed', | |
2, | |
7, | |
], | |
] | |
with block: | |
gr.HTML( | |
""" | |
<div style="text-align: center; max-width: 650px; margin: 0 auto;"> | |
<div> | |
<img class="logo" src="https://cdn.discordapp.com/attachments/973596613933146123/1043954179481276416/747251668968350_.pic.jpg" alt="Weekend and Hyacinth Logo" | |
style="margin: auto; max-width: 7rem;"> | |
<h1 style="font-weight: 900; font-size: 3rem; margin-top: 25px; margin-bottom: 25px;"> | |
Text to Nail set | |
</h1> | |
</div> | |
<p style="margin-bottom: 5px; font-size: 94%"> | |
Generate a new Nail Set from a text description. Use the token {Nail Set} in your prompts for the effect. | |
</p> | |
</div> | |
""" | |
) | |
with gr.Group(): | |
with gr.Box(): | |
with gr.Row().style(mobile_collapse=False, equal_height=True): | |
text = gr.Textbox( | |
label="Enter your prompt", | |
show_label=False, | |
max_lines=1, | |
placeholder="Enter your prompt", | |
).style( | |
border=(True, False, True, True), | |
rounded=(True, False, False, True), | |
container=False, | |
) | |
btn = gr.Button("Generate image").style( | |
margin=False, | |
rounded=(False, True, True, False), | |
) | |
gallery = gr.Gallery( | |
label="Generated images", show_label=False, elem_id="gallery" | |
).style(grid=[2], height="auto") | |
with gr.Row(elem_id="advanced-options"): | |
samples = gr.Slider(label="Images", minimum=1, maximum=4, value=2, step=1) | |
steps = gr.Slider(label="Steps", minimum=50, maximum=100, value=50, step=5) | |
scale = gr.Slider( | |
label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1 | |
) | |
ex = gr.Examples(examples=examples, fn=infer, inputs=[text, samples, scale], outputs=gallery, cache_examples=False) | |
ex.dataset.headers = [""] | |
text.submit(infer, inputs=[text, samples, steps, scale], outputs=gallery) | |
btn.click(infer, inputs=[text, samples, steps, scale], outputs=gallery) | |
gr.HTML( | |
""" | |
<div class="footer"> | |
<p> Nail Diffuser by π Weekend and Hyacinth | |
</p> | |
</div> | |
<div class="acknowledgments"> | |
<p> Use the tokens {Nail Set} in your prompts for the effect. | |
<p> Put in a text prompt and generate your own nail set! | |
<p> Trained by Weekend and Hyacinth </p> | |
</div> | |
""" | |
) | |
block.launch() |