├── .gitignore ├── LICENSE ├── README.md ├── images └── ss1.webp ├── install.py └── scripts └── easy_stablecascade_diffusers.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Adi Eyal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stable Cascade in stable-diffusion-webui 2 | 3 | Please have someone remake this extension. 4 | 5 | ## Requirements 6 | 7 | * VRAM: 16GB? 8 | 9 | ## Screenshots 10 | 11 | ![](images/ss1.webp) 12 | -------------------------------------------------------------------------------- /images/ss1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blue-pen5805/sdweb-easy-stablecascade-diffusers/71d37440bdfa776ce19341257eb372fd58bf1c97/images/ss1.webp -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | import launch 2 | 3 | try: 4 | from diffusers import StableCascadeDecoderPipeline 5 | except: 6 | launch.run_pip(f"install git+https://github.com/kashif/diffusers.git@a3dc21385b7386beb3dab3a9845962ede6765887", "diffusers@wuerstchen-v3") 7 | -------------------------------------------------------------------------------- /scripts/easy_stablecascade_diffusers.py: -------------------------------------------------------------------------------- 1 | import gradio as gr 2 | import torch 3 | import gc 4 | import json 5 | from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline 6 | 7 | from modules import script_callbacks, images 8 | from modules.processing import get_fixed_seed 9 | from modules.rng import create_generator 10 | from modules.shared import opts 11 | from modules.ui_components import ResizeHandleRow 12 | 13 | # modules/infotext_utils.py 14 | def quote(text): 15 | if ',' not in str(text) and '\n' not in str(text) and ':' not in str(text): 16 | return text 17 | 18 | return json.dumps(text, ensure_ascii=False) 19 | 20 | # modules/processing.py 21 | def create_infotext(prompt, negative_prompt, guidence_scale, prior_steps, decoder_steps, seed, width, height): 22 | generation_params = { 23 | "Model": "StableCascade", 24 | "Size": f"{width}x{height}", 25 | "Seed": seed, 26 | "Steps(Prior)": prior_steps, 27 | "Steps(Decoder)": decoder_steps, 28 | "CFG": guidence_scale, 29 | "RNG": opts.randn_source if opts.randn_source != "GPU" else None 30 | } 31 | 32 | generation_params_text = ", ".join([k if k == v else f'{k}: {quote(v)}' for k, v in generation_params.items() if v is not None]) 33 | 34 | prompt_text = prompt 35 | negative_prompt_text = f"\nNegative prompt: {negative_prompt}" if negative_prompt else "" 36 | 37 | return f"{prompt_text}{negative_prompt_text}\n{generation_params_text}".strip() 38 | 39 | def predict(prompt, negative_prompt, width, height, guidance_scale, prior_steps, decoder_steps, seed, batch_size): 40 | device = "cuda" 41 | prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", torch_dtype=torch.bfloat16).to(device) 42 | 43 | fixed_seed = get_fixed_seed(seed) 44 | prior_output = prior( 45 | prompt=prompt, 46 | negative_prompt=negative_prompt, 47 | width=width, 48 | height=height, 49 | guidance_scale=guidance_scale, 50 | num_inference_steps=prior_steps, 51 | num_images_per_prompt=batch_size, 52 | generator=create_generator(fixed_seed) 53 | ) 54 | del prior 55 | gc.collect() 56 | torch.cuda.empty_cache() 57 | 58 | decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", torch_dtype=torch.float16).to(device) 59 | decoder_output = decoder( 60 | image_embeddings=prior_output.image_embeddings.half(), 61 | prompt=prompt, 62 | negative_prompt=negative_prompt, 63 | guidance_scale=0.0, 64 | output_type="pil", 65 | num_inference_steps=decoder_steps 66 | ).images 67 | del decoder 68 | gc.collect() 69 | torch.cuda.empty_cache() 70 | 71 | for image in decoder_output: 72 | images.save_image( 73 | image, 74 | opts.outdir_samples or opts.outdir_txt2img_samples, 75 | "", 76 | fixed_seed, 77 | prompt, 78 | opts.samples_format, 79 | info=create_infotext(prompt, negative_prompt, guidance_scale, prior_steps, decoder_steps, fixed_seed, width, height) 80 | ) 81 | 82 | return decoder_output 83 | 84 | def on_ui_tabs(): 85 | with gr.Blocks() as stable_cascade_block: 86 | with ResizeHandleRow(): 87 | with gr.Column(): 88 | prompt = gr.Textbox(label='Prompt', placeholder='Enter a prompt here...', default='') 89 | negative_prompt = gr.Textbox(label='Negative Prompt', placeholder='') 90 | width = gr.Slider(label='Width', minimum=16, maximum=4096, step=8, value=1024) 91 | height = gr.Slider(label='Height', minimum=16, maximum=4096, step=8, value=1024) 92 | guidence_scale = gr.Slider(label='CFG', minimum=1, maximum=32, step=0.5, value=4.0) 93 | prior_step = gr.Slider(label='Steps(Prior)', minimum=1, maximum=60, step=1, value=20) 94 | decoder_steps = gr.Slider(label='Steps(Decoder)', minimum=1, maximum=60, step=1, value=10) 95 | batch_size = gr.Slider(label='Batch Size', minimum=1, maximum=9, step=1, value=1) 96 | sampling_seed = gr.Number(label='Seed', value=-1, precision=0) 97 | 98 | generate_button = gr.Button(value="Generate") 99 | 100 | ctrls = [prompt, negative_prompt, width, height, guidence_scale, prior_step, decoder_steps, sampling_seed, batch_size] 101 | 102 | with gr.Column(): 103 | output_gallery = gr.Gallery(label='Gallery', height=opts.gallery_height, show_label=False, object_fit='contain', visible=True, columns=3, type='pil') 104 | 105 | generate_button.click(predict, inputs=ctrls, outputs=[output_gallery]) 106 | return [(stable_cascade_block, "StableCascade", "stable_cascade")] 107 | 108 | script_callbacks.on_ui_tabs(on_ui_tabs) 109 | --------------------------------------------------------------------------------