Spaces:
Runtime error
Runtime error
Upload 32 files
Browse filesFiles changed (10)
- app.py+7-4
- diffusion_webui/__init__.py+30-1
- diffusion_webui/app.pyAdded+77
- diffusion_webui/diffusion_models/controlnet/__init__.py+8
- diffusion_webui/diffusion_models/controlnet/controlnet_inpaint/__init__.py+7
- diffusion_webui/diffusion_models/controlnet/controlnet_mlsd.py+11-4
- diffusion_webui/diffusion_models/controlnet/controlnet_normal.pyAdded+190
- diffusion_webui/diffusion_models/stable_diffusion/__init__.py+3
- diffusion_webui/helpers.py+12-41
- diffusion_webui/utils/model_list.py+9-4
123345612 unmodified lines19202122232425252627282917 unmodified lines474849505152535414 unmodified lines6970716972737475767477import gradio as gr
from diffusion_webui.helpers import (from diffusion_webui import ( CodeformerUpscalerGenerator, StableDiffusionControlInpaintNetDepthGenerator, StableDiffusionControlNetCannyGenerator,12 unmodified lines StableDiffusionImage2ImageGenerator, StableDiffusionInpaintGenerator, StableDiffusionText2ImageGenerator, StableDiffusionControlNetNormalGenerator,)
def main():def diffusion_app(): app = gr.Blocks() with app: with gr.Row():17 unmodified lines StableDiffusionControlNetPoseGenerator.app() with gr.Tab("Scribble"): StableDiffusionControlNetScribbleGenerator.app() with gr.Tab("Normal"): StableDiffusionControlNetNormalGenerator.app() with gr.Tab("Seg"): StableDiffusionControlNetSegGenerator.app() with gr.Tab("ControlNet Inpaint"):14 unmodified lines with gr.Tab("Upscaler"): CodeformerUpscalerGenerator.app()
app.queue(concurrency_count=1) app.queue(concurrency_count=2) app.launch(debug=True, enable_queue=True)
if __name__ == "__main__": main() diffusion_app()1234567891011121314151617181920212223242526272829130from diffusion_webui.diffusion_models.stable_diffusion import ( StableDiffusionText2ImageGenerator, StableDiffusionImage2ImageGenerator, StableDiffusionInpaintGenerator,)
from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint import ( StableDiffusionControlNetInpaintCannyGenerator, StableDiffusionControlInpaintNetDepthGenerator, StableDiffusionControlNetInpaintHedGenerator, StableDiffusionControlNetInpaintMlsdGenerator, StableDiffusionControlNetInpaintPoseGenerator, StableDiffusionControlNetInpaintScribbleGenerator, StableDiffusionControlNetInpaintSegGenerator,)
from diffusion_webui.diffusion_models.controlnet import ( StableDiffusionControlNetCannyGenerator, StableDiffusionControlNetDepthGenerator, StableDiffusionControlNetHEDGenerator, StableDiffusionControlNetMLSDGenerator, StableDiffusionControlNetNormalGenerator, StableDiffusionControlNetPoseGenerator, StableDiffusionControlNetScribbleGenerator, StableDiffusionControlNetSegGenerator,)
from diffusion_webui.app import diffusion_app as app
__version__ = "2.0.1"__version__ = "2.2.0"1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import gradio as gr
from diffusion_webui import ( CodeformerUpscalerGenerator, StableDiffusionControlInpaintNetDepthGenerator, StableDiffusionControlNetCannyGenerator, StableDiffusionControlNetDepthGenerator, StableDiffusionControlNetHEDGenerator, StableDiffusionControlNetInpaintCannyGenerator, StableDiffusionControlNetInpaintHedGenerator, StableDiffusionControlNetInpaintMlsdGenerator, StableDiffusionControlNetInpaintPoseGenerator, StableDiffusionControlNetInpaintScribbleGenerator, StableDiffusionControlNetInpaintSegGenerator, StableDiffusionControlNetMLSDGenerator, StableDiffusionControlNetPoseGenerator, StableDiffusionControlNetScribbleGenerator, StableDiffusionControlNetSegGenerator, StableDiffusionImage2ImageGenerator, StableDiffusionInpaintGenerator, StableDiffusionText2ImageGenerator, StableDiffusionControlNetNormalGenerator,)
def diffusion_app(): app = gr.Blocks() with app: with gr.Row(): with gr.Column(): with gr.Tab("Text2Img"): StableDiffusionText2ImageGenerator.app() with gr.Tab("Img2Img"): StableDiffusionImage2ImageGenerator.app() with gr.Tab("Inpaint"): StableDiffusionInpaintGenerator.app() with gr.Tab("ControlNet"): with gr.Tab("Canny"): StableDiffusionControlNetCannyGenerator.app() with gr.Tab("Depth"): StableDiffusionControlNetDepthGenerator.app() with gr.Tab("HED"): StableDiffusionControlNetHEDGenerator.app() with gr.Tab("MLSD"): StableDiffusionControlNetMLSDGenerator.app() with gr.Tab("Pose"): StableDiffusionControlNetPoseGenerator.app() with gr.Tab("Scribble"): StableDiffusionControlNetScribbleGenerator.app() with gr.Tab("Normal"): StableDiffusionControlNetNormalGenerator.app() with gr.Tab("Seg"): StableDiffusionControlNetSegGenerator.app() with gr.Tab("ControlNet Inpaint"): with gr.Tab("Canny"): StableDiffusionControlNetInpaintCannyGenerator.app() with gr.Tab("Depth"): StableDiffusionControlInpaintNetDepthGenerator.app() with gr.Tab("HED"): StableDiffusionControlNetInpaintHedGenerator.app() with gr.Tab("MLSD"): StableDiffusionControlNetInpaintMlsdGenerator.app() with gr.Tab("Pose"): StableDiffusionControlNetInpaintPoseGenerator.app() with gr.Tab("Scribble"): StableDiffusionControlNetInpaintScribbleGenerator.app() with gr.Tab("Seg"): StableDiffusionControlNetInpaintSegGenerator.app() with gr.Tab("Upscaler"): CodeformerUpscalerGenerator.app()
app.queue(concurrency_count=2) app.launch(debug=True, enable_queue=True)
if __name__ == "__main__": diffusion_app()12345678from diffusion_webui.diffusion_models.controlnet.controlnet_canny import StableDiffusionControlNetCannyGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_depth import StableDiffusionControlNetDepthGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_hed import StableDiffusionControlNetHEDGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_mlsd import StableDiffusionControlNetMLSDGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_normal import StableDiffusionControlNetNormalGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_pose import StableDiffusionControlNetPoseGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_scribble import StableDiffusionControlNetScribbleGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_seg import StableDiffusionControlNetSegGenerator1234567from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_canny import StableDiffusionControlNetInpaintCannyGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_depth import StableDiffusionControlInpaintNetDepthGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_hed import StableDiffusionControlNetInpaintHedGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_mlsd import StableDiffusionControlNetInpaintMlsdGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_pose import StableDiffusionControlNetInpaintPoseGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_scribble import StableDiffusionControlNetInpaintScribbleGeneratorfrom diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_seg import StableDiffusionControlNetInpaintSegGenerator3 unmodified lines45677891034 unmodified lines4546474848495051525 unmodified lines5859606061616263646559 unmodified lines1251261271281291301311321331341351363 unmodified linesfrom diffusers import ControlNetModel, StableDiffusionControlNetPipelinefrom PIL import Image
from diffusion_webui.utils.model_list import stable_model_listfrom diffusion_webui.utils.model_list import stable_model_list, controlnet_mlsd_model_listfrom diffusion_webui.utils.scheduler_list import ( SCHEDULER_LIST, get_scheduler_list,34 unmodified lines def generate_image( self, image_path: str, model_path: str, stable_model_path: str, controlnet_model_path: str, prompt: str, negative_prompt: str, num_images_per_prompt: int,5 unmodified lines image = self.controlnet_mlsd(image_path=image_path)
pipe = self.load_model( stable_model_path=model_path, controlnet_model_path="lllyasviel/sd-controlnet-mlsd", stable_model_path=stable_model_path, controlnet_model_path=controlnet_model_path, scheduler=scheduler, )
59 unmodified lines
with gr.Row(): with gr.Column(): controlnet_mlsd_controlnet_model_id = gr.Dropdown( choices=controlnet_mlsd_model_list, value=controlnet_mlsd_model_list[0], label="ControlNet Model Id", ) controlnet_mlsd_scheduler = gr.Dropdown( choices=SCHEDULER_LIST, value=SCHEDULER_LIST[0],123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190from diffusers import StableDiffusionControlNetPipeline, ControlNetModelfrom diffusers.utils import load_imagefrom transformers import pipelinefrom PIL import Imageimport gradio as grimport numpy as npimport torchimport cv2
from diffusion_webui.utils.model_list import ( controlnet_normal_model_list, stable_model_list,)from diffusion_webui.utils.scheduler_list import ( SCHEDULER_LIST, get_scheduler_list,)
class StableDiffusionControlNetNormalGenerator: def __init__(self): self.pipe = None
def load_model(self, stable_model_path, controlnet_model_path, scheduler): if self.pipe is None: controlnet = ControlNetModel.from_pretrained( controlnet_model_path, torch_dtype=torch.float16 ) self.pipe = StableDiffusionControlNetPipeline.from_pretrained( pretrained_model_name_or_path=stable_model_path, controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16, )
self.pipe = get_scheduler_list(pipe=self.pipe, scheduler=scheduler) self.pipe.to("cuda") self.pipe.enable_xformers_memory_efficient_attention()
return self.pipe
def controlnet_normal( self, image_path: str, ): image = load_image(image_path).convert("RGB") depth_estimator = pipeline("depth-estimation", model ="Intel/dpt-hybrid-midas" ) image = depth_estimator(image)['predicted_depth'][0] image = image.numpy() image_depth = image.copy() image_depth -= np.min(image_depth) image_depth /= np.max(image_depth) bg_threhold = 0.4 x = cv2.Sobel(image, cv2.CV_32F, 1, 0, ksize=3) x[image_depth < bg_threhold] = 0 y = cv2.Sobel(image, cv2.CV_32F, 0, 1, ksize=3) y[image_depth < bg_threhold] = 0 z = np.ones_like(x) * np.pi * 2.0 image = np.stack([x, y, z], axis=2) image /= np.sum(image ** 2.0, axis=2, keepdims=True) ** 0.5 image = (image * 127.5 + 127.5).clip(0, 255).astype(np.uint8) image = Image.fromarray(image) return image
def generate_image( self, image_path: str, stable_model_path: str, controlnet_model_path: str, prompt: str, negative_prompt: str, num_images_per_prompt: int, guidance_scale: int, num_inference_step: int, scheduler: str, seed_generator: int, ): pipe = self.load_model(stable_model_path, controlnet_model_path, scheduler) image = self.controlnet_normal(image_path)
if seed_generator == 0: random_seed = torch.randint(0, 1000000, (1,)) generator = torch.manual_seed(random_seed) else: generator = torch.manual_seed(seed_generator) output = pipe( prompt=prompt, image=image, negative_prompt=negative_prompt, num_images_per_prompt=num_images_per_prompt, num_inference_steps=num_inference_step, guidance_scale=guidance_scale, generator=generator, ).images
return output
def app(): with gr.Blocks(): with gr.Row(): with gr.Column(): controlnet_normal_image_file = gr.Image( type="filepath", label="Image" )
controlnet_normal_prompt = gr.Textbox( lines=1, placeholder="Prompt", show_label=False, )
controlnet_normal_negative_prompt = gr.Textbox( lines=1, placeholder="Negative Prompt", show_label=False, ) with gr.Row(): with gr.Column(): controlnet_normal_stable_model_id = gr.Dropdown( choices=stable_model_list, value=stable_model_list[0], label="Stable Model Id", )
controlnet_normal_guidance_scale = gr.Slider( minimum=0.1, maximum=15, step=0.1, value=7.5, label="Guidance Scale", ) controlnet_normal_num_inference_step = gr.Slider( minimum=1, maximum=100, step=1, value=50, label="Num Inference Step", ) controlnet_normal_num_images_per_prompt = gr.Slider( minimum=1, maximum=10, step=1, value=1, label="Number Of Images", ) with gr.Row(): with gr.Column(): controlnet_normal_model_id = gr.Dropdown( choices=controlnet_normal_model_list, value=controlnet_normal_model_list[0], label="ControlNet Model Id", )
controlnet_normal_scheduler = gr.Dropdown( choices=SCHEDULER_LIST, value=SCHEDULER_LIST[0], label="Scheduler", )
controlnet_normal_seed_generator = gr.Number( value=0, label="Seed Generator", ) controlnet_normal_predict = gr.Button(value="Generator")
with gr.Column(): output_image = gr.Gallery( label="Generated images", show_label=False, elem_id="gallery", ).style(grid=(1, 2))
controlnet_normal_predict.click( fn=StableDiffusionControlNetCannyGenerator().generate_image, inputs=[ controlnet_normal_image_file, controlnet_normal_stable_model_id, controlnet_normal_model_id, controlnet_normal_prompt, controlnet_normal_negative_prompt, controlnet_normal_num_images_per_prompt, controlnet_normal_guidance_scale, controlnet_normal_num_inference_step, controlnet_normal_scheduler, controlnet_normal_seed_generator, ], outputs=[output_image], )123from diffusion_webui.diffusion_models.stable_diffusion.text2img_app import StableDiffusionText2ImageGeneratorfrom diffusion_webui.diffusion_models.stable_diffusion.img2img_app import StableDiffusionImage2ImageGeneratorfrom diffusion_webui.diffusion_models.stable_diffusion.inpaint_app import StableDiffusionInpaintGenerator1234567812345610781213915161018191121221224251327281430311516171819202133342236372339402425434445464748495051525354from diffusion_webui.diffusion_models.controlnet.controlnet_canny import ( StableDiffusionControlNetCannyGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_depth import ( StableDiffusionControlNetDepthGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_hed import ( StableDiffusionControlNetHEDGenerator,from diffusion_webui.diffusion_models.stable_diffusion import ( StableDiffusionText2ImageGenerator, StableDiffusionImage2ImageGenerator, StableDiffusionInpaintGenerator,)
from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_canny import (from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint import ( StableDiffusionControlNetInpaintCannyGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_depth import ( StableDiffusionControlInpaintNetDepthGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_hed import ( StableDiffusionControlNetInpaintHedGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_mlsd import ( StableDiffusionControlNetInpaintMlsdGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_pose import ( StableDiffusionControlNetInpaintPoseGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_scribble import ( StableDiffusionControlNetInpaintScribbleGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_inpaint.controlnet_inpaint_seg import ( StableDiffusionControlNetInpaintSegGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_mlsd import ()
from diffusion_webui.diffusion_models.controlnet import ( StableDiffusionControlNetCannyGenerator, StableDiffusionControlNetDepthGenerator, StableDiffusionControlNetHEDGenerator, StableDiffusionControlNetMLSDGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_pose import ( StableDiffusionControlNetPoseGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_scribble import ( StableDiffusionControlNetScribbleGenerator,)from diffusion_webui.diffusion_models.controlnet.controlnet_seg import ( StableDiffusionControlNetSegGenerator,)from diffusion_webui.diffusion_models.stable_diffusion.img2img_app import ( StableDiffusionImage2ImageGenerator,)from diffusion_webui.diffusion_models.stable_diffusion.inpaint_app import ( StableDiffusionInpaintGenerator,)from diffusion_webui.diffusion_models.stable_diffusion.text2img_app import ( StableDiffusionText2ImageGenerator,)from diffusion_webui.upscaler_models.codeformer_upscaler import ( CodeformerUpscalerGenerator,)5 unmodified lines6789109101112131415161718192120212223242526272 unmodified lines303132333334353637383940416 unmodified lines48495051525354555657585 unmodified lines "dreamlike-art/dreamlike-diffusion-1.0", "gsdf/Counterfeit-V2.5", "dreamlike-art/dreamlike-photoreal-2.0" ]
controlnet_canny_model_list = [ "lllyasviel/sd-controlnet-canny", "lllyasviel/control_v11p_sd15_canny", "thibaud/controlnet-sd21-canny-diffusers",
]
controlnet_depth_model_list = [ "lllyasviel/sd-controlnet-depth", "lllyasviel/control_v11p_sd15_depth", "lllyasviel/control_v11f1p_sd15_depth", "thibaud/controlnet-sd21-depth-diffusers",]
controlnet_pose_model_list = [ "lllyasviel/sd-controlnet-openpose", "lllyasviel/control_v11p_sd15_openpose",2 unmodified lines
controlnet_hed_model_list = [ "lllyasviel/sd-controlnet-hed", "lllyasviel/control_v11p_sd15_scribble", "thibaud/controlnet-sd21-hed-diffusers",]
controlnet_scribble_model_list = [ "lllyasviel/sd-controlnet-scribble", "lllyasviel/control_v11p_sd15_scribble", "thibaud/controlnet-sd21-scribble-diffusers",]stable_inpiant_model_list = [6 unmodified lines "lllyasviel/control_v11p_sd15_mlsd",]
controlnet_normal_model_list = [ "lllyasviel/sd-controlnet-normal", "lllyasviel/control_v11p_sd15_normalbae",]
controlnet_seg_model_list = [ "lllyasviel/sd-controlnet-seg", "lllyasviel/control_v11p_sd15_seg",app.py+7-4
diffusion_webui/__init__.py+30-1
diffusion_webui/app.pyAdded+77
diffusion_webui/diffusion_models/controlnet/__init__.py+8
diffusion_webui/diffusion_models/controlnet/controlnet_inpaint/__init__.py+7
diffusion_webui/diffusion_models/controlnet/controlnet_mlsd.py+11-4
diffusion_webui/diffusion_models/controlnet/controlnet_normal.pyAdded+190
diffusion_webui/diffusion_models/stable_diffusion/__init__.py+3
diffusion_webui/helpers.py+12-41
diffusion_webui/utils/model_list.py+9-4