File size: 26,166 Bytes
ea7f8c4
87b62f4
 
b1cc251
87b62f4
 
 
ea7f8c4
 
 
 
 
 
 
5783f33
 
d578119
5783f33
87b62f4
19dcf85
 
 
 
 
 
87b62f4
19dcf85
ea7f8c4
87b62f4
19dcf85
87b62f4
d077fcd
19dcf85
8c78e27
 
3df17a8
 
 
 
87b62f4
 
 
 
38b68da
87b62f4
 
3df17a8
 
 
 
 
87b62f4
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
30257f2
8c78e27
 
30257f2
 
 
 
 
38b68da
30257f2
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
 
19dcf85
38b68da
87b62f4
 
 
 
 
 
 
 
 
d077fcd
a2fbeba
87b62f4
8c78e27
 
bc83ad3
 
 
 
87b62f4
a2fbeba
 
 
 
 
 
38b68da
a2fbeba
38b68da
00ac23b
a2fbeba
00ac23b
bc83ad3
a2fbeba
 
 
 
38b68da
a2fbeba
38b68da
00ac23b
a2fbeba
00ac23b
bc83ad3
 
 
 
 
87b62f4
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
87b62f4
8c78e27
 
87b62f4
 
 
 
 
38b68da
87b62f4
 
 
 
8c78e27
d077fcd
b1cc251
8c78e27
 
b1cc251
38b68da
a95e279
38b68da
 
a95e279
b1cc251
38b68da
a95e279
b1cc251
 
87b62f4
38b68da
5783f33
3248690
 
 
5783f33
00ac23b
 
 
 
 
b066650
07c3671
65bb020
00ac23b
 
 
a618ce5
 
c4df34b
5a5ea72
a618ce5
 
3248690
a618ce5
 
0479306
c0e7a6b
0c832c0
0479306
91ded52
ff0d0ab
8c78e27
c4df34b
3248690
91ded52
 
c4df34b
 
a4a5d7c
91ded52
 
5a5ea72
 
 
91ded52
 
 
444af75
0c832c0
444af75
13f230e
6e0cd8e
5bb43dd
 
 
13f230e
3feebbe
e74fb8a
352f7e9
0c832c0
8c78e27
a618ce5
 
 
a4a5d7c
a618ce5
 
 
 
 
 
 
5783f33
c4df34b
54e5951
c4df34b
38b68da
00ac23b
 
436c61b
6668caf
6f89cbb
bcbf694
 
 
 
38b68da
bcbf694
 
 
 
c4df34b
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
38b68da
bcbf694
 
38b68da
bcbf694
38b68da
bcbf694
 
a2fbeba
b637c74
bcbf694
 
 
 
 
 
bc83ad3
38b68da
bcbf694
bc83ad3
bcbf694
43811cc
84ba5b3
bc83ad3
38b68da
bcbf694
 
 
 
 
 
38b68da
bcbf694
512febd
bcbf694
512febd
bcbf694
 
38b68da
bcbf694
 
 
 
 
 
 
 
 
 
38b68da
bcbf694
 
 
 
 
 
 
 
 
 
 
 
 
38b68da
bcbf694
 
 
 
 
 
 
 
 
 
 
 
 
38b68da
bcbf694
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
 
 
 
 
 
 
38b68da
bcbf694
 
 
38b68da
bcbf694
38b68da
bcbf694
 
87b62f4
00ac23b
87b62f4
38b68da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
import os, sys, time, random, shutil, json, re
import gradio as gr
import cv2
import numpy as np

from annotator.util import resize_image, HWC3

RES = os.path.join(os.path.dirname(__file__), "_res")

gr.set_static_paths(paths=["_res", "_res/assets/"])

custom_css = RES + "/_custom.css"
custom_js = RES + "/_custom.js"

custom_head = f"""
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css"/>
        <!--script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/js/all.min.js"></script-->
"""

