CoolFace
Apppublic

ringhyacinth/Nail-Diffuser

sourceHugging Faceopenrailupdated 4y agoView on Hugging Face
23likes
app.py201 linesDownload Raw Back to root
1from contextlib import nullcontext2import gradio as gr3import torch4from torch import autocast5from diffusers import StableDiffusionPipeline6 7 8device = "cuda" if torch.cuda.is_available() else "cpu"9context = autocast if device == "cuda" else nullcontext10dtype = torch.float16 if device == "cuda" else torch.float3211 12pipe = StableDiffusionPipeline.from_pretrained("ringhyacinth/nail-set-diffuser", torch_dtype=dtype)13pipe = pipe.to(device)14 15 16# Disable nsfw checker17disable_safety = True18 19if disable_safety:20  def null_safety(images, **kwargs):21      return images, False22  pipe.safety_checker = null_safety23 24 25def infer(prompt, n_samples, steps, scale):26 27    with context("cuda"):28        images = pipe(n_samples*[prompt], guidance_scale=scale, num_inference_steps=steps).images29 30    return images31 32css = """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 113block = gr.Blocks(css=css)114 115examples = [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 133with 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 set142                </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.1178            )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 Hyacinth191                    </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 201block.launch()