Commit ·
8c78e27
1
Parent(s): e74fb8a
28. Sept. 2024, 16:42
Browse files
app.py
CHANGED
|
@@ -31,6 +31,8 @@ title = "ControlNet v1.1 Preprocessors Standalone"
|
|
| 31 |
|
| 32 |
# Canny
|
| 33 |
model_canny = None
|
|
|
|
|
|
|
| 34 |
def canny(img, res, l, h):
|
| 35 |
img = resize_image(HWC3(img), res)
|
| 36 |
global model_canny
|
|
@@ -41,8 +43,11 @@ def canny(img, res, l, h):
|
|
| 41 |
result = model_canny(img, l, h)
|
| 42 |
return [result]
|
| 43 |
|
|
|
|
| 44 |
# Hed
|
| 45 |
model_hed = None
|
|
|
|
|
|
|
| 46 |
def hed(img, res):
|
| 47 |
img = resize_image(HWC3(img), res)
|
| 48 |
global model_hed
|
|
@@ -53,8 +58,11 @@ def hed(img, res):
|
|
| 53 |
result = model_hed(img)
|
| 54 |
return [result]
|
| 55 |
|
|
|
|
| 56 |
# Pidi
|
| 57 |
model_pidi = None
|
|
|
|
|
|
|
| 58 |
def pidi(img, res):
|
| 59 |
img = resize_image(HWC3(img), res)
|
| 60 |
global model_pidi
|
|
@@ -65,8 +73,11 @@ def pidi(img, res):
|
|
| 65 |
result = model_pidi(img)
|
| 66 |
return [result]
|
| 67 |
|
|
|
|
| 68 |
# MLSD
|
| 69 |
model_mlsd = None
|
|
|
|
|
|
|
| 70 |
def mlsd(img, res, thr_v, thr_d):
|
| 71 |
img = resize_image(HWC3(img), res)
|
| 72 |
global model_mlsd
|
|
@@ -77,8 +88,11 @@ def mlsd(img, res, thr_v, thr_d):
|
|
| 77 |
result = model_mlsd(img, thr_v, thr_d)
|
| 78 |
return [result]
|
| 79 |
|
|
|
|
| 80 |
# Midas
|
| 81 |
model_midas = None
|
|
|
|
|
|
|
| 82 |
def midas(img, res):
|
| 83 |
img = resize_image(HWC3(img), res)
|
| 84 |
global model_midas
|
|
@@ -89,8 +103,11 @@ def midas(img, res):
|
|
| 89 |
result = model_midas(img)
|
| 90 |
return [result]
|
| 91 |
|
|
|
|
| 92 |
# Zoe
|
| 93 |
model_zoe = None
|
|
|
|
|
|
|
| 94 |
def zoe(img, res):
|
| 95 |
img = resize_image(HWC3(img), res)
|
| 96 |
global model_zoe
|
|
@@ -101,8 +118,11 @@ def zoe(img, res):
|
|
| 101 |
result = model_zoe(img)
|
| 102 |
return [result]
|
| 103 |
|
|
|
|
| 104 |
# Normal Bae
|
| 105 |
model_normalbae = None
|
|
|
|
|
|
|
| 106 |
def normalbae(img, res):
|
| 107 |
img = resize_image(HWC3(img), res)
|
| 108 |
global model_normalbae
|
|
@@ -113,8 +133,11 @@ def normalbae(img, res):
|
|
| 113 |
result = model_normalbae(img)
|
| 114 |
return [result]
|
| 115 |
|
|
|
|
| 116 |
# DWPose
|
| 117 |
model_dwpose = None
|
|
|
|
|
|
|
| 118 |
def dwpose(img, res):
|
| 119 |
img = resize_image(HWC3(img), res)
|
| 120 |
global model_dwpose
|
|
@@ -125,8 +148,11 @@ def dwpose(img, res):
|
|
| 125 |
result = model_dwpose(img)
|
| 126 |
return [result]
|
| 127 |
|
|
|
|
| 128 |
# OpenPose
|
| 129 |
model_openpose = None
|
|
|
|
|
|
|
| 130 |
def openpose(img, res, hand_and_face):
|
| 131 |
img = resize_image(HWC3(img), res)
|
| 132 |
global model_openpose
|
|
@@ -152,6 +178,8 @@ def openpose(img, res, hand_and_face):
|
|
| 152 |
# Lineart
|
| 153 |
model_lineart_anime = None
|
| 154 |
model_lineart = None
|
|
|
|
|
|
|
| 155 |
def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None):
|
| 156 |
print("Old Images: ", old_images)
|
| 157 |
result_images = []
|
|
@@ -186,8 +214,11 @@ def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None)
|
|
| 186 |
result_images.extend(old_images)
|
| 187 |
return result_images
|
| 188 |
|
|
|
|
| 189 |
# OneFormer
|
| 190 |
model_oneformer_coco = None
|
|
|
|
|
|
|
| 191 |
def oneformer_coco(img, res):
|
| 192 |
img = resize_image(HWC3(img), res)
|
| 193 |
global model_oneformer_coco
|
|
@@ -198,8 +229,11 @@ def oneformer_coco(img, res):
|
|
| 198 |
result = model_oneformer_coco(img)
|
| 199 |
return [result]
|
| 200 |
|
|
|
|
| 201 |
# OneFormer ADE20k
|
| 202 |
model_oneformer_ade20k = None
|
|
|
|
|
|
|
| 203 |
def oneformer_ade20k(img, res):
|
| 204 |
img = resize_image(HWC3(img), res)
|
| 205 |
global model_oneformer_ade20k
|
|
@@ -210,8 +244,11 @@ def oneformer_ade20k(img, res):
|
|
| 210 |
result = model_oneformer_ade20k(img)
|
| 211 |
return [result]
|
| 212 |
|
|
|
|
| 213 |
# Content Shuffler
|
| 214 |
model_content_shuffler = None
|
|
|
|
|
|
|
| 215 |
def content_shuffler(img, res):
|
| 216 |
img = resize_image(HWC3(img), res)
|
| 217 |
global model_content_shuffler
|
|
@@ -222,8 +259,11 @@ def content_shuffler(img, res):
|
|
| 222 |
result = model_content_shuffler(img)
|
| 223 |
return [result]
|
| 224 |
|
|
|
|
| 225 |
# Color Shuffler
|
| 226 |
model_color_shuffler = None
|
|
|
|
|
|
|
| 227 |
def color_shuffler(img, res):
|
| 228 |
img = resize_image(HWC3(img), res)
|
| 229 |
global model_color_shuffler
|
|
@@ -234,8 +274,11 @@ def color_shuffler(img, res):
|
|
| 234 |
result = model_color_shuffler(img)
|
| 235 |
return [result]
|
| 236 |
|
|
|
|
| 237 |
# Inpaint
|
| 238 |
model_inpaint = None
|
|
|
|
|
|
|
| 239 |
def inpaint(image, invert):
|
| 240 |
# color = HWC3(image["image"])
|
| 241 |
color = HWC3(image["background"])
|
|
@@ -283,12 +326,7 @@ with gr.Blocks(theme=theme, css=custom_css, js=custom_js, head=custom_head, titl
|
|
| 283 |
resolution = gr.Slider(label="Auflösung", minimum=256, maximum=1024, value=512, step=64)
|
| 284 |
run_btn_lineart = gr.Button("Run")
|
| 285 |
invert.change(lambda x: {"info": invert_toggle_info[0] if x else invert_toggle_info[1], "__type__": "update"}, inputs=invert, outputs=invert)
|
| 286 |
-
|
| 287 |
-
global input_options
|
| 288 |
-
if tab_name == "Lineart":
|
| 289 |
-
input_options = [preprocessor_name, invert]
|
| 290 |
-
return {"preprocessor_name": preprocessor_name, "invert": invert, "resolution": resolution}
|
| 291 |
-
|
| 292 |
## TAB Canny
|
| 293 |
with gr.Tab("Canny Edge") as tab_canny:
|
| 294 |
with gr.Row():
|
|
@@ -299,14 +337,25 @@ with gr.Blocks(theme=theme, css=custom_css, js=custom_js, head=custom_head, titl
|
|
| 299 |
high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
|
| 300 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
run_btn_lineart = gr.Button("Run", visible=False)
|
| 304 |
run_btn_canny = gr.Button("Run", visible=False)
|
| 305 |
-
|
| 306 |
all_run_btns = [run_btn_lineart, run_btn_canny]
|
| 307 |
-
|
| 308 |
-
tab_lineart.select(
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
with gr.Column(scale=2):
|
| 311 |
gallery = gr.Gallery(label="Generated images", show_label=False, interactive=False, format="png", elem_id="output_gallery", elem_classes="output-gallery", columns=[3], rows=[2], object_fit="contain", height="auto", type="filepath")
|
| 312 |
|
|
|
|
| 31 |
|
| 32 |
# Canny
|
| 33 |
model_canny = None
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def canny(img, res, l, h):
|
| 37 |
img = resize_image(HWC3(img), res)
|
| 38 |
global model_canny
|
|
|
|
| 43 |
result = model_canny(img, l, h)
|
| 44 |
return [result]
|
| 45 |
|
| 46 |
+
|
| 47 |
# Hed
|
| 48 |
model_hed = None
|
| 49 |
+
|
| 50 |
+
|
| 51 |
def hed(img, res):
|
| 52 |
img = resize_image(HWC3(img), res)
|
| 53 |
global model_hed
|
|
|
|
| 58 |
result = model_hed(img)
|
| 59 |
return [result]
|
| 60 |
|
| 61 |
+
|
| 62 |
# Pidi
|
| 63 |
model_pidi = None
|
| 64 |
+
|
| 65 |
+
|
| 66 |
def pidi(img, res):
|
| 67 |
img = resize_image(HWC3(img), res)
|
| 68 |
global model_pidi
|
|
|
|
| 73 |
result = model_pidi(img)
|
| 74 |
return [result]
|
| 75 |
|
| 76 |
+
|
| 77 |
# MLSD
|
| 78 |
model_mlsd = None
|
| 79 |
+
|
| 80 |
+
|
| 81 |
def mlsd(img, res, thr_v, thr_d):
|
| 82 |
img = resize_image(HWC3(img), res)
|
| 83 |
global model_mlsd
|
|
|
|
| 88 |
result = model_mlsd(img, thr_v, thr_d)
|
| 89 |
return [result]
|
| 90 |
|
| 91 |
+
|
| 92 |
# Midas
|
| 93 |
model_midas = None
|
| 94 |
+
|
| 95 |
+
|
| 96 |
def midas(img, res):
|
| 97 |
img = resize_image(HWC3(img), res)
|
| 98 |
global model_midas
|
|
|
|
| 103 |
result = model_midas(img)
|
| 104 |
return [result]
|
| 105 |
|
| 106 |
+
|
| 107 |
# Zoe
|
| 108 |
model_zoe = None
|
| 109 |
+
|
| 110 |
+
|
| 111 |
def zoe(img, res):
|
| 112 |
img = resize_image(HWC3(img), res)
|
| 113 |
global model_zoe
|
|
|
|
| 118 |
result = model_zoe(img)
|
| 119 |
return [result]
|
| 120 |
|
| 121 |
+
|
| 122 |
# Normal Bae
|
| 123 |
model_normalbae = None
|
| 124 |
+
|
| 125 |
+
|
| 126 |
def normalbae(img, res):
|
| 127 |
img = resize_image(HWC3(img), res)
|
| 128 |
global model_normalbae
|
|
|
|
| 133 |
result = model_normalbae(img)
|
| 134 |
return [result]
|
| 135 |
|
| 136 |
+
|
| 137 |
# DWPose
|
| 138 |
model_dwpose = None
|
| 139 |
+
|
| 140 |
+
|
| 141 |
def dwpose(img, res):
|
| 142 |
img = resize_image(HWC3(img), res)
|
| 143 |
global model_dwpose
|
|
|
|
| 148 |
result = model_dwpose(img)
|
| 149 |
return [result]
|
| 150 |
|
| 151 |
+
|
| 152 |
# OpenPose
|
| 153 |
model_openpose = None
|
| 154 |
+
|
| 155 |
+
|
| 156 |
def openpose(img, res, hand_and_face):
|
| 157 |
img = resize_image(HWC3(img), res)
|
| 158 |
global model_openpose
|
|
|
|
| 178 |
# Lineart
|
| 179 |
model_lineart_anime = None
|
| 180 |
model_lineart = None
|
| 181 |
+
|
| 182 |
+
|
| 183 |
def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None):
|
| 184 |
print("Old Images: ", old_images)
|
| 185 |
result_images = []
|
|
|
|
| 214 |
result_images.extend(old_images)
|
| 215 |
return result_images
|
| 216 |
|
| 217 |
+
|
| 218 |
# OneFormer
|
| 219 |
model_oneformer_coco = None
|
| 220 |
+
|
| 221 |
+
|
| 222 |
def oneformer_coco(img, res):
|
| 223 |
img = resize_image(HWC3(img), res)
|
| 224 |
global model_oneformer_coco
|
|
|
|
| 229 |
result = model_oneformer_coco(img)
|
| 230 |
return [result]
|
| 231 |
|
| 232 |
+
|
| 233 |
# OneFormer ADE20k
|
| 234 |
model_oneformer_ade20k = None
|
| 235 |
+
|
| 236 |
+
|
| 237 |
def oneformer_ade20k(img, res):
|
| 238 |
img = resize_image(HWC3(img), res)
|
| 239 |
global model_oneformer_ade20k
|
|
|
|
| 244 |
result = model_oneformer_ade20k(img)
|
| 245 |
return [result]
|
| 246 |
|
| 247 |
+
|
| 248 |
# Content Shuffler
|
| 249 |
model_content_shuffler = None
|
| 250 |
+
|
| 251 |
+
|
| 252 |
def content_shuffler(img, res):
|
| 253 |
img = resize_image(HWC3(img), res)
|
| 254 |
global model_content_shuffler
|
|
|
|
| 259 |
result = model_content_shuffler(img)
|
| 260 |
return [result]
|
| 261 |
|
| 262 |
+
|
| 263 |
# Color Shuffler
|
| 264 |
model_color_shuffler = None
|
| 265 |
+
|
| 266 |
+
|
| 267 |
def color_shuffler(img, res):
|
| 268 |
img = resize_image(HWC3(img), res)
|
| 269 |
global model_color_shuffler
|
|
|
|
| 274 |
result = model_color_shuffler(img)
|
| 275 |
return [result]
|
| 276 |
|
| 277 |
+
|
| 278 |
# Inpaint
|
| 279 |
model_inpaint = None
|
| 280 |
+
|
| 281 |
+
|
| 282 |
def inpaint(image, invert):
|
| 283 |
# color = HWC3(image["image"])
|
| 284 |
color = HWC3(image["background"])
|
|
|
|
| 326 |
resolution = gr.Slider(label="Auflösung", minimum=256, maximum=1024, value=512, step=64)
|
| 327 |
run_btn_lineart = gr.Button("Run")
|
| 328 |
invert.change(lambda x: {"info": invert_toggle_info[0] if x else invert_toggle_info[1], "__type__": "update"}, inputs=invert, outputs=invert)
|
| 329 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
## TAB Canny
|
| 331 |
with gr.Tab("Canny Edge") as tab_canny:
|
| 332 |
with gr.Row():
|
|
|
|
| 337 |
high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
|
| 338 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 339 |
|
| 340 |
+
def set_inputs(tab_name):
|
| 341 |
+
global input_options
|
| 342 |
+
if tab_name == "Lineart":
|
| 343 |
+
input_options = [preprocessor_name, invert]
|
| 344 |
+
return {"preprocessor_name": preprocessor_name, "invert": invert, "resolution": resolution}
|
| 345 |
|
| 346 |
run_btn_lineart = gr.Button("Run", visible=False)
|
| 347 |
run_btn_canny = gr.Button("Run", visible=False)
|
| 348 |
+
|
| 349 |
all_run_btns = [run_btn_lineart, run_btn_canny]
|
| 350 |
+
|
| 351 |
+
tab_lineart.select(
|
| 352 |
+
fn=set_inputs(
|
| 353 |
+
"lineart",
|
| 354 |
+
),
|
| 355 |
+
inputs=all_run_btns,
|
| 356 |
+
outputs=all_run_btns,
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
with gr.Column(scale=2):
|
| 360 |
gallery = gr.Gallery(label="Generated images", show_label=False, interactive=False, format="png", elem_id="output_gallery", elem_classes="output-gallery", columns=[3], rows=[2], object_fit="contain", height="auto", type="filepath")
|
| 361 |
|