# MARK: Gradio Theme
theme = gr.themes.Soft(
    primary_hue="emerald",
    radius_size="sm",
    neutral_hue=gr.themes.Color(c100="#a6adc8", c200="#9399b2", c300="#7f849c", c400="#6c7086", c50="#cdd6f4", c500="#585b70", c600="#45475a", c700="#313244", c800="#1e1e2e", c900="#181825", c950="#11111b"),
)

title = "ControlNet v1.1 Preprocessors Standalone"


# MARK: Funktionen

# Canny
model_canny = None


def canny(img, res, l, h, old_images=None):
    print("Old Images: ", old_images)
    result_images = []
    result = None
    img = resize_image(HWC3(img), res)
    global model_canny
    if model_canny is None:
        from annotator.canny import CannyDetector

        model_canny = CannyDetector()
    result = model_canny(img, l, h)
    result_images.append(result)

    if old_images is not None:
        result_images.extend(old_images)
    return result_images


# Hed
model_hed = None


def hed(img, res):
    img = resize_image(HWC3(img), res)
    global model_hed
    if model_hed is None:
        from annotator.hed import HEDdetector

        model_hed = HEDdetector()
    result = model_hed(img)
    return [result]


# Pidi
model_pidi = None


def pidi(img, res):
    img = resize_image(HWC3(img), res)
    global model_pidi
    if model_pidi is None:
        from annotator.pidinet import PidiNetDetector

        model_pidi = PidiNetDetector()
    result = model_pidi(img)
    return [result]


# MLSD
model_mlsd = None


def mlsd(img, res, thr_v, thr_d):
    img = resize_image(HWC3(img), res)
    global model_mlsd
    if model_mlsd is None:
        from annotator.mlsd import MLSDdetector

        model_mlsd = MLSDdetector()
    result = model_mlsd(img, thr_v, thr_d)
    return [result]


# Midas
model_midas = None


def midas(img, res):
    img = resize_image(HWC3(img), res)
    global model_midas
    if model_midas is None:
        from annotator.midas import MidasDetector

        model_midas = MidasDetector()
    result = model_midas(img)
    return [result]


# Zoe
model_zoe = None


def zoe(img, res):
    img = resize_image(HWC3(img), res)
    global model_zoe
    if model_zoe is None:
        from annotator.zoe import ZoeDetector

        model_zoe = ZoeDetector()
    result = model_zoe(img)
    return [result]


# Normal Bae
model_normalbae = None


def normalbae(img, res):
    img = resize_image(HWC3(img), res)
    global model_normalbae
    if model_normalbae is None:
        from annotator.normalbae import NormalBaeDetector

        model_normalbae = NormalBaeDetector()
    result = model_normalbae(img)
    return [result]


# DWPose
model_dwpose = None


def dwpose(img, res):
    img = resize_image(HWC3(img), res)
    global model_dwpose
    if model_dwpose is None:
        from annotator.dwpose import DWposeDetector

        model_dwpose = DWposeDetector()
    result = model_dwpose(img)
    return [result]


# OpenPose
model_openpose = None


def openpose(img, res, hand_and_face):
    img = resize_image(HWC3(img), res)
    global model_openpose
    if model_openpose is None:
        from annotator.openpose import OpenposeDetector

        model_openpose = OpenposeDetector()
    result = model_openpose(img, hand_and_face)
    return [result]


# model_uniformer = None
# def uniformer(img, res):
#    img = resize_image(HWC3(img), res)
#    global model_uniformer
#    if model_uniformer is None:
#        from annotator.uniformer import UniformerDetector
#        model_uniformer = UniformerDetector()
#    result = model_uniformer(img)
#    return [result]


# Lineart
model_lineart_anime = None
model_lineart = None


