Spaces:
Paused
Paused
Commit ·
4984c7e
1
Parent(s): 4783dcc
high quality (#17)
Browse files- High quality (0f59bfafcd98b4b4a93790a81be7de43d068135f)
- Update app.py (09d2a3966a11c5d694bde9833a8a514a0e291a14)
Co-authored-by: Apolinário from multimodal AI art <multimodalart@users.noreply.huggingface.co>
Files changed (4)
- app.py+75-23
- checkers_mid.jpgAdded
- funky.jpegAdded
- ultra_checkers.pngAdded
7 unmodified lines89101112134 unmodified lines181920212223242526272829303132333420 unmodified lines5556575859601 unmodified line6263646566675 unmodified lines7374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361377 unmodified linesStableDiffusionControlNetPipeline,ControlNetModel,StableDiffusionLatentUpscalePipeline,DPMSolverMultistepScheduler, # <-- Added importEulerDiscreteScheduler # <-- Added import)4 unmodified linesBASE_MODEL = "SG161222/Realistic_Vision_V5.1_noVAE"# Initialize both pipelinesvae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")#init_pipe = DiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V5.1_noVAE", torch_dtype=torch.float16)controlnet = ControlNetModel.from_pretrained("monster-labs/control_v1p_sd15_qrcode_monster")#, torch_dtype=torch.float16)main_pipe = StableDiffusionControlNetPipeline.from_pretrained(BASE_MODEL,controlnet=controlnet,vae=vae,safety_checker=None,#torch_dtype=torch.float16,).to("cuda")#model_id = "stabilityai/sd-x2-latent-upscaler"#upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)#upscaler.to("cuda")20 unmodified linesreturn img# Inference functiondef inference(control_image: Image.Image,1 unmodified linenegative_prompt: str,guidance_scale: float = 8.0,controlnet_conditioning_scale: float = 1,seed: int = -1,sampler = "DPM++ Karras SDE",progress = gr.Progress(track_tqdm=True)5 unmodified lines#init_image = init_pipe(prompt).images[0]# Rest of your existing codecontrol_image = center_crop_resize(control_image)main_pipe.scheduler = SAMPLER_MAP[sampler](main_pipe.scheduler.config)generator = torch.manual_seed(seed) if seed != -1 else torch.Generator()out = main_pipe(prompt=prompt,negative_prompt=negative_prompt,image=control_image,#control_image=control_image,guidance_scale=float(guidance_scale),controlnet_conditioning_scale=float(controlnet_conditioning_scale),generator=generator,#strength=strength,num_inference_steps=30,#output_type="latent").images[0]return out, gr.update(visible=True)with gr.Blocks(css=css) as app:gr.Markdown('''<center><h1>Illusion Diffusion 🌀</h1></span><span font-size:16px;">Generate stunning illusion artwork with Stable Diffusion</span></center>A space by AP [Follow me on Twitter](https://twitter.com/angrypenguinPNG)This project works by using [Monster Labs QR Control Net](https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster).Given a prompt and your pattern, we use a QR code conditioned controlnet to create a stunning illusion! Credit to: MrUgleh (https://twitter.com/MrUgleh) for discovering the workflow :)''')with gr.Row():with gr.Column():control_image = gr.Image(label="Input Illusion", type="pil", elem_id="control_image")controlnet_conditioning_scale = gr.Slider(minimum=0.0, maximum=5.0, step=0.01, value=0.8, label="Illusion strength", info="ControlNet conditioning scale", elem_id="illusion_strength")gr.Examples(examples=["checkers.png", "pattern.png", "spiral.jpeg"], inputs=control_image)prompt = gr.Textbox(label="Prompt", elem_id="prompt")negative_prompt = gr.Textbox(label="Negative Prompt", value="low quality", elem_id="negative_prompt")with gr.Accordion(label="Advanced Options", open=False):#strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.9, label="Strength")guidance_scale = gr.Slider(minimum=0.0, maximum=50.0, step=0.25, value=7.5, label="Guidance Scale")sampler = gr.Dropdown(choices=list(SAMPLER_MAP.keys()), value="Euler")seed = gr.Slider(minimum=-1, maximum=9999999999, step=1, value=2313123, label="Seed", randomize=True)run_btn = gr.Button("Run")with gr.Column():result_image = gr.Image(label="Illusion Diffusion Output", elem_id="output")with gr.Group(elem_id="share-btn-container", visible=False) as share_group:community_icon = gr.HTML(community_icon_html)loading_icon = gr.HTML(loading_icon_html)share_button = gr.Button("Share to community", elem_id="share-btn")history = show_gallery_history()run_btn.click(inference,inputs=[control_image, prompt, negative_prompt, guidance_scale, controlnet_conditioning_scale, seed, sampler],outputs=[result_image, share_group]).then(fn=fetch_gallery_history, inputs=[prompt, result_image], outputs=history, queue=False7 unmodified lines891011121314154 unmodified lines2021222324252627282930313233343536373839404120 unmodified lines626364656667686970717273747576777879808182838485868788899091921 unmodified line9495969798991001011025 unmodified lines1081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881897 unmodified linesStableDiffusionControlNetPipeline,ControlNetModel,StableDiffusionLatentUpscalePipeline,StableDiffusionImg2ImgPipeline,StableDiffusionControlNetImg2ImgPipeline,DPMSolverMultistepScheduler, # <-- Added importEulerDiscreteScheduler # <-- Added import)4 unmodified linesBASE_MODEL = "SG161222/Realistic_Vision_V5.1_noVAE"# Initialize both pipelinesvae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse", torch_dtype=torch.float16)#init_pipe = DiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V5.1_noVAE", torch_dtype=torch.float16)controlnet = ControlNetModel.from_pretrained("monster-labs/control_v1p_sd15_qrcode_monster", torch_dtype=torch.float16)#, torch_dtype=torch.float16)main_pipe = StableDiffusionControlNetPipeline.from_pretrained(BASE_MODEL,controlnet=controlnet,vae=vae,safety_checker=None,torch_dtype=torch.float16,).to("cuda")#main_pipe.unet = torch.compile(main_pipe.unet, mode="reduce-overhead", fullgraph=True)#main_pipe.unet.to(memory_format=torch.channels_last)#main_pipe.unet = torch.compile(main_pipe.unet, mode="reduce-overhead", fullgraph=True)#model_id = "stabilityai/sd-x2-latent-upscaler"image_pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(BASE_MODEL, unet=main_pipe.unet, vae=vae, controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16).to("cuda")#image_pipe.unet = torch.compile(image_pipe.unet, mode="reduce-overhead", fullgraph=True)#upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)#upscaler.to("cuda")20 unmodified linesreturn imgdef common_upscale(samples, width, height, upscale_method, crop=False):if crop == "center":old_width = samples.shape[3]old_height = samples.shape[2]old_aspect = old_width / old_heightnew_aspect = width / heightx = 0y = 0if old_aspect > new_aspect:x = round((old_width - old_width * (new_aspect / old_aspect)) / 2)elif old_aspect < new_aspect:y = round((old_height - old_height * (old_aspect / new_aspect)) / 2)s = samples[:,:,y:old_height-y,x:old_width-x]else:s = samplesreturn torch.nn.functional.interpolate(s, size=(height, width), mode=upscale_method)def upscale(samples, upscale_method, scale_by):#s = samples.copy()width = round(samples["images"].shape[3] * scale_by)height = round(samples["images"].shape[2] * scale_by)s = common_upscale(samples["images"], width, height, upscale_method, "disabled")return (s)# Inference functiondef inference(control_image: Image.Image,1 unmodified linenegative_prompt: str,guidance_scale: float = 8.0,controlnet_conditioning_scale: float = 1,control_guidance_start: float = 1,control_guidance_end: float = 1,upscaler_strength: float = 0.5,seed: int = -1,sampler = "DPM++ Karras SDE",progress = gr.Progress(track_tqdm=True)5 unmodified lines#init_image = init_pipe(prompt).images[0]# Rest of your existing codecontrol_image_small = center_crop_resize(control_image)main_pipe.scheduler = SAMPLER_MAP[sampler](main_pipe.scheduler.config)generator = torch.manual_seed(seed) if seed != -1 else torch.Generator()out = main_pipe(prompt=prompt,negative_prompt=negative_prompt,image=control_image_small,guidance_scale=float(guidance_scale),controlnet_conditioning_scale=float(controlnet_conditioning_scale),generator=generator,control_guidance_start=float(control_guidance_start),control_guidance_end=float(control_guidance_end),num_inference_steps=15,output_type="latent")control_image_large = center_crop_resize(control_image, (1024, 1024))upscaled_latents = upscale(out, "nearest-exact", 2)out_image = image_pipe(prompt=prompt,negative_prompt=negative_prompt,control_image=control_image_large,image=upscaled_latents,guidance_scale=float(guidance_scale),generator=generator,num_inference_steps=20,strength=upscaler_strength,control_guidance_start=float(control_guidance_start),control_guidance_end=float(control_guidance_end),controlnet_conditioning_scale=float(controlnet_conditioning_scale))return out_image["images"][0], gr.update(visible=True)#return outwith gr.Blocks(css=css) as app:gr.Markdown('''<center><h1>Illusion Diffusion HQ 🌀</h1></span><span font-size:16px;">Generate stunning high quality illusion artwork with Stable Diffusion</span></center>A space by AP [Follow me on Twitter](https://twitter.com/angrypenguinPNG)This project works by using [Monster Labs QR Control Net](https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster).Given a prompt and your pattern, we use a QR code conditioned controlnet to create a stunning illusion! Credit to: [MrUgleh](https://twitter.com/MrUgleh) for discovering the workflow :)''')with gr.Row():with gr.Column():control_image = gr.Image(label="Input Illusion", type="pil", elem_id="control_image")controlnet_conditioning_scale = gr.Slider(minimum=0.0, maximum=5.0, step=0.01, value=0.8, label="Illusion strength", elem_id="illusion_strength", info="ControlNet conditioning scale")gr.Examples(examples=["checkers.png", "checkers_mid.jpg", "pattern.png", "ultra_checkers.png", "spiral.jpeg", "funky.jpeg" ], inputs=control_image)prompt = gr.Textbox(label="Prompt", elem_id="prompt")negative_prompt = gr.Textbox(label="Negative Prompt", value="low quality", elem_id="negative_prompt")with gr.Accordion(label="Advanced Options", open=False):guidance_scale = gr.Slider(minimum=0.0, maximum=50.0, step=0.25, value=7.5, label="Guidance Scale")sampler = gr.Dropdown(choices=list(SAMPLER_MAP.keys()), value="Euler")control_start = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0, label="Start of ControlNet")control_end = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1, label="End of ControlNet")strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=1, label="Strength of the upscaler")seed = gr.Slider(minimum=-1, maximum=9999999999, step=1, value=-1, label="Seed", info="-1 means random seed", randomize=True)run_btn = gr.Button("Run")with gr.Column():result_image = gr.Image(label="Illusion Diffusion Output", interactive=False, elem_id="output")with gr.Group(elem_id="share-btn-container", visible=False) as share_group:community_icon = gr.HTML(community_icon_html)loading_icon = gr.HTML(loading_icon_html)share_button = gr.Button("Share to community", elem_id="share-btn")history = show_gallery_history()run_btn.click(inference,inputs=[control_image, prompt, negative_prompt, guidance_scale, controlnet_conditioning_scale, control_start, control_end, strength, seed, sampler],outputs=[result_image, share_group]).then(fn=fetch_gallery_history, inputs=[prompt, result_image], outputs=history, queue=False
app.py+75-23
checkers_mid.jpgAdded

funky.jpegAdded

ultra_checkers.pngAdded
