Normal
Browse files13 unmodified lines14151617181920212223242526272829303132335 unmodified lines394041424344454647485 unmodified lines5455565758596061626364656667686970717273747576777879808182838442 unmodified lines12712812913013113213313468 unmodified lines20320420520620720820913 unmodified linesDESCRIPTION += "\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"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")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)def save_image(img):unique_name = str(uuid.uuid4()) + ".png"5 unmodified linesseed = random.randint(0, MAX_SEED)return seed@spaces.GPU(duration=60, queue=False)def generate(prompt: str,style: str = "BEST",negative_prompt: str = "",use_negative_prompt: bool = False,seed: int = 0,5 unmodified linesuse_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")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 linesfn=generate,inputs=[prompt,style,negative_prompt,use_negative_prompt,seed,13 unmodified lines14151617181920212223242526272829303132333435363738395 unmodified lines4546474849505152535 unmodified lines59606162636465666768697042 unmodified lines11311411511611711868 unmodified lines18718818919019119213 unmodified linesDESCRIPTION += "\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", "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.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 linesseed = random.randint(0, MAX_SEED)return seed@spaces.GPU(duration=30, queue=False)def generate(prompt: str,negative_prompt: str = "",use_negative_prompt: bool = False,seed: int = 0,5 unmodified linesuse_resolution_binning: bool = True,progress=gr.Progress(track_tqdm=True),):pipe.to(device)seed = int(randomize_seed_fn(seed, randomize_seed))generator = torch.Generator().manual_seed(seed)options = {"prompt":prompt,"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.Accordion("Advanced options", open=False):with gr.Row():use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)68 unmodified linesfn=generate,inputs=[prompt,negative_prompt,use_negative_prompt,seed,
app.py+16-33