Update app.py
Browse files
app.py
CHANGED
@@ -30,12 +30,16 @@ controlnets = [
|
|
30 |
),
|
31 |
]
|
32 |
|
33 |
-
pipe_CN = StableDiffusionXLControlNetPipeline.from_pretrained("SG161222/RealVisXL_V5.0", torch_dtype=torch.float16,controlnet=controlnets, use_safetensors=True, variant='fp16')
|
34 |
-
pipe_CN.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", torch_dtype=torch.float16)
|
35 |
pipe_CN.scheduler=DPMSolverSDEScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
36 |
|
37 |
pipe_CN.to("cuda")
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
|
40 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",text_encoder_2=pipe_CN.text_encoder_2,vae=pipe_CN.vae,torch_dtype=torch.float16,use_safetensors=True,variant="fp16")
|
41 |
refiner.to("cuda")
|
@@ -44,7 +48,16 @@ pipe_IN = StableDiffusionXLControlNetInpaintPipeline.from_pretrained("diffusers/
|
|
44 |
pipe_IN.load_lora_weights('Tonioesparza/ourhood_training_dreambooth_lora_2_0', weight_name='pytorch_lora_weights.safetensors',adapter_name='ourhood')
|
45 |
pipe_IN.to("cuda")
|
46 |
|
47 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
###pro_encode = pipe_cn.encode_text(prompt)
|
50 |
|
@@ -76,6 +89,9 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int)
|
|
76 |
mask1 = load_image(scaff_dic[scaffold]['mask1'])
|
77 |
masks = processor_mask.preprocess([mask1], height=output_height, width=output_width)
|
78 |
masks = [masks.reshape(1, masks.shape[0], masks.shape[2], masks.shape[3])]
|
|
|
|
|
|
|
79 |
###ip_images init
|
80 |
###ip_img_1 = load_image(r"C:\Users\AntonioEsparzaGlisma\PycharmProjects\hB8\Cases\a-place-to_210930_HAY_A-PLACE-TO_091-768x1024.png")
|
81 |
###ip_images = [[ip_img_1]]
|
@@ -84,8 +100,13 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int)
|
|
84 |
###precomputed depth image
|
85 |
depth_image = load_image(scaff_dic[scaffold]['depth_image'])
|
86 |
canny_image = load_image(scaff_dic[scaffold]['canny_image'])
|
|
|
|
|
|
|
87 |
images_CN = [depth_image, canny_image]
|
88 |
|
|
|
|
|
89 |
neg1 = 'text,watermark'
|
90 |
prompt2 = 'Photorealistic rendering, of an OurHood privacy booth, with a silken oak frame, hickory stained melange polyester fabric, windows'
|
91 |
neg2 = 'curtains, pillows'
|
@@ -98,8 +119,8 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int)
|
|
98 |
num_inference_steps=n_steps,
|
99 |
num_images_per_prompt=1,
|
100 |
generator=generator,
|
101 |
-
denoising_end=0.
|
102 |
-
image=
|
103 |
output_type="latent",
|
104 |
control_guidance_start=[0.0,0.5],
|
105 |
control_guidance_end=[0.5,1.0],
|
@@ -113,7 +134,7 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int)
|
|
113 |
image = refiner(
|
114 |
prompt=prompt1,
|
115 |
num_inference_steps=n_steps,
|
116 |
-
denoising_start=0.
|
117 |
image=results).images[0]
|
118 |
|
119 |
|
@@ -125,10 +146,10 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int)
|
|
125 |
negative_prompt=neg2,
|
126 |
image=image,
|
127 |
mask_image=mask1,
|
128 |
-
num_inference_steps=
|
129 |
strength=1.0,
|
130 |
control_guidance_end=[0.9,0.9],
|
131 |
-
controlnet_conditioning_scale=[0.
|
132 |
control_image=images_CN,
|
133 |
generator=generator,
|
134 |
).images[0]
|
|
|
30 |
),
|
31 |
]
|
32 |
|
33 |
+
pipe_CN = StableDiffusionXLControlNetPipeline.from_pretrained("SG161222/RealVisXL_V5.0", torch_dtype=torch.float16,controlnet=[controlnets[0],controlnets[0]], use_safetensors=True, variant='fp16')
|
34 |
+
###pipe_CN.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", torch_dtype=torch.float16)
|
35 |
pipe_CN.scheduler=DPMSolverSDEScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
36 |
|
37 |
pipe_CN.to("cuda")
|
38 |
+
state_dict, network_alphas = StableDiffusionXLControlNetPipeline.lora_state_dict('CreativesCombined/hb8_cases_dreambooth_lora_test_1_14', weight_name='pytorch_lora_weights.safetensors')
|
39 |
+
pipe_CN.load_lora_into_unet(state_dict, network_alphas, pipe_CN.unet, adapter_name='unet_cases')
|
40 |
+
pipe_CN.load_lora_into_text_encoder(state_dict, network_alphas, pipe_CN.text_encoder, adapter_name='text_cases')
|
41 |
+
pipe_CN.load_lora_into_text_encoder(state_dict, network_alphas, pipe_CN.text_encoder ,prefix='2', adapter_name='text_2_cases')
|
42 |
+
pipe_CN.set_adapters(["unet_cases","text_cases","text_2_cases"], adapter_weights=[1.0, 0.5,0.5])
|
43 |
|
44 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",text_encoder_2=pipe_CN.text_encoder_2,vae=pipe_CN.vae,torch_dtype=torch.float16,use_safetensors=True,variant="fp16")
|
45 |
refiner.to("cuda")
|
|
|
48 |
pipe_IN.load_lora_weights('Tonioesparza/ourhood_training_dreambooth_lora_2_0', weight_name='pytorch_lora_weights.safetensors',adapter_name='ourhood')
|
49 |
pipe_IN.to("cuda")
|
50 |
|
51 |
+
def make_inpaint_condition(image, image_mask):
|
52 |
+
image = np.array(image.convert("RGB")).astype(np.float32) / 255.0
|
53 |
+
image_mask = np.array(image_mask.convert("L")).astype(np.float32) / 255.0
|
54 |
+
assert image.shape[0:1] == image_mask.shape[0:1]
|
55 |
+
image[image_mask > 0.5] = -1.0 # set as masked pixel
|
56 |
+
image = np.expand_dims(image, 0).transpose(0, 3, 1, 2)
|
57 |
+
image = torch.from_numpy(image)
|
58 |
+
return image
|
59 |
+
|
60 |
+
def ourhood_inference(prompt=str,num_inference_steps=int,scaffold=int,seed=int):
|
61 |
|
62 |
###pro_encode = pipe_cn.encode_text(prompt)
|
63 |
|
|
|
89 |
mask1 = load_image(scaff_dic[scaffold]['mask1'])
|
90 |
masks = processor_mask.preprocess([mask1], height=output_height, width=output_width)
|
91 |
masks = [masks.reshape(1, masks.shape[0], masks.shape[2], masks.shape[3])]
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
###ip_images init
|
96 |
###ip_img_1 = load_image(r"C:\Users\AntonioEsparzaGlisma\PycharmProjects\hB8\Cases\a-place-to_210930_HAY_A-PLACE-TO_091-768x1024.png")
|
97 |
###ip_images = [[ip_img_1]]
|
|
|
100 |
###precomputed depth image
|
101 |
depth_image = load_image(scaff_dic[scaffold]['depth_image'])
|
102 |
canny_image = load_image(scaff_dic[scaffold]['canny_image'])
|
103 |
+
|
104 |
+
masked_depth=make_inpaint_condition(depth_image,mask1)
|
105 |
+
|
106 |
images_CN = [depth_image, canny_image]
|
107 |
|
108 |
+
|
109 |
+
prompt1 = 'A frontpage still-life photograph, an 8-foot wooden crate, '+ prompt
|
110 |
neg1 = 'text,watermark'
|
111 |
prompt2 = 'Photorealistic rendering, of an OurHood privacy booth, with a silken oak frame, hickory stained melange polyester fabric, windows'
|
112 |
neg2 = 'curtains, pillows'
|
|
|
119 |
num_inference_steps=n_steps,
|
120 |
num_images_per_prompt=1,
|
121 |
generator=generator,
|
122 |
+
denoising_end=0.9,
|
123 |
+
image=[depth_image,masked_depth],
|
124 |
output_type="latent",
|
125 |
control_guidance_start=[0.0,0.5],
|
126 |
control_guidance_end=[0.5,1.0],
|
|
|
134 |
image = refiner(
|
135 |
prompt=prompt1,
|
136 |
num_inference_steps=n_steps,
|
137 |
+
denoising_start=0.9,
|
138 |
image=results).images[0]
|
139 |
|
140 |
|
|
|
146 |
negative_prompt=neg2,
|
147 |
image=image,
|
148 |
mask_image=mask1,
|
149 |
+
num_inference_steps=65,
|
150 |
strength=1.0,
|
151 |
control_guidance_end=[0.9,0.9],
|
152 |
+
controlnet_conditioning_scale=[0.35, 0.65],
|
153 |
control_image=images_CN,
|
154 |
generator=generator,
|
155 |
).images[0]
|