def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None):
    print("Old Images: ", old_images)
    result_images = []
    result = None
    img = resize_image(HWC3(img), res)
    ["Lineart", "Lineart Coarse", "Lineart Anime"]
    if preprocessor_name in ["Lineart", "Lineart Coarse"]:
        coarse = "Coarse" in preprocessor_name
        global model_lineart
        if model_lineart is None:
            from annotator.lineart import LineartDetector

            model_lineart = LineartDetector()
        if invert:
            result = (cv2.bitwise_not(model_lineart(img, coarse)), preprocessor_name)
        else:
            result = (model_lineart(img, coarse), preprocessor_name)
        # return [result]
    elif preprocessor_name == "Lineart Anime":
        global model_lineart_anime
        if model_lineart_anime is None:
            from annotator.lineart_anime import LineartAnimeDetector

            model_lineart_anime = LineartAnimeDetector()
        if invert:
            result = (cv2.bitwise_not(model_lineart_anime(img)), preprocessor_name)
        else:
            result = (model_lineart_anime(img), preprocessor_name)

    result_images.append(result)
    if old_images is not None:
        result_images.extend(old_images)
    return result_images


# OneFormer
model_oneformer_coco = None


def oneformer_coco(img, res):
    img = resize_image(HWC3(img), res)
    global model_oneformer_coco
    if model_oneformer_coco is None:
        from annotator.oneformer import OneformerCOCODetector

        model_oneformer_coco = OneformerCOCODetector()
    result = model_oneformer_coco(img)
    return [result]


# OneFormer ADE20k
model_oneformer_ade20k = None


def oneformer_ade20k(img, res):
    img = resize_image(HWC3(img), res)
    global model_oneformer_ade20k
    if model_oneformer_ade20k is None:
        from annotator.oneformer import OneformerADE20kDetector

        model_oneformer_ade20k = OneformerADE20kDetector()
    result = model_oneformer_ade20k(img)
    return [result]


# Content Shuffler
model_content_shuffler = None


def content_shuffler(img, res):
    img = resize_image(HWC3(img), res)
    global model_content_shuffler
    if model_content_shuffler is None:
        from annotator.shuffle import ContentShuffleDetector

        model_content_shuffler = ContentShuffleDetector()
    result = model_content_shuffler(img)
    return [result]


# Color Shuffler
model_color_shuffler = None


def color_shuffler(img, res):
    img = resize_image(HWC3(img), res)
    global model_color_shuffler
    if model_color_shuffler is None:
        from annotator.shuffle import ColorShuffleDetector

        model_color_shuffler = ColorShuffleDetector()
    result = model_color_shuffler(img)
    return [result]


# Inpaint
model_inpaint = None


def inpaint(image, invert):
    #    color = HWC3(image["image"])
    color = HWC3(image["background"])
    if invert:
        #        alpha = image["mask"][:, :, 0:1]
        alpha = image["layers"][0][:, :, 3:]
    else:
        #        alpha = 255 - image["mask"][:, :, 0:1]
        alpha = 255 - image["layers"][0][:, :, 3:]
    result = np.concatenate([color, alpha], axis=2)
    return [result]


# MARK: GRADIO UI

input_options = []

