Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,9 @@ import numpy as np
|
|
4 |
|
5 |
from annotator.util import resize_image, HWC3
|
6 |
|
7 |
-
DESCRIPTION =
|
8 |
-
DESCRIPTION +=
|
9 |
-
DESCRIPTION +=
|
10 |
-
|
11 |
|
12 |
|
13 |
model_canny = None
|
@@ -18,6 +17,7 @@ def canny(img, res, l, h):
|
|
18 |
global model_canny
|
19 |
if model_canny is None:
|
20 |
from annotator.canny import CannyDetector
|
|
|
21 |
model_canny = CannyDetector()
|
22 |
result = model_canny(img, l, h)
|
23 |
return [result]
|
@@ -31,6 +31,7 @@ def hed(img, res):
|
|
31 |
global model_hed
|
32 |
if model_hed is None:
|
33 |
from annotator.hed import HEDdetector
|
|
|
34 |
model_hed = HEDdetector()
|
35 |
result = model_hed(img)
|
36 |
return [result]
|
@@ -44,6 +45,7 @@ def pidi(img, res):
|
|
44 |
global model_pidi
|
45 |
if model_pidi is None:
|
46 |
from annotator.pidinet import PidiNetDetector
|
|
|
47 |
model_pidi = PidiNetDetector()
|
48 |
result = model_pidi(img)
|
49 |
return [result]
|
@@ -57,6 +59,7 @@ def mlsd(img, res, thr_v, thr_d):
|
|
57 |
global model_mlsd
|
58 |
if model_mlsd is None:
|
59 |
from annotator.mlsd import MLSDdetector
|
|
|
60 |
model_mlsd = MLSDdetector()
|
61 |
result = model_mlsd(img, thr_v, thr_d)
|
62 |
return [result]
|
@@ -70,6 +73,7 @@ def midas(img, res):
|
|
70 |
global model_midas
|
71 |
if model_midas is None:
|
72 |
from annotator.midas import MidasDetector
|
|
|
73 |
model_midas = MidasDetector()
|
74 |
result = model_midas(img)
|
75 |
return [result]
|
@@ -83,6 +87,7 @@ def zoe(img, res):
|
|
83 |
global model_zoe
|
84 |
if model_zoe is None:
|
85 |
from annotator.zoe import ZoeDetector
|
|
|
86 |
model_zoe = ZoeDetector()
|
87 |
result = model_zoe(img)
|
88 |
return [result]
|
@@ -96,6 +101,7 @@ def normalbae(img, res):
|
|
96 |
global model_normalbae
|
97 |
if model_normalbae is None:
|
98 |
from annotator.normalbae import NormalBaeDetector
|
|
|
99 |
model_normalbae = NormalBaeDetector()
|
100 |
result = model_normalbae(img)
|
101 |
return [result]
|
@@ -103,11 +109,13 @@ def normalbae(img, res):
|
|
103 |
|
104 |
model_dwpose = None
|
105 |
|
|
|
106 |
def dwpose(img, res):
|
107 |
img = resize_image(HWC3(img), res)
|
108 |
global model_dwpose
|
109 |
if model_dwpose is None:
|
110 |
from annotator.dwpose import DWposeDetector
|
|
|
111 |
model_dwpose = DWposeDetector()
|
112 |
result = model_dwpose(img)
|
113 |
return [result]
|
@@ -121,6 +129,7 @@ def openpose(img, res, hand_and_face):
|
|
121 |
global model_openpose
|
122 |
if model_openpose is None:
|
123 |
from annotator.openpose import OpenposeDetector
|
|
|
124 |
model_openpose = OpenposeDetector()
|
125 |
result = model_openpose(img, hand_and_face)
|
126 |
return [result]
|
@@ -129,7 +138,7 @@ def openpose(img, res, hand_and_face):
|
|
129 |
model_uniformer = None
|
130 |
|
131 |
|
132 |
-
#def uniformer(img, res):
|
133 |
# img = resize_image(HWC3(img), res)
|
134 |
# global model_uniformer
|
135 |
# if model_uniformer is None:
|
@@ -144,6 +153,7 @@ model_uniformer = None
|
|
144 |
model_lineart_anime = None
|
145 |
model_lineart = None
|
146 |
|
|
|
147 |
def lineart(img, res, preprocessor_name="Lineart", invert=True):
|
148 |
img = resize_image(HWC3(img), res)
|
149 |
["Lineart", "Lineart Coarse", "Lineart Anime"]
|
@@ -152,25 +162,28 @@ def lineart(img, res, preprocessor_name="Lineart", invert=True):
|
|
152 |
global model_lineart
|
153 |
if model_lineart is None:
|
154 |
from annotator.lineart import LineartDetector
|
|
|
155 |
model_lineart = LineartDetector()
|
156 |
-
|
157 |
-
if
|
158 |
result = cv2.bitwise_not(model_lineart(img, coarse))
|
159 |
else:
|
160 |
-
result = model_lineart(img, coarse)
|
161 |
return [result]
|
162 |
elif preprocessor_name == "Lineart Anime":
|
163 |
global model_lineart_anime
|
164 |
if model_lineart_anime is None:
|
165 |
from annotator.lineart_anime import LineartAnimeDetector
|
|
|
166 |
model_lineart_anime = LineartAnimeDetector()
|
167 |
-
|
168 |
-
if
|
169 |
result = cv2.bitwise_not(model_lineart_anime(img))
|
170 |
else:
|
171 |
result = model_lineart_anime(img)
|
172 |
return [result]
|
173 |
|
|
|
174 |
model_oneformer_coco = None
|
175 |
|
176 |
|
@@ -179,6 +192,7 @@ def oneformer_coco(img, res):
|
|
179 |
global model_oneformer_coco
|
180 |
if model_oneformer_coco is None:
|
181 |
from annotator.oneformer import OneformerCOCODetector
|
|
|
182 |
model_oneformer_coco = OneformerCOCODetector()
|
183 |
result = model_oneformer_coco(img)
|
184 |
return [result]
|
@@ -192,6 +206,7 @@ def oneformer_ade20k(img, res):
|
|
192 |
global model_oneformer_ade20k
|
193 |
if model_oneformer_ade20k is None:
|
194 |
from annotator.oneformer import OneformerADE20kDetector
|
|
|
195 |
model_oneformer_ade20k = OneformerADE20kDetector()
|
196 |
result = model_oneformer_ade20k(img)
|
197 |
return [result]
|
@@ -205,6 +220,7 @@ def content_shuffler(img, res):
|
|
205 |
global model_content_shuffler
|
206 |
if model_content_shuffler is None:
|
207 |
from annotator.shuffle import ContentShuffleDetector
|
|
|
208 |
model_content_shuffler = ContentShuffleDetector()
|
209 |
result = model_content_shuffler(img)
|
210 |
return [result]
|
@@ -218,171 +234,192 @@ def color_shuffler(img, res):
|
|
218 |
global model_color_shuffler
|
219 |
if model_color_shuffler is None:
|
220 |
from annotator.shuffle import ColorShuffleDetector
|
|
|
221 |
model_color_shuffler = ColorShuffleDetector()
|
222 |
result = model_color_shuffler(img)
|
223 |
return [result]
|
224 |
|
|
|
225 |
model_inpaint = None
|
226 |
|
227 |
|
228 |
def inpaint(image, invert):
|
229 |
-
# color = HWC3(image["image"])
|
230 |
color = HWC3(image["background"])
|
231 |
-
if
|
232 |
-
# alpha = image["mask"][:, :, 0:1]
|
233 |
alpha = image["layers"][0][:, :, 3:]
|
234 |
else:
|
235 |
-
# alpha = 255 - image["mask"][:, :, 0:1]
|
236 |
alpha = 255 - image["layers"][0][:, :, 3:]
|
237 |
result = np.concatenate([color, alpha], axis=2)
|
238 |
return [result]
|
239 |
|
|
|
240 |
theme = gr.themes.Soft(
|
241 |
primary_hue="emerald",
|
242 |
-
# neutral_hue=gr.themes.Color(c100="#fce7f3", c200="#fbcfe8", c300="#f9a8d4", c400="#f472b6", c50="#fdf2f8", c500="#9b3b6b", c600="#7f2f53", c700="#641b3a", c800="#5d1431", c900="#361120", c950="#2b0d19"),
|
243 |
radius_size="sm",
|
244 |
)
|
245 |
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
gr.Markdown(DESCRIPTION)
|
248 |
with gr.Tab("Canny Edge"):
|
249 |
with gr.Row():
|
250 |
gr.Markdown("## Canny Edge")
|
251 |
with gr.Row():
|
252 |
with gr.Column():
|
253 |
-
|
254 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
255 |
low_threshold = gr.Slider(label="low_threshold", minimum=1, maximum=255, value=100, step=1)
|
256 |
high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
|
257 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
258 |
run_button = gr.Button("Run")
|
259 |
-
|
260 |
with gr.Column():
|
261 |
-
|
262 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
263 |
run_button.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold], outputs=[gallery])
|
264 |
-
|
265 |
with gr.Tab("HED Edge"):
|
266 |
with gr.Row():
|
267 |
gr.Markdown("## HED Edge "SoftEdge"")
|
268 |
with gr.Row():
|
269 |
with gr.Column():
|
270 |
-
|
271 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
272 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
273 |
run_button = gr.Button("Run")
|
274 |
-
|
275 |
with gr.Column():
|
276 |
-
|
277 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
278 |
run_button.click(fn=hed, inputs=[input_image, resolution], outputs=[gallery])
|
279 |
-
|
280 |
with gr.Tab("Pidi Edge"):
|
281 |
with gr.Row():
|
282 |
gr.Markdown("## Pidi Edge "SoftEdge"")
|
283 |
with gr.Row():
|
284 |
with gr.Column():
|
285 |
-
|
286 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
287 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
288 |
run_button = gr.Button("Run")
|
289 |
-
|
290 |
with gr.Column():
|
291 |
-
|
292 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
293 |
run_button.click(fn=pidi, inputs=[input_image, resolution], outputs=[gallery])
|
294 |
-
|
295 |
with gr.Tab("MLSD Edge"):
|
296 |
with gr.Row():
|
297 |
gr.Markdown("## MLSD Edge")
|
298 |
with gr.Row():
|
299 |
with gr.Column():
|
300 |
-
|
301 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
302 |
value_threshold = gr.Slider(label="value_threshold", minimum=0.01, maximum=2.0, value=0.1, step=0.01)
|
303 |
distance_threshold = gr.Slider(label="distance_threshold", minimum=0.01, maximum=20.0, value=0.1, step=0.01)
|
304 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
305 |
run_button = gr.Button("Run")
|
306 |
-
|
307 |
with gr.Column():
|
308 |
-
|
309 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
310 |
run_button.click(fn=mlsd, inputs=[input_image, resolution, value_threshold, distance_threshold], outputs=[gallery])
|
311 |
-
|
312 |
with gr.Tab("MIDAS Depth"):
|
313 |
with gr.Row():
|
314 |
gr.Markdown("## MIDAS Depth")
|
315 |
with gr.Row():
|
316 |
with gr.Column():
|
317 |
-
|
318 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
319 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
320 |
run_button = gr.Button("Run")
|
321 |
-
|
322 |
with gr.Column():
|
323 |
-
|
324 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
325 |
run_button.click(fn=midas, inputs=[input_image, resolution], outputs=[gallery])
|
326 |
-
|
327 |
-
|
328 |
with gr.Tab("ZOE Depth"):
|
329 |
with gr.Row():
|
330 |
gr.Markdown("## Zoe Depth")
|
331 |
with gr.Row():
|
332 |
with gr.Column():
|
333 |
-
|
334 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
335 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
336 |
run_button = gr.Button("Run")
|
337 |
-
|
338 |
with gr.Column():
|
339 |
-
|
340 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
341 |
run_button.click(fn=zoe, inputs=[input_image, resolution], outputs=[gallery])
|
342 |
-
|
343 |
with gr.Tab("Normal Bae"):
|
344 |
with gr.Row():
|
345 |
gr.Markdown("## Normal Bae")
|
346 |
with gr.Row():
|
347 |
with gr.Column():
|
348 |
-
|
349 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
350 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
351 |
run_button = gr.Button("Run")
|
352 |
-
|
353 |
with gr.Column():
|
354 |
-
|
355 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
356 |
run_button.click(fn=normalbae, inputs=[input_image, resolution], outputs=[gallery])
|
357 |
-
|
358 |
with gr.Tab("DWPose"):
|
359 |
with gr.Row():
|
360 |
gr.Markdown("## DWPose")
|
361 |
with gr.Row():
|
362 |
with gr.Column():
|
363 |
-
|
364 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
365 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
366 |
run_button = gr.Button("Run")
|
367 |
-
|
368 |
with gr.Column():
|
369 |
-
|
370 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
371 |
run_button.click(fn=dwpose, inputs=[input_image, resolution], outputs=[gallery])
|
372 |
-
|
373 |
with gr.Tab("Openpose"):
|
374 |
with gr.Row():
|
375 |
gr.Markdown("## Openpose")
|
376 |
with gr.Row():
|
377 |
with gr.Column():
|
378 |
-
|
379 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
380 |
-
hand_and_face = gr.Checkbox(label=
|
381 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
382 |
run_button = gr.Button("Run")
|
383 |
-
|
384 |
with gr.Column():
|
385 |
-
|
386 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
387 |
run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])
|
388 |
|
@@ -394,30 +431,30 @@ with gr.Blocks(theme=theme) as demo:
|
|
394 |
with gr.Column():
|
395 |
preprocessor_name = gr.Radio(label="Preprocessor", choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
|
396 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
397 |
-
invert = gr.Checkbox(label=
|
398 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
399 |
-
run_button = gr.Button("
|
400 |
-
|
401 |
with gr.Column():
|
402 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
|
|
403 |
run_button.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert], outputs=[gallery])
|
404 |
-
|
405 |
-
|
406 |
with gr.Tab("InPaint"):
|
407 |
with gr.Row():
|
408 |
gr.Markdown("## InPaint")
|
409 |
with gr.Row():
|
410 |
with gr.Column():
|
411 |
-
|
412 |
input_image = gr.ImageMask(sources="upload", type="numpy", height="auto")
|
413 |
-
invert = gr.Checkbox(label=
|
414 |
run_button = gr.Button("Run")
|
415 |
-
|
416 |
with gr.Column():
|
417 |
-
|
418 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
419 |
run_button.click(fn=inpaint, inputs=[input_image, invert], outputs=[gallery])
|
420 |
-
|
421 |
# with gr.Row():
|
422 |
# gr.Markdown("## Uniformer Segmentation")
|
423 |
# with gr.Row():
|
@@ -428,8 +465,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
428 |
# with gr.Column():
|
429 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
430 |
# run_button.click(fn=uniformer, inputs=[input_image, resolution], outputs=[gallery])
|
431 |
-
|
432 |
-
|
433 |
# with gr.Row():
|
434 |
# gr.Markdown("## Oneformer COCO Segmentation")
|
435 |
# with gr.Row():
|
@@ -443,8 +479,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
443 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
444 |
# gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
445 |
# run_button.click(fn=oneformer_coco, inputs=[input_image, resolution], outputs=[gallery])
|
446 |
-
|
447 |
-
|
448 |
# with gr.Row():
|
449 |
# gr.Markdown("## Oneformer ADE20K Segmentation")
|
450 |
# with gr.Row():
|
@@ -458,19 +493,19 @@ with gr.Blocks(theme=theme) as demo:
|
|
458 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
459 |
# gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
460 |
# run_button.click(fn=oneformer_ade20k, inputs=[input_image, resolution], outputs=[gallery])
|
461 |
-
|
462 |
with gr.Tab("Content Shuffle"):
|
463 |
with gr.Row():
|
464 |
gr.Markdown("## Content Shuffle")
|
465 |
with gr.Row():
|
466 |
with gr.Column():
|
467 |
-
|
468 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
469 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
470 |
run_button = gr.Button("Run")
|
471 |
-
|
472 |
with gr.Column():
|
473 |
-
|
474 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
475 |
run_button.click(fn=content_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
476 |
|
@@ -479,17 +514,16 @@ with gr.Blocks(theme=theme) as demo:
|
|
479 |
gr.Markdown("## Color Shuffle")
|
480 |
with gr.Row():
|
481 |
with gr.Column():
|
482 |
-
|
483 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
484 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
485 |
run_button = gr.Button("Run")
|
486 |
-
|
487 |
with gr.Column():
|
488 |
-
|
489 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
490 |
|
491 |
-
|
492 |
run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
493 |
|
494 |
|
495 |
-
demo.launch()
|
|
|
4 |
|
5 |
from annotator.util import resize_image, HWC3
|
6 |
|
7 |
+
DESCRIPTION = "# "
|
8 |
+
DESCRIPTION += "# ControlNet v1.1 Preprocessors Standalone"
|
9 |
+
DESCRIPTION += "\n<p>Generate Control Images for Stable Diffusion and other apps that uses ControlNet.</p>"
|
|
|
10 |
|
11 |
|
12 |
model_canny = None
|
|
|
17 |
global model_canny
|
18 |
if model_canny is None:
|
19 |
from annotator.canny import CannyDetector
|
20 |
+
|
21 |
model_canny = CannyDetector()
|
22 |
result = model_canny(img, l, h)
|
23 |
return [result]
|
|
|
31 |
global model_hed
|
32 |
if model_hed is None:
|
33 |
from annotator.hed import HEDdetector
|
34 |
+
|
35 |
model_hed = HEDdetector()
|
36 |
result = model_hed(img)
|
37 |
return [result]
|
|
|
45 |
global model_pidi
|
46 |
if model_pidi is None:
|
47 |
from annotator.pidinet import PidiNetDetector
|
48 |
+
|
49 |
model_pidi = PidiNetDetector()
|
50 |
result = model_pidi(img)
|
51 |
return [result]
|
|
|
59 |
global model_mlsd
|
60 |
if model_mlsd is None:
|
61 |
from annotator.mlsd import MLSDdetector
|
62 |
+
|
63 |
model_mlsd = MLSDdetector()
|
64 |
result = model_mlsd(img, thr_v, thr_d)
|
65 |
return [result]
|
|
|
73 |
global model_midas
|
74 |
if model_midas is None:
|
75 |
from annotator.midas import MidasDetector
|
76 |
+
|
77 |
model_midas = MidasDetector()
|
78 |
result = model_midas(img)
|
79 |
return [result]
|
|
|
87 |
global model_zoe
|
88 |
if model_zoe is None:
|
89 |
from annotator.zoe import ZoeDetector
|
90 |
+
|
91 |
model_zoe = ZoeDetector()
|
92 |
result = model_zoe(img)
|
93 |
return [result]
|
|
|
101 |
global model_normalbae
|
102 |
if model_normalbae is None:
|
103 |
from annotator.normalbae import NormalBaeDetector
|
104 |
+
|
105 |
model_normalbae = NormalBaeDetector()
|
106 |
result = model_normalbae(img)
|
107 |
return [result]
|
|
|
109 |
|
110 |
model_dwpose = None
|
111 |
|
112 |
+
|
113 |
def dwpose(img, res):
|
114 |
img = resize_image(HWC3(img), res)
|
115 |
global model_dwpose
|
116 |
if model_dwpose is None:
|
117 |
from annotator.dwpose import DWposeDetector
|
118 |
+
|
119 |
model_dwpose = DWposeDetector()
|
120 |
result = model_dwpose(img)
|
121 |
return [result]
|
|
|
129 |
global model_openpose
|
130 |
if model_openpose is None:
|
131 |
from annotator.openpose import OpenposeDetector
|
132 |
+
|
133 |
model_openpose = OpenposeDetector()
|
134 |
result = model_openpose(img, hand_and_face)
|
135 |
return [result]
|
|
|
138 |
model_uniformer = None
|
139 |
|
140 |
|
141 |
+
# def uniformer(img, res):
|
142 |
# img = resize_image(HWC3(img), res)
|
143 |
# global model_uniformer
|
144 |
# if model_uniformer is None:
|
|
|
153 |
model_lineart_anime = None
|
154 |
model_lineart = None
|
155 |
|
156 |
+
|
157 |
def lineart(img, res, preprocessor_name="Lineart", invert=True):
|
158 |
img = resize_image(HWC3(img), res)
|
159 |
["Lineart", "Lineart Coarse", "Lineart Anime"]
|
|
|
162 |
global model_lineart
|
163 |
if model_lineart is None:
|
164 |
from annotator.lineart import LineartDetector
|
165 |
+
|
166 |
model_lineart = LineartDetector()
|
167 |
+
# result = model_lineart(img, coarse)
|
168 |
+
if invert:
|
169 |
result = cv2.bitwise_not(model_lineart(img, coarse))
|
170 |
else:
|
171 |
+
result = model_lineart(img, coarse)
|
172 |
return [result]
|
173 |
elif preprocessor_name == "Lineart Anime":
|
174 |
global model_lineart_anime
|
175 |
if model_lineart_anime is None:
|
176 |
from annotator.lineart_anime import LineartAnimeDetector
|
177 |
+
|
178 |
model_lineart_anime = LineartAnimeDetector()
|
179 |
+
# result = model_lineart_anime(img)
|
180 |
+
if invert:
|
181 |
result = cv2.bitwise_not(model_lineart_anime(img))
|
182 |
else:
|
183 |
result = model_lineart_anime(img)
|
184 |
return [result]
|
185 |
|
186 |
+
|
187 |
model_oneformer_coco = None
|
188 |
|
189 |
|
|
|
192 |
global model_oneformer_coco
|
193 |
if model_oneformer_coco is None:
|
194 |
from annotator.oneformer import OneformerCOCODetector
|
195 |
+
|
196 |
model_oneformer_coco = OneformerCOCODetector()
|
197 |
result = model_oneformer_coco(img)
|
198 |
return [result]
|
|
|
206 |
global model_oneformer_ade20k
|
207 |
if model_oneformer_ade20k is None:
|
208 |
from annotator.oneformer import OneformerADE20kDetector
|
209 |
+
|
210 |
model_oneformer_ade20k = OneformerADE20kDetector()
|
211 |
result = model_oneformer_ade20k(img)
|
212 |
return [result]
|
|
|
220 |
global model_content_shuffler
|
221 |
if model_content_shuffler is None:
|
222 |
from annotator.shuffle import ContentShuffleDetector
|
223 |
+
|
224 |
model_content_shuffler = ContentShuffleDetector()
|
225 |
result = model_content_shuffler(img)
|
226 |
return [result]
|
|
|
234 |
global model_color_shuffler
|
235 |
if model_color_shuffler is None:
|
236 |
from annotator.shuffle import ColorShuffleDetector
|
237 |
+
|
238 |
model_color_shuffler = ColorShuffleDetector()
|
239 |
result = model_color_shuffler(img)
|
240 |
return [result]
|
241 |
|
242 |
+
|
243 |
model_inpaint = None
|
244 |
|
245 |
|
246 |
def inpaint(image, invert):
|
247 |
+
# color = HWC3(image["image"])
|
248 |
color = HWC3(image["background"])
|
249 |
+
if invert:
|
250 |
+
# alpha = image["mask"][:, :, 0:1]
|
251 |
alpha = image["layers"][0][:, :, 3:]
|
252 |
else:
|
253 |
+
# alpha = 255 - image["mask"][:, :, 0:1]
|
254 |
alpha = 255 - image["layers"][0][:, :, 3:]
|
255 |
result = np.concatenate([color, alpha], axis=2)
|
256 |
return [result]
|
257 |
|
258 |
+
|
259 |
theme = gr.themes.Soft(
|
260 |
primary_hue="emerald",
|
261 |
+
# neutral_hue=gr.themes.Color(c100="#fce7f3", c200="#fbcfe8", c300="#f9a8d4", c400="#f472b6", c50="#fdf2f8", c500="#9b3b6b", c600="#7f2f53", c700="#641b3a", c800="#5d1431", c900="#361120", c950="#2b0d19"),
|
262 |
radius_size="sm",
|
263 |
)
|
264 |
|
265 |
+
css = """
|
266 |
+
div.tabs > div.tab-nav > button.selected {
|
267 |
+
border-width: 0 !important;
|
268 |
+
background: var(--primary-600) !important;
|
269 |
+
color: var(--body-text-color);
|
270 |
+
}
|
271 |
+
|
272 |
+
div.tabs > div.tab-nav {
|
273 |
+
border-bottom: 8px solid var(--primary-600) !important;
|
274 |
+
}
|
275 |
+
|
276 |
+
div.tabs div.tabitem {
|
277 |
+
display: flex;
|
278 |
+
position: relative;
|
279 |
+
border: none !important;
|
280 |
+
background-color: var(--neutral-900) !important;
|
281 |
+
}
|
282 |
+
"""
|
283 |
+
|
284 |
+
with gr.Blocks(theme=theme, css=css) as demo:
|
285 |
gr.Markdown(DESCRIPTION)
|
286 |
with gr.Tab("Canny Edge"):
|
287 |
with gr.Row():
|
288 |
gr.Markdown("## Canny Edge")
|
289 |
with gr.Row():
|
290 |
with gr.Column():
|
291 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
292 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
293 |
low_threshold = gr.Slider(label="low_threshold", minimum=1, maximum=255, value=100, step=1)
|
294 |
high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
|
295 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
296 |
run_button = gr.Button("Run")
|
297 |
+
# run_button = gr.Button(label="Run")
|
298 |
with gr.Column():
|
299 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
300 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
301 |
run_button.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold], outputs=[gallery])
|
302 |
+
|
303 |
with gr.Tab("HED Edge"):
|
304 |
with gr.Row():
|
305 |
gr.Markdown("## HED Edge "SoftEdge"")
|
306 |
with gr.Row():
|
307 |
with gr.Column():
|
308 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
309 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
310 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
311 |
run_button = gr.Button("Run")
|
312 |
+
# run_button = gr.Button(label="Run")
|
313 |
with gr.Column():
|
314 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
315 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
316 |
run_button.click(fn=hed, inputs=[input_image, resolution], outputs=[gallery])
|
317 |
+
|
318 |
with gr.Tab("Pidi Edge"):
|
319 |
with gr.Row():
|
320 |
gr.Markdown("## Pidi Edge "SoftEdge"")
|
321 |
with gr.Row():
|
322 |
with gr.Column():
|
323 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
324 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
325 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
326 |
run_button = gr.Button("Run")
|
327 |
+
# run_button = gr.Button(label="Run")
|
328 |
with gr.Column():
|
329 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
330 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
331 |
run_button.click(fn=pidi, inputs=[input_image, resolution], outputs=[gallery])
|
332 |
+
|
333 |
with gr.Tab("MLSD Edge"):
|
334 |
with gr.Row():
|
335 |
gr.Markdown("## MLSD Edge")
|
336 |
with gr.Row():
|
337 |
with gr.Column():
|
338 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
339 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
340 |
value_threshold = gr.Slider(label="value_threshold", minimum=0.01, maximum=2.0, value=0.1, step=0.01)
|
341 |
distance_threshold = gr.Slider(label="distance_threshold", minimum=0.01, maximum=20.0, value=0.1, step=0.01)
|
342 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
343 |
run_button = gr.Button("Run")
|
344 |
+
# run_button = gr.Button(label="Run")
|
345 |
with gr.Column():
|
346 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
347 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
348 |
run_button.click(fn=mlsd, inputs=[input_image, resolution, value_threshold, distance_threshold], outputs=[gallery])
|
349 |
+
|
350 |
with gr.Tab("MIDAS Depth"):
|
351 |
with gr.Row():
|
352 |
gr.Markdown("## MIDAS Depth")
|
353 |
with gr.Row():
|
354 |
with gr.Column():
|
355 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
356 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
357 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
358 |
run_button = gr.Button("Run")
|
359 |
+
# run_button = gr.Button(label="Run")
|
360 |
with gr.Column():
|
361 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
362 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
363 |
run_button.click(fn=midas, inputs=[input_image, resolution], outputs=[gallery])
|
364 |
+
|
|
|
365 |
with gr.Tab("ZOE Depth"):
|
366 |
with gr.Row():
|
367 |
gr.Markdown("## Zoe Depth")
|
368 |
with gr.Row():
|
369 |
with gr.Column():
|
370 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
371 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
372 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
373 |
run_button = gr.Button("Run")
|
374 |
+
# run_button = gr.Button(label="Run")
|
375 |
with gr.Column():
|
376 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
377 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
378 |
run_button.click(fn=zoe, inputs=[input_image, resolution], outputs=[gallery])
|
379 |
+
|
380 |
with gr.Tab("Normal Bae"):
|
381 |
with gr.Row():
|
382 |
gr.Markdown("## Normal Bae")
|
383 |
with gr.Row():
|
384 |
with gr.Column():
|
385 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
386 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
387 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
388 |
run_button = gr.Button("Run")
|
389 |
+
# run_button = gr.Button(label="Run")
|
390 |
with gr.Column():
|
391 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
392 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
393 |
run_button.click(fn=normalbae, inputs=[input_image, resolution], outputs=[gallery])
|
394 |
+
|
395 |
with gr.Tab("DWPose"):
|
396 |
with gr.Row():
|
397 |
gr.Markdown("## DWPose")
|
398 |
with gr.Row():
|
399 |
with gr.Column():
|
400 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
401 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
402 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
403 |
run_button = gr.Button("Run")
|
404 |
+
# run_button = gr.Button(label="Run")
|
405 |
with gr.Column():
|
406 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
407 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
408 |
run_button.click(fn=dwpose, inputs=[input_image, resolution], outputs=[gallery])
|
409 |
+
|
410 |
with gr.Tab("Openpose"):
|
411 |
with gr.Row():
|
412 |
gr.Markdown("## Openpose")
|
413 |
with gr.Row():
|
414 |
with gr.Column():
|
415 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
416 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
417 |
+
hand_and_face = gr.Checkbox(label="Hand and Face", value=False)
|
418 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
419 |
run_button = gr.Button("Run")
|
420 |
+
# run_button = gr.Button(label="Run")
|
421 |
with gr.Column():
|
422 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
423 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
424 |
run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])
|
425 |
|
|
|
431 |
with gr.Column():
|
432 |
preprocessor_name = gr.Radio(label="Preprocessor", choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
|
433 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
434 |
+
invert = gr.Checkbox(label="Invert", value=True)
|
435 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
436 |
+
run_button = gr.Button("Lineart")
|
437 |
+
# run_button = gr.Button(label="Run")
|
438 |
with gr.Column():
|
439 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
440 |
+
preprocessor_name.insert = lambda: run_button.set_value(preprocessor_name.value)
|
441 |
run_button.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert], outputs=[gallery])
|
442 |
+
|
|
|
443 |
with gr.Tab("InPaint"):
|
444 |
with gr.Row():
|
445 |
gr.Markdown("## InPaint")
|
446 |
with gr.Row():
|
447 |
with gr.Column():
|
448 |
+
# input_image = gr.Image(source='upload', type="numpy", tool="sketch", height=512)
|
449 |
input_image = gr.ImageMask(sources="upload", type="numpy", height="auto")
|
450 |
+
invert = gr.Checkbox(label="Invert Mask", value=False)
|
451 |
run_button = gr.Button("Run")
|
452 |
+
# run_button = gr.Button(label="Run")
|
453 |
with gr.Column():
|
454 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
455 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
456 |
run_button.click(fn=inpaint, inputs=[input_image, invert], outputs=[gallery])
|
457 |
+
|
458 |
# with gr.Row():
|
459 |
# gr.Markdown("## Uniformer Segmentation")
|
460 |
# with gr.Row():
|
|
|
465 |
# with gr.Column():
|
466 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
467 |
# run_button.click(fn=uniformer, inputs=[input_image, resolution], outputs=[gallery])
|
468 |
+
|
|
|
469 |
# with gr.Row():
|
470 |
# gr.Markdown("## Oneformer COCO Segmentation")
|
471 |
# with gr.Row():
|
|
|
479 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
480 |
# gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
481 |
# run_button.click(fn=oneformer_coco, inputs=[input_image, resolution], outputs=[gallery])
|
482 |
+
|
|
|
483 |
# with gr.Row():
|
484 |
# gr.Markdown("## Oneformer ADE20K Segmentation")
|
485 |
# with gr.Row():
|
|
|
493 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
494 |
# gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
495 |
# run_button.click(fn=oneformer_ade20k, inputs=[input_image, resolution], outputs=[gallery])
|
496 |
+
|
497 |
with gr.Tab("Content Shuffle"):
|
498 |
with gr.Row():
|
499 |
gr.Markdown("## Content Shuffle")
|
500 |
with gr.Row():
|
501 |
with gr.Column():
|
502 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
503 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
504 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
505 |
run_button = gr.Button("Run")
|
506 |
+
# run_button = gr.Button(label="Run")
|
507 |
with gr.Column():
|
508 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
509 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
510 |
run_button.click(fn=content_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
511 |
|
|
|
514 |
gr.Markdown("## Color Shuffle")
|
515 |
with gr.Row():
|
516 |
with gr.Column():
|
517 |
+
# input_image = gr.Image(source='upload', type="numpy")
|
518 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
519 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
520 |
run_button = gr.Button("Run")
|
521 |
+
# run_button = gr.Button(label="Run")
|
522 |
with gr.Column():
|
523 |
+
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
524 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
525 |
|
|
|
526 |
run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
527 |
|
528 |
|
529 |
+
demo.launch()
|