Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
from torch import autocast | |
from diffusers import StableDiffusionPipeline | |
#model_id = "hakurei/waifu-diffusion" | |
pipe = StableDiffusionPipeline.from_pretrained("hakurei/waifu-diffusion", torch_type=torch.float16, revision="fp16") | |
pipe = pipe.to("cuda") | |
#torch.backends.cudnn.benchmark = True | |
num_samples = 2 | |
def infer(prompt): | |
images = pipe([prompt] * num_samples, guidance_scale=7.5)["sample"] | |
return images | |
css = """ | |
.gradio-container { | |
font-family: 'IBM Plex Sans', sans-serif; | |
} | |
.gr-button { | |
color: white; | |
border-color: black; | |
background: black; | |
} | |
input[type='range'] { | |
accent-color: black; | |
} | |
.dark input[type='range'] { | |
accent-color: #dfdfdf; | |
} | |
.container { | |
max-width: 730px; | |
margin: auto; | |
padding-top: 1.5rem; | |
} | |
#gallery { | |
min-height: 22rem; | |
margin-bottom: 15px; | |
margin-left: auto; | |
margin-right: auto; | |
border-bottom-right-radius: .5rem !important; | |
border-bottom-left-radius: .5rem !important; | |
} | |
#gallery>div>.h-full { | |
min-height: 20rem; | |
} | |
.details:hover { | |
text-decoration: underline; | |
} | |
.gr-button { | |
white-space: nowrap; | |
} | |
.gr-button:focus { | |
border-color: rgb(147 197 253 / var(--tw-border-opacity)); | |
outline: none; | |
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); | |
--tw-border-opacity: 1; | |
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); | |
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color); | |
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity)); | |
--tw-ring-opacity: .5; | |
} | |
#advanced-btn { | |
font-size: .7rem !important; | |
line-height: 19px; | |
margin-top: 12px; | |
margin-bottom: 12px; | |
padding: 2px 8px; | |
border-radius: 14px !important; | |
} | |
#advanced-options { | |
display: none; | |
margin-bottom: 20px; | |
} | |
.footer { | |
margin-bottom: 45px; | |
margin-top: 35px; | |
text-align: center; | |
border-bottom: 1px solid #e5e5e5; | |
} | |
.footer>p { | |
font-size: .8rem; | |
display: inline-block; | |
padding: 0 10px; | |
transform: translateY(10px); | |
background: white; | |
} | |
.dark .footer { | |
border-color: #303030; | |
} | |
.dark .footer>p { | |
background: #0b0f19; | |
} | |
.acknowledgments h4{ | |
margin: 1.25em 0 .25em 0; | |
font-weight: bold; | |
font-size: 115%; | |
} | |
#container-advanced-btns{ | |
display: flex; | |
flex-wrap: wrap; | |
justify-content: space-between; | |
align-items: center; | |
} | |
.animate-spin { | |
animation: spin 1s linear infinite; | |
} | |
@keyframes spin { | |
from { | |
transform: rotate(0deg); | |
} | |
to { | |
transform: rotate(360deg); | |
} | |
} | |
#share-btn-container { | |
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem; | |
} | |
#share-btn { | |
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; | |
} | |
#share-btn * { | |
all: unset; | |
} | |
.gr-form{ | |
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0; | |
} | |
#prompt-container{ | |
gap: 0; | |
} | |
#generated_id{ | |
min-height: 700px | |
} | |
""" | |
block = gr.Blocks(css=css) | |
examples = [ | |
[ | |
'Goku' | |
], | |
[ | |
'Mikasa Ackerman' | |
], | |
[ | |
'Saber' | |
], | |
] | |
with block as demo: | |
gr.HTML( | |
""" | |
<div style="text-align: center; max-width: 650px; margin: 0 auto;"> | |
<div | |
style=" | |
display: inline-flex; | |
align-items: center; | |
gap: 0.8rem; | |
font-size: 1.75rem; | |
" | |
> | |
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAA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GSyfncHg3o9I/rmGYX438MPORam9Doip7JKy3jS24W8Cz09FfvAHUsm9fuw1BK02VEtNbLRcnDECwjncig9nQaZdZmE9MBmbFPCyjymUrZNcqlEJklKoATD902eRHR2BZhhvraxVH1pZq66/e3kfUOiHlzUtU9z+gf77gzA8tLa6gnOvnIShKrBUA0G83j8YYVLBJkAEXV9IBngxSGiMQ2U82W7Sor//gkKec01D891ZrM6X66Vd2x6W7wUu+Q8A/w+34pKwK2kanwAAAABJRU5ErkJggg==" /> | |
<h1 style="font-weight: 900; margin-bottom: 7px;"> | |
Waifu Diffusion Demo | |
</h1> | |
</div> | |
<p style="margin-bottom: 10px; font-size: 94%"> | |
waifu-diffusion is a latent text-to-image diffusion model that has been conditioned on high-quality anime images through fine-tuning | |
</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 | |
).style( | |
border=(True, False, True, True), | |
rounded=(True, False, False, True), | |
container=False, | |
) | |
btn = gr.Button("Run").style( | |
margin=False, | |
rounded=(False, True, True, False), | |
) | |
gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="generated_id").style( | |
grid=[4], height="auto" | |
) | |
ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=gallery, cache_examples=True) | |
ex.dataset.headers = [""] | |
text.submit(infer, inputs=[text], outputs=gallery) | |
btn.click(infer, inputs=[text], outputs=gallery) | |
gr.HTML( | |
""" | |
<div class="footer"> | |
<p>Stable Diffusion model fine-tuned on 56K anime image board images by <a href="https://huggingface.co/hakurei" style="text-decoration: underline;" target="_blank">hakurei</a> | |
</p> | |
</div> | |
<div class="acknowledgments"> | |
<p><h4>LICENSE</h4> | |
The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p> | |
<p><h4>Biases and content acknowledgment</h4> | |
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p> | |
</div> | |
""" | |
) | |
demo.queue(max_size=25).launch() |