with gr.Blocks(theme=theme, css=custom_css, js=custom_js, head=custom_head, title=title) as demo:
    with gr.Row(elem_classes="row-header"):
        gr.Markdown(
            f"""
                    <h1>{title}</h1>
                    <p>Erstelle "Control Images" für Stable Diffusion und andere Tools die ControlNet verwenden.<br/>
                    Diese Demo läuft nur auf CPU, eine Inference wird daher sehr lange dauern. Du kannst diesen Space clonen und lokal auf deinem Computer verwenden.</p>
                    <p><i class="winking-hand-emoji"></i> Sebastian, gib dem Space gerne ein <i class="heart-beat-emoji"></i></p>
                    
                    """,
            elem_classes="md-header",
        )
    with gr.Tab("Preprocessors"):
        with gr.Row(elem_classes="row-main"):
            with gr.Column(scale=1, elem_id="input_column", elem_classes="input-column"):
                input_image = gr.Image(label="Dein Bild", type="numpy")

                ## TAB LINEART
                with gr.Tab("Lineart") as tab_lineart:
                    with gr.Row():
                        with gr.Column():
                            invert_toggle_info = ["Schwarzer Hintergrund, Weiße Linien", "Weißer Hintergrund, Schwarze Linien"]
                            preprocessor_name = gr.Radio(label="Preprocessor", show_label=False, choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart", elem_classes="radio-btn-group")

                            invert = gr.Checkbox(label="Farbe invertieren?", info=invert_toggle_info[0], value=True, elem_classes="toggle-btn")
                            # resolution = gr.Slider(label="Auflösung", minimum=256, maximum=1024, value=512, step=64)
                            invert.change(lambda x: {"info": invert_toggle_info[0] if x else invert_toggle_info[1], "__type__": "update"}, inputs=invert, outputs=invert)

                ## TAB Canny
                with gr.Tab("Canny Edge") as tab_canny:
                    # with gr.Row():
                    #     gr.Markdown("## Canny Edge")
                    with gr.Row():
                        with gr.Column():

                            low_threshold = gr.Slider(label="niedriger Schwellenwert", minimum=1, maximum=255, value=100, step=1)
                            high_threshold = gr.Slider(label="hoher Schwellenwert", minimum=1, maximum=255, value=200, step=1)

                with gr.Row():
                    resolution = gr.Slider(label="Auflösung (Pixel Breiet)", minimum=256, maximum=1024, value=512, step=64)
                with gr.Row():
                    run_btn_lineart = gr.Button("Los", variant="primary", visible=True)
                    run_btn_canny = gr.Button("Los", variant="primary", visible=False)

                all_run_btns = [run_btn_lineart, run_btn_canny]

                def set_inputs(tab):
                    tab = "tab_lineart" if tab is None else tab
                    # global input_options
                    lineart_btn_visible = True if tab == "tab_lineart" else False
                    canny_btn_visible = True if tab == "tab_canny" else False

                    return {"visible": lineart_btn_visible, "__type__": "update"}, {"visible": canny_btn_visible, "__type__": "update"}

                tab_lineart.select(fn=lambda: set_inputs("tab_lineart"), inputs=None, outputs=[run_btn_lineart, run_btn_canny])
                tab_canny.select(fn=lambda: set_inputs("tab_canny"), inputs=None, outputs=[run_btn_lineart, run_btn_canny])

            with gr.Column(scale=2):
                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")

    with gr.Tab("Tutorial (demnächst!)"):
        with gr.Row(elem_classes="row-main"):
            with gr.Column():
                gr.Markdown(
                    f"""
                    # Das Tutorial kommt bald.
                    """
                )

    # MARK: Button Runs
    run_btn_lineart.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert, gallery], outputs=[gallery])
    run_btn_canny.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold, gallery], outputs=[gallery])


