svjack commited on
Commit
ad0ab61
โ€ข
1 Parent(s): 738df7c

Create switch_app_multi_download.py

Browse files
Files changed (1) hide show
  1. switch_app_multi_download.py +491 -0
switch_app_multi_download.py ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import torch
4
+ import cv2
5
+ import gradio as gr
6
+ import numpy as np
7
+ from huggingface_hub import snapshot_download
8
+ from transformers import CLIPVisionModelWithProjection, CLIPImageProcessor
9
+ from diffusers.utils import load_image
10
+ from kolors.pipelines.pipeline_controlnet_xl_kolors_img2img import StableDiffusionXLControlNetImg2ImgPipeline
11
+ from kolors.models.modeling_chatglm import ChatGLMModel
12
+ from kolors.models.tokenization_chatglm import ChatGLMTokenizer
13
+ from kolors.models.controlnet import ControlNetModel
14
+ from diffusers import AutoencoderKL
15
+ from kolors.models.unet_2d_condition import UNet2DConditionModel
16
+ from diffusers import EulerDiscreteScheduler
17
+ from PIL import Image
18
+ from annotator.midas import MidasDetector
19
+ from annotator.dwpose import DWposeDetector
20
+ from annotator.util import resize_image, HWC3
21
+ from zipfile import ZipFile
22
+ from uuid import uuid1
23
+ from PIL import Image
24
+
25
+ device = "cuda"
26
+ ckpt_dir = snapshot_download(repo_id="Kwai-Kolors/Kolors")
27
+ ckpt_dir_depth = snapshot_download(repo_id="Kwai-Kolors/Kolors-ControlNet-Depth")
28
+ ckpt_dir_canny = snapshot_download(repo_id="Kwai-Kolors/Kolors-ControlNet-Canny")
29
+ ckpt_dir_ipa = snapshot_download(repo_id="Kwai-Kolors/Kolors-IP-Adapter-Plus")
30
+ ckpt_dir_pose = snapshot_download(repo_id="Kwai-Kolors/Kolors-ControlNet-Pose")
31
+ '''
32
+ ckpt_dir = "Kolors"
33
+ ckpt_dir_depth = "Kolors-ControlNet-Depth"
34
+ ckpt_dir_canny = "Kolors-ControlNet-Canny"
35
+ ckpt_dir_ipa = "Kolors-IP-Adapter-Plus"
36
+ ckpt_dir_pose = "Kolors-ControlNet-Pose"
37
+ '''
38
+
39
+ text_encoder = ChatGLMModel.from_pretrained(f'{ckpt_dir}/text_encoder', torch_dtype=torch.float16).half().to(device)
40
+ tokenizer = ChatGLMTokenizer.from_pretrained(f'{ckpt_dir}/text_encoder')
41
+ vae = AutoencoderKL.from_pretrained(f"{ckpt_dir}/vae", revision=None).half().to(device)
42
+ scheduler = EulerDiscreteScheduler.from_pretrained(f"{ckpt_dir}/scheduler")
43
+ unet = UNet2DConditionModel.from_pretrained(f"{ckpt_dir}/unet", revision=None).half().to(device)
44
+
45
+ image_encoder = CLIPVisionModelWithProjection.from_pretrained(f'{ckpt_dir_ipa}/image_encoder', ignore_mismatched_sizes=True).to(dtype=torch.float16, device=device)
46
+ ip_img_size = 336
47
+ clip_image_processor = CLIPImageProcessor(size=ip_img_size, crop_size=ip_img_size)
48
+
49
+ model_midas = MidasDetector()
50
+ model_dwpose = DWposeDetector()
51
+
52
+ MAX_SEED = np.iinfo(np.int32).max
53
+ MAX_IMAGE_SIZE = 512
54
+
55
+ def process_canny_condition(image, canny_threods=[100, 200]):
56
+ np_image = image.copy()
57
+ np_image = cv2.Canny(np_image, canny_threods[0], canny_threods[1])
58
+ np_image = np_image[:, :, None]
59
+ np_image = np.concatenate([np_image, np_image, np_image], axis=2)
60
+ np_image = HWC3(np_image)
61
+ return Image.fromarray(np_image)
62
+
63
+ def process_depth_condition_midas(img, res=1024):
64
+ h, w, _ = img.shape
65
+ img = resize_image(HWC3(img), res)
66
+ result = HWC3(model_midas(img))
67
+ result = cv2.resize(result, (w, h))
68
+ return Image.fromarray(result)
69
+
70
+ def process_dwpose_condition(image, res=1024):
71
+ h, w, _ = image.shape
72
+ img = resize_image(HWC3(image), res)
73
+ out_res, out_img = model_dwpose(image)
74
+ result = HWC3(out_img)
75
+ result = cv2.resize(result, (w, h))
76
+ return Image.fromarray(result)
77
+
78
+ def infer_canny(prompt,
79
+ image=None,
80
+ ipa_img=None,
81
+ negative_prompt="nsfw๏ผŒ่„ธ้ƒจ้˜ดๅฝฑ๏ผŒไฝŽๅˆ†่พจ็Ž‡๏ผŒ็ณŸ็ณ•็š„่งฃๅ‰–็ป“ๆž„ใ€็ณŸ็ณ•็š„ๆ‰‹๏ผŒ็ผบๅคฑๆ‰‹ๆŒ‡ใ€่ดจ้‡ๆœ€ๅทฎใ€ไฝŽ่ดจ้‡ใ€jpegไผชๅฝฑใ€ๆจก็ณŠใ€็ณŸ็ณ•๏ผŒ้ป‘่„ธ๏ผŒ้œ“่™น็ฏ",
82
+ seed=66,
83
+ randomize_seed=False,
84
+ guidance_scale=5.0,
85
+ num_inference_steps=50,
86
+ controlnet_conditioning_scale=0.5,
87
+ control_guidance_end=0.9,
88
+ strength=1.0,
89
+ ip_scale=0.5,
90
+ num_images=1):
91
+ if randomize_seed:
92
+ seed = random.randint(0, MAX_SEED)
93
+ init_image = resize_image(image, MAX_IMAGE_SIZE)
94
+ pipe = pipe_canny.to("cuda")
95
+ pipe.set_ip_adapter_scale([ip_scale])
96
+ condi_img = process_canny_condition(np.array(init_image))
97
+ images = []
98
+ for i in range(num_images):
99
+ generator = torch.Generator().manual_seed(seed + i)
100
+ image = pipe(
101
+ prompt=prompt,
102
+ image=init_image,
103
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
104
+ control_guidance_end=control_guidance_end,
105
+ ip_adapter_image=[ipa_img],
106
+ strength=strength,
107
+ control_image=condi_img,
108
+ negative_prompt=negative_prompt,
109
+ num_inference_steps=num_inference_steps,
110
+ guidance_scale=guidance_scale,
111
+ num_images_per_prompt=1,
112
+ generator=generator,
113
+ ).images[0]
114
+ images.append(image)
115
+ return [condi_img] + images, seed
116
+
117
+ def infer_depth(prompt,
118
+ image=None,
119
+ ipa_img=None,
120
+ negative_prompt="nsfw๏ผŒ่„ธ้ƒจ้˜ดๅฝฑ๏ผŒไฝŽๅˆ†่พจ็Ž‡๏ผŒ็ณŸ็ณ•็š„่งฃๅ‰–็ป“ๆž„ใ€็ณŸ็ณ•็š„ๆ‰‹๏ผŒ็ผบๅคฑๆ‰‹ๆŒ‡ใ€่ดจ้‡ๆœ€ๅทฎใ€ไฝŽ่ดจ้‡ใ€jpegไผช๏ฟฝ๏ฟฝ๏ฟฝใ€ๆจก็ณŠใ€็ณŸ็ณ•๏ผŒ้ป‘่„ธ๏ผŒ้œ“่™น็ฏ",
121
+ seed=66,
122
+ randomize_seed=False,
123
+ guidance_scale=5.0,
124
+ num_inference_steps=50,
125
+ controlnet_conditioning_scale=0.5,
126
+ control_guidance_end=0.9,
127
+ strength=1.0,
128
+ ip_scale=0.5,
129
+ num_images=1):
130
+ if randomize_seed:
131
+ seed = random.randint(0, MAX_SEED)
132
+ init_image = resize_image(image, MAX_IMAGE_SIZE)
133
+ pipe = pipe_depth.to("cuda")
134
+ pipe.set_ip_adapter_scale([ip_scale])
135
+ condi_img = process_depth_condition_midas(np.array(init_image), MAX_IMAGE_SIZE)
136
+ images = []
137
+ for i in range(num_images):
138
+ generator = torch.Generator().manual_seed(seed + i)
139
+ image = pipe(
140
+ prompt=prompt,
141
+ image=init_image,
142
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
143
+ control_guidance_end=control_guidance_end,
144
+ ip_adapter_image=[ipa_img],
145
+ strength=strength,
146
+ control_image=condi_img,
147
+ negative_prompt=negative_prompt,
148
+ num_inference_steps=num_inference_steps,
149
+ guidance_scale=guidance_scale,
150
+ num_images_per_prompt=1,
151
+ generator=generator,
152
+ ).images[0]
153
+ images.append(image)
154
+ return [condi_img] + images, seed
155
+
156
+ def infer_pose(prompt,
157
+ image=None,
158
+ ipa_img=None,
159
+ negative_prompt="nsfw๏ผŒ่„ธ้ƒจ้˜ดๅฝฑ๏ผŒไฝŽๅˆ†่พจ็Ž‡๏ผŒjpegไผชๅฝฑใ€ๆจก็ณŠใ€็ณŸ็ณ•๏ผŒ้ป‘่„ธ๏ผŒ้œ“่™น็ฏ",
160
+ seed=66,
161
+ randomize_seed=False,
162
+ guidance_scale=5.0,
163
+ num_inference_steps=50,
164
+ controlnet_conditioning_scale=0.5,
165
+ control_guidance_end=0.9,
166
+ strength=1.0,
167
+ ip_scale=0.5,
168
+ num_images=1):
169
+ if randomize_seed:
170
+ seed = random.randint(0, MAX_SEED)
171
+ init_image = resize_image(image, MAX_IMAGE_SIZE)
172
+ pipe = pipe_pose.to("cuda")
173
+ pipe.set_ip_adapter_scale([ip_scale])
174
+ condi_img = process_dwpose_condition(np.array(init_image), MAX_IMAGE_SIZE)
175
+ images = []
176
+ for i in range(num_images):
177
+ generator = torch.Generator().manual_seed(seed + i)
178
+ image = pipe(
179
+ prompt=prompt,
180
+ image=init_image,
181
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
182
+ control_guidance_end=control_guidance_end,
183
+ ip_adapter_image=[ipa_img],
184
+ strength=strength,
185
+ control_image=condi_img,
186
+ negative_prompt=negative_prompt,
187
+ num_inference_steps=num_inference_steps,
188
+ guidance_scale=guidance_scale,
189
+ num_images_per_prompt=1,
190
+ generator=generator,
191
+ ).images[0]
192
+ images.append(image)
193
+ return [condi_img] + images, seed
194
+
195
+ canny_examples = [
196
+ ["ไธ€ไธช็บข่‰ฒๅคดๅ‘็š„ๅฅณๅญฉ๏ผŒๅ”ฏ็พŽ้ฃŽๆ™ฏ๏ผŒๆธ…ๆ–ฐๆ˜Žไบฎ๏ผŒๆ–‘้ฉณ็š„ๅ…‰ๅฝฑ๏ผŒๆœ€ๅฅฝ็š„่ดจ้‡๏ผŒ่ถ…็ป†่Š‚๏ผŒ8K็”ป่ดจ",
197
+ "image/woman_2.png", "image/2.png", 3],
198
+ ]
199
+
200
+ depth_examples = [
201
+ ["ไธ€ไธชๆผ‚ไบฎ็š„ๅฅณๅญฉ๏ผŒๆœ€ๅฅฝ็š„่ดจ้‡๏ผŒ่ถ…็ป†่Š‚๏ผŒ8K็”ป่ดจ",
202
+ "image/1.png", "image/woman_1.png", 3],
203
+ ]
204
+
205
+ pose_examples = [
206
+ ["ไธ€ไฝ็ฉฟ็€็ดซ่‰ฒๆณกๆณก่ข–่ฟž่กฃ่ฃ™ใ€ๆˆด็€็š‡ๅ† ๅ’Œ็™ฝ่‰ฒ่•พไธๆ‰‹ๅฅ—็š„ๅฅณๅญฉ๏ผŒ่ถ…้ซ˜ๅˆ†่พจ็Ž‡๏ผŒๆœ€ไฝณๅ“่ดจ๏ผŒ8k็”ป่ดจ",
207
+ "image/woman_3.png", "image/woman_4.png", 3],
208
+ ]
209
+
210
+ css = """
211
+ #col-left {
212
+ margin: 0 auto;
213
+ max-width: 600px;
214
+ }
215
+ #col-right {
216
+ margin: 0 auto;
217
+ max-width: 750px;
218
+ }
219
+ #button {
220
+ color: blue;
221
+ }
222
+ """
223
+
224
+ def load_description(fp):
225
+ with open(fp, 'r', encoding='utf-8') as f:
226
+ content = f.read()
227
+ return content
228
+
229
+ def clear_resources():
230
+ global pipe_canny, pipe_depth, pipe_pose
231
+ if 'pipe_canny' in globals():
232
+ del pipe_canny
233
+ if 'pipe_depth' in globals():
234
+ del pipe_depth
235
+ if 'pipe_pose' in globals():
236
+ del pipe_pose
237
+ torch.cuda.empty_cache()
238
+
239
+ def load_canny_pipeline():
240
+ global pipe_canny
241
+ controlnet_canny = ControlNetModel.from_pretrained(f"{ckpt_dir_canny}", revision=None).half().to(device)
242
+ pipe_canny = StableDiffusionXLControlNetImg2ImgPipeline(
243
+ vae=vae,
244
+ controlnet=controlnet_canny,
245
+ text_encoder=text_encoder,
246
+ tokenizer=tokenizer,
247
+ unet=unet,
248
+ scheduler=scheduler,
249
+ image_encoder=image_encoder,
250
+ feature_extractor=clip_image_processor,
251
+ force_zeros_for_empty_prompt=False
252
+ )
253
+ pipe_canny.load_ip_adapter(f'{ckpt_dir_ipa}', subfolder="", weight_name=["ip_adapter_plus_general.bin"])
254
+
255
+ def load_depth_pipeline():
256
+ global pipe_depth
257
+ controlnet_depth = ControlNetModel.from_pretrained(f"{ckpt_dir_depth}", revision=None).half().to(device)
258
+ pipe_depth = StableDiffusionXLControlNetImg2ImgPipeline(
259
+ vae=vae,
260
+ controlnet=controlnet_depth,
261
+ text_encoder=text_encoder,
262
+ tokenizer=tokenizer,
263
+ unet=unet,
264
+ scheduler=scheduler,
265
+ image_encoder=image_encoder,
266
+ feature_extractor=clip_image_processor,
267
+ force_zeros_for_empty_prompt=False
268
+ )
269
+ pipe_depth.load_ip_adapter(f'{ckpt_dir_ipa}', subfolder="", weight_name=["ip_adapter_plus_general.bin"])
270
+
271
+ def load_pose_pipeline():
272
+ global pipe_pose
273
+ controlnet_pose = ControlNetModel.from_pretrained(f"{ckpt_dir_pose}", revision=None).half().to(device)
274
+ pipe_pose = StableDiffusionXLControlNetImg2ImgPipeline(
275
+ vae=vae,
276
+ controlnet=controlnet_pose,
277
+ text_encoder=text_encoder,
278
+ tokenizer=tokenizer,
279
+ unet=unet,
280
+ scheduler=scheduler,
281
+ image_encoder=image_encoder,
282
+ feature_extractor=clip_image_processor,
283
+ force_zeros_for_empty_prompt=False
284
+ )
285
+ pipe_pose.load_ip_adapter(f'{ckpt_dir_ipa}', subfolder="", weight_name=["ip_adapter_plus_general.bin"])
286
+
287
+ def switch_to_canny():
288
+ clear_resources()
289
+ load_canny_pipeline()
290
+ return gr.update(visible=True)
291
+
292
+ def switch_to_depth():
293
+ clear_resources()
294
+ load_depth_pipeline()
295
+ return gr.update(visible=True)
296
+
297
+ def switch_to_pose():
298
+ clear_resources()
299
+ load_pose_pipeline()
300
+ return gr.update(visible=True)
301
+
302
+ def zip_images(gallery, zip_name):
303
+ if gallery is None or len(gallery) == 0:
304
+ return None
305
+
306
+ if not zip_name:
307
+ zip_name = "generated_images.zip"
308
+
309
+ with ZipFile(zip_name, "w") as zipObj:
310
+ for i, image in enumerate(gallery):
311
+ temp_file = f"temp_{i}.png"
312
+ Image.open(image[0]).save(temp_file)
313
+ #image.save(temp_file)
314
+ zipObj.write(temp_file, f"image_{i}.png")
315
+ os.remove(temp_file)
316
+
317
+ return zip_name
318
+
319
+ def update_zip_name(ipa_image_file):
320
+ #print(ipa_image_file)
321
+ if ipa_image_file is not None and type(ipa_image_file) == type(""):
322
+ name = ipa_image_file.split("/")[-1].split('.')[0]
323
+ return "{}_generated_images.zip".format(name)
324
+ return "generated_images.zip"
325
+
326
+ with gr.Blocks(css=css) as Kolors:
327
+ gr.HTML(load_description("assets/title.md"))
328
+ with gr.Row():
329
+ with gr.Column(elem_id="col-left"):
330
+ with gr.Row():
331
+ prompt = gr.Textbox(
332
+ label="Prompt",
333
+ placeholder="Enter your prompt",
334
+ lines=2
335
+ )
336
+ with gr.Row():
337
+ image = gr.Image(label="Image", type="pil")
338
+ #ipa_image = gr.Image(label="IP-Adapter-Image", type="pil")
339
+ ipa_image = gr.Image(type="pil", visible = False)
340
+ ipa_image_file = gr.Image(type = "filepath", label="IP-Adapter-Image")
341
+ with gr.Row():
342
+ num_images = gr.Slider(
343
+ label="Number of Images",
344
+ minimum=1,
345
+ maximum=10,
346
+ step=1,
347
+ value=1,
348
+ )
349
+ with gr.Accordion("Advanced Settings", open=False):
350
+ negative_prompt = gr.Textbox(
351
+ label="Negative prompt",
352
+ placeholder="Enter a negative prompt",
353
+ visible=True,
354
+ value="nsfw๏ผŒ่„ธ้ƒจ้˜ดๅฝฑ๏ผŒไฝŽๅˆ†่พจ็Ž‡๏ผŒ็ณŸ็ณ•็š„่งฃๅ‰–็ป“ๆž„ใ€็ณŸ็ณ•็š„ๆ‰‹๏ผŒ็ผบๅคฑๆ‰‹ๆŒ‡ใ€่ดจ้‡ๆœ€ๅทฎใ€ไฝŽ่ดจ้‡ใ€jpegไผชๅฝฑใ€ๆจก็ณŠใ€็ณŸ็ณ•๏ผŒ้ป‘่„ธ๏ผŒ้œ“่™น็ฏ"
355
+ )
356
+ seed = gr.Slider(
357
+ label="Seed",
358
+ minimum=0,
359
+ maximum=MAX_SEED,
360
+ step=1,
361
+ value=0,
362
+ )
363
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
364
+ with gr.Row():
365
+ guidance_scale = gr.Slider(
366
+ label="Guidance scale",
367
+ minimum=0.0,
368
+ maximum=10.0,
369
+ step=0.1,
370
+ value=5.0,
371
+ )
372
+ num_inference_steps = gr.Slider(
373
+ label="Number of inference steps",
374
+ minimum=10,
375
+ maximum=50,
376
+ step=1,
377
+ value=30,
378
+ )
379
+ with gr.Row():
380
+ controlnet_conditioning_scale = gr.Slider(
381
+ label="Controlnet Conditioning Scale",
382
+ minimum=0.0,
383
+ maximum=1.0,
384
+ step=0.1,
385
+ value=0.5,
386
+ )
387
+ control_guidance_end = gr.Slider(
388
+ label="Control Guidance End",
389
+ minimum=0.0,
390
+ maximum=1.0,
391
+ step=0.1,
392
+ value=0.9,
393
+ )
394
+ with gr.Row():
395
+ strength = gr.Slider(
396
+ label="Strength",
397
+ minimum=0.0,
398
+ maximum=1.0,
399
+ step=0.1,
400
+ value=1.0,
401
+ )
402
+ ip_scale = gr.Slider(
403
+ label="IP_Scale",
404
+ minimum=0.0,
405
+ maximum=1.0,
406
+ step=0.1,
407
+ value=0.5,
408
+ )
409
+ with gr.Row():
410
+ canny_button = gr.Button("Canny", elem_id="button")
411
+ depth_button = gr.Button("Depth", elem_id="button")
412
+ pose_button = gr.Button("Pose", elem_id="button")
413
+
414
+ with gr.Column(elem_id="col-right"):
415
+ result = gr.Gallery(label="Result", show_label=False, columns=3)
416
+ seed_used = gr.Number(label="Seed Used")
417
+ zip_name = gr.Textbox(label="Zip File Name", value="generated_images.zip")
418
+ zip_button = gr.Button("Zip Images as Zip", elem_id="button")
419
+ download_file = gr.File(label="Download Zip File of Image")
420
+
421
+ with gr.Row():
422
+ gr.Examples(
423
+ fn=infer_canny,
424
+ examples=canny_examples,
425
+ inputs=[prompt, image, ipa_image_file, num_images],
426
+ outputs=[result, seed_used],
427
+ label="Canny"
428
+ )
429
+ with gr.Row():
430
+ gr.Examples(
431
+ fn=infer_depth,
432
+ examples=depth_examples,
433
+ inputs=[prompt, image, ipa_image_file, num_images],
434
+ outputs=[result, seed_used],
435
+ label="Depth"
436
+ )
437
+ with gr.Row():
438
+ gr.Examples(
439
+ fn=infer_pose,
440
+ examples=pose_examples,
441
+ inputs=[prompt, image, ipa_image_file, num_images],
442
+ outputs=[result, seed_used],
443
+ label="Pose"
444
+ )
445
+
446
+ canny_button.click(
447
+ fn=switch_to_canny,
448
+ outputs=[canny_button]
449
+ ).then(
450
+ fn=infer_canny,
451
+ inputs=[prompt, image, ipa_image, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength, ip_scale, num_images],
452
+ outputs=[result, seed_used]
453
+ )
454
+
455
+ depth_button.click(
456
+ fn=switch_to_depth,
457
+ outputs=[depth_button]
458
+ ).then(
459
+ fn=infer_depth,
460
+ inputs=[prompt, image, ipa_image, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength, ip_scale, num_images],
461
+ outputs=[result, seed_used]
462
+ )
463
+
464
+ pose_button.click(
465
+ fn=switch_to_pose,
466
+ outputs=[pose_button]
467
+ ).then(
468
+ fn=infer_pose,
469
+ inputs=[prompt, image, ipa_image, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength, ip_scale, num_images],
470
+ outputs=[result, seed_used]
471
+ )
472
+
473
+ ipa_image_file.change(
474
+ fn = lambda x: Image.open(x),
475
+ inputs = [ipa_image_file],
476
+ outputs = [ipa_image]
477
+ )
478
+
479
+ ipa_image_file.change(
480
+ fn=update_zip_name,
481
+ inputs=[ipa_image_file],
482
+ outputs=[zip_name]
483
+ )
484
+
485
+ zip_button.click(
486
+ fn=zip_images,
487
+ inputs=[result, zip_name],
488
+ outputs=download_file
489
+ )
490
+
491
+ Kolors.queue().launch(debug=True, share=True)