from diffusers import StableDiffusionPipeline import gradio as gr import torch import os from share_btn import community_icon_html, loading_icon_html, share_js if torch.cuda.is_available(): torchfloat = torch.float16 else: torchfloat = torch.float32 models = [ "DGSpitzer/Cyberpunk-Anime-Diffusion" ] prompt_prefixes = { models[0]: "dgs illustration style " } current_model = models[0] auth_token = os.environ.get("adminToken") or True pipe = StableDiffusionPipeline.from_pretrained(current_model, use_auth_token=auth_token, torch_dtype=torchfloat, revision="fp16") if torch.cuda.is_available(): pipe = pipe.to("cuda") else: pipe = pipe.to("cpu") device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶" def on_model_change(model): global current_model global pipe if model != current_model: current_model = model pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torchfloat) if torch.cuda.is_available(): pipe = pipe.to("cuda") def inference(prompt, guidance, steps): prompt = prompt_prefixes[current_model] + prompt image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0] return image, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True) def inference_example(prompt, guidance, steps): prompt = prompt_prefixes[current_model] + prompt image = pipe(prompt, num_inference_steps=int(steps), guidance_scale=guidance, width=512, height=512).images[0] return image css = """ #col-container {max-width: 700px; margin-left: auto; margin-right: auto;} a {text-decoration-line: underline; font-weight: 600;} .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;right:0; } #share-btn * { all: unset; } #share-btn-container div:nth-child(-n+2){ width: auto !important; min-height: 0px !important; } #share-btn-container .wrap { display: none !important; } """ with gr.Blocks(css=css) as demo: gr.HTML( """
Demo for Cyberpunk Anime Diffusion. Based of the projects by anzorq and fffiloni