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( """

Text to Nail set

Generate a new Nail Set from a text description. Use the token {Nail Set} in your prompts for the effect.

""" ) 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( """

Use the tokens {Nail Set} in your prompts for the effect.

Put in a text prompt and generate your own nail set!

Trained by Weekend and Hyacinth

""" ) block.launch()