Normal
Browse files13 unmodified lines141516171718192021222324242526272829302526272829303132333435363738395 unmodified lines45464742484950455152535 unmodified lines596061575859606162636465666768697071727374756263646566678168697042 unmodified lines11311411513013111611711868 unmodified lines18718818920619019119213 unmodified lines DESCRIPTION += "\n<p>Running on CPU 🥶 This demo may not work on CPU.</p>"
MAX_SEED = np.iinfo(np.int32).maxCACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "1") == "1"MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
if torch.cuda.is_available():pipe = StableDiffusionXLPipeline.from_pretrained( "sd-community/sdxl-flash", torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False)pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config) pipe = StableDiffusionXLPipeline.from_pretrained( "sd-community/sdxl-flash", torch_dtype=torch.float16, use_safetensors=True, add_watermarker=False ) pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config) pipe.load_lora_weights("ehristoforu/dalle-3-xl-v2", weight_name="dalle-3-xl-lora-v2.safetensors", adapter_name="dalle") pipe.set_adapters("dalle")
pipe.to("cuda")
def save_image(img): unique_name = str(uuid.uuid4()) + ".png"5 unmodified lines seed = random.randint(0, MAX_SEED) return seed
@spaces.GPU(duration=60, queue=False)@spaces.GPU(duration=30, queue=False)def generate( prompt: str, style: str = "BEST", negative_prompt: str = "", use_negative_prompt: bool = False, seed: int = 0,5 unmodified lines use_resolution_binning: bool = True, progress=gr.Progress(track_tqdm=True),): if style=="BEST" : pipe.load_lora_weights("ehristoforu/dalle-3-xl-v2", weight_name="dalle-3-xl-lora-v2.safetensors", adapter_name="dalle2") pipe.load_lora_weights("ehristoforu/dalle-3-xl", weight_name="dalle-3-xl-lora-v1.safetensors", adapter_name="dalle1") pipe.set_adapters(["dalle2","dalle1"], adapter_weights=[0.7, 0.3]) elif style=="Origami": pipe.load_lora_weights("RalFinger/origami-style-sdxl-lora", weight_name="ral-orgmi-sdxl.safetensors", adapter_name="origami") pipe.set_adapters(["origami"], adapter_weights=[2]) elif style=="3D": pipe.load_lora_weights("artificialguybr/3DRedmond-V1", weight_name="3DRedmond-3DRenderStyle-3DRenderAF.safetensors", adapter_name="3d") pipe.set_adapters(["3d"]) elif style=="PixelART": pipe.load_lora_weights("artificialguybr/PixelArtRedmond", weight_name="PixelArtRedmond-Lite64.safetensors", adapter_name="lora") pipe.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel") pipe.set_adapters(["lora", "pixel"], adapter_weights=[1.0, 1.2]) elif style=="Logo": pipe.load_lora_weights("artificialguybr/LogoRedmond-LogoLoraForSDXL", weight_name="LogoRedmond_LogoRedAF.safetensors", adapter_name="logo") pipe.set_adapters(["logo"]) pipe.to("cuda") pipe.to(device) seed = int(randomize_seed_fn(seed, randomize_seed)) generator = torch.Generator().manual_seed(seed)
options = { "prompt":prompt, "style":style, "negative_prompt":negative_prompt, "width":width, "height":height,42 unmodified lines ) run_button = gr.Button("Run", scale=0) result = gr.Gallery(label="Result", columns=1) with gr.Row(): style = gr.Radio(choices=["Default","BEST","3D", "PixelART","Logo","Origami"],label="Style", value="Default", interactive=True) with gr.Accordion("Advanced options", open=False): with gr.Row(): use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)68 unmodified lines fn=generate, inputs=[ prompt, style, negative_prompt, use_negative_prompt, seed,app.py+16-33