"""
with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
    gr.Markdown(DESCRIPTION, elem_classes="top-description")
    with gr.Tab("Canny Edge", elem_id="tab_wrapper", elem_classes="tab_wrapper"):
        with gr.Row():
            gr.Markdown("## Canny Edge")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                low_threshold = gr.Slider(label="low_threshold", minimum=1, maximum=255, value=100, step=1)
                high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_btn_canny = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold], outputs=[gallery])

    with gr.Tab("HED Edge"):
        with gr.Row():
            gr.Markdown("## HED Edge&nbsp;&quot;SoftEdge&quot;")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=hed, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("Pidi Edge"):
        with gr.Row():
            gr.Markdown("## Pidi Edge&nbsp;&quot;SoftEdge&quot;")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=pidi, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("MLSD Edge"):
        with gr.Row():
            gr.Markdown("## MLSD Edge")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                value_threshold = gr.Slider(label="value_threshold", minimum=0.01, maximum=2.0, value=0.1, step=0.01)
                distance_threshold = gr.Slider(label="distance_threshold", minimum=0.01, maximum=20.0, value=0.1, step=0.01)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=mlsd, inputs=[input_image, resolution, value_threshold, distance_threshold], outputs=[gallery])

    with gr.Tab("MIDAS Depth"):
        with gr.Row():
            gr.Markdown("## MIDAS Depth")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=midas, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("ZOE Depth"):
        with gr.Row():
            gr.Markdown("## Zoe Depth")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=zoe, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("Normal Bae"):
        with gr.Row():
            gr.Markdown("## Normal Bae")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=normalbae, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("DWPose"):
        with gr.Row():
            gr.Markdown("## DWPose")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=dwpose, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("Openpose"):
        with gr.Row():
            gr.Markdown("## Openpose")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                hand_and_face = gr.Checkbox(label="Hand and Face", value=False)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])

    ## TAB LINEART
    with gr.Tab("Lineart"):
        with gr.Row():
            gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion.  Inverted image can also be created here for use with ControlNet Scribble.")
        with gr.Row():
            with gr.Column():
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                preprocessor_name = gr.Radio(label="Preprocessor", show_label=False, choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
                invert = gr.Checkbox(label="Invert", value=True)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_btn_lineart = gr.Button("Run")
            with gr.Column():
                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")

        run_btn_lineart.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert, gallery], outputs=[gallery])

    with gr.Tab("InPaint"):
        with gr.Row():
            gr.Markdown("## InPaint")
        with gr.Row():
            with gr.Column():
                input_image = gr.ImageMask(sources="upload", type="numpy", height="auto")
                invert = gr.Checkbox(label="Invert Mask", value=False)
                run_button = gr.Button("Run")

            with gr.Column():

                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=inpaint, inputs=[input_image, invert], outputs=[gallery])

    #    with gr.Row():
    #        gr.Markdown("## Uniformer Segmentation")
    #    with gr.Row():
    #        with gr.Column():
    #            input_image = gr.Image(source='upload', type="numpy")
    #            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
    #            run_button = gr.Button(label="Run")
    #        with gr.Column():
    #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    #    run_button.click(fn=uniformer, inputs=[input_image, resolution], outputs=[gallery])

    #    with gr.Row():
    #        gr.Markdown("## Oneformer COCO Segmentation")
    #    with gr.Row():
    #        with gr.Column():
    #            input_image = gr.Image(source='upload', type="numpy")
    #            input_image = gr.Image(label="Input Image", type="numpy", height=512)
    #            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
    #            run_button = gr.Button("Run")
    #            run_button = gr.Button(label="Run")
    #        with gr.Column():
    #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    #            gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
    #    run_button.click(fn=oneformer_coco, inputs=[input_image, resolution], outputs=[gallery])

    #    with gr.Row():
    #        gr.Markdown("## Oneformer ADE20K Segmentation")
    #    with gr.Row():
    #        with gr.Column():
    #            input_image = gr.Image(source='upload', type="numpy")
    #            input_image = gr.Image(label="Input Image", type="numpy", height=512)
    #            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=640, step=64)
    #            run_button = gr.Button("Run")
    #            run_button = gr.Button(label="Run")
    #        with gr.Column():
    #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    #            gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
    #    run_button.click(fn=oneformer_ade20k, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("Content Shuffle"):
        with gr.Row():
            gr.Markdown("## Content Shuffle")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
        run_button.click(fn=content_shuffler, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Tab("Color Shuffle"):
        with gr.Row():
            gr.Markdown("## Color Shuffle")
        with gr.Row():
            with gr.Column():
                #            input_image = gr.Image(source='upload', type="numpy")
                input_image = gr.Image(label="Input Image", type="numpy", height=512)
                resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
                run_button = gr.Button("Run")
            #            run_button = gr.Button(label="Run")
            with gr.Column():
                #            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
                gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")

    run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
"""

demo.launch()