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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import basicsr_shim # noqa: F401 basicsr の代替シム(torchvision互換問題を回避)
|
| 2 |
+
import patch_annotators # noqa: F401 各アノテーターの互換性パッチ
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import cv2
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
from annotator.util import resize_image, HWC3
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
DESCRIPTION = '# ControlNet v1.1 Annotators (that runs on cpu only)'
|
| 11 |
+
DESCRIPTION += '\n<p>This app generates Control Image for Mochi Diffusion's ControlNet.</p>'
|
| 12 |
+
DESCRIPTION += '\n<p>HEIC image is not converted. Please use PNG or JPG image.</p>'
|
| 13 |
+
DESCRIPTION += '\n<p>Gradioのバージョンが上がって変換された画像がWebpになっています。最新のMochiDiffusionでは問題なく使えるようです。</p>'
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
model_canny = None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def canny(img, res, l, h):
|
| 20 |
+
img = resize_image(HWC3(img), res)
|
| 21 |
+
global model_canny
|
| 22 |
+
if model_canny is None:
|
| 23 |
+
from annotator.canny import CannyDetector
|
| 24 |
+
model_canny = CannyDetector()
|
| 25 |
+
result = model_canny(img, l, h)
|
| 26 |
+
return [result]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
model_hed = None
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def hed(img, res):
|
| 33 |
+
img = resize_image(HWC3(img), res)
|
| 34 |
+
global model_hed
|
| 35 |
+
if model_hed is None:
|
| 36 |
+
from annotator.hed import HEDdetector
|
| 37 |
+
model_hed = HEDdetector()
|
| 38 |
+
result = model_hed(img)
|
| 39 |
+
return [result]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
model_pidi = None
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def pidi(img, res):
|
| 46 |
+
img = resize_image(HWC3(img), res)
|
| 47 |
+
global model_pidi
|
| 48 |
+
if model_pidi is None:
|
| 49 |
+
from annotator.pidinet import PidiNetDetector
|
| 50 |
+
model_pidi = PidiNetDetector()
|
| 51 |
+
result = model_pidi(img)
|
| 52 |
+
return [result]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
model_mlsd = None
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def mlsd(img, res, thr_v, thr_d):
|
| 59 |
+
img = resize_image(HWC3(img), res)
|
| 60 |
+
global model_mlsd
|
| 61 |
+
if model_mlsd is None:
|
| 62 |
+
from annotator.mlsd import MLSDdetector
|
| 63 |
+
model_mlsd = MLSDdetector()
|
| 64 |
+
result = model_mlsd(img, thr_v, thr_d)
|
| 65 |
+
return [result]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
model_midas = None
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def midas(img, res):
|
| 72 |
+
img = resize_image(HWC3(img), res)
|
| 73 |
+
global model_midas
|
| 74 |
+
if model_midas is None:
|
| 75 |
+
from annotator.midas import MidasDetector
|
| 76 |
+
model_midas = MidasDetector()
|
| 77 |
+
result = model_midas(img)
|
| 78 |
+
return [result]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
model_zoe = None
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def zoe(img, res):
|
| 85 |
+
img = resize_image(HWC3(img), res)
|
| 86 |
+
global model_zoe
|
| 87 |
+
if model_zoe is None:
|
| 88 |
+
from annotator.zoe import ZoeDetector
|
| 89 |
+
model_zoe = ZoeDetector()
|
| 90 |
+
result = model_zoe(img)
|
| 91 |
+
return [result]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
model_normalbae = None
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def normalbae(img, res):
|
| 98 |
+
img = resize_image(HWC3(img), res)
|
| 99 |
+
global model_normalbae
|
| 100 |
+
if model_normalbae is None:
|
| 101 |
+
from annotator.normalbae import NormalBaeDetector
|
| 102 |
+
model_normalbae = NormalBaeDetector()
|
| 103 |
+
result = model_normalbae(img)
|
| 104 |
+
return [result]
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
model_openpose = None
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def openpose(img, res, hand_and_face):
|
| 111 |
+
img = resize_image(HWC3(img), res)
|
| 112 |
+
global model_openpose
|
| 113 |
+
if model_openpose is None:
|
| 114 |
+
from annotator.openpose import OpenposeDetector
|
| 115 |
+
model_openpose = OpenposeDetector()
|
| 116 |
+
result = model_openpose(img, hand_and_face)
|
| 117 |
+
return [result]
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
model_dwpose = None
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def dwpose(img, res):
|
| 124 |
+
img = resize_image(HWC3(img), res)
|
| 125 |
+
global model_dwpose
|
| 126 |
+
if model_dwpose is None:
|
| 127 |
+
from annotator.dwpose import DWposeDetector
|
| 128 |
+
model_dwpose = DWposeDetector()
|
| 129 |
+
result = model_dwpose(img)
|
| 130 |
+
return [result]
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
model_lineart_anime = None
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def lineart_anime(img, res, invert=True):
|
| 137 |
+
img = resize_image(HWC3(img), res)
|
| 138 |
+
global model_lineart_anime
|
| 139 |
+
if model_lineart_anime is None:
|
| 140 |
+
from annotator.lineart_anime import LineartAnimeDetector
|
| 141 |
+
model_lineart_anime = LineartAnimeDetector()
|
| 142 |
+
if invert:
|
| 143 |
+
result = cv2.bitwise_not(model_lineart_anime(img))
|
| 144 |
+
else:
|
| 145 |
+
result = model_lineart_anime(img)
|
| 146 |
+
return [result]
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
model_lineart = None
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def lineart(img, res, coarse=False, invert=True):
|
| 153 |
+
img = resize_image(HWC3(img), res)
|
| 154 |
+
global model_lineart
|
| 155 |
+
if model_lineart is None:
|
| 156 |
+
from annotator.lineart import LineartDetector
|
| 157 |
+
model_lineart = LineartDetector()
|
| 158 |
+
if invert:
|
| 159 |
+
result = cv2.bitwise_not(model_lineart(img, coarse))
|
| 160 |
+
else:
|
| 161 |
+
result = model_lineart(img, coarse)
|
| 162 |
+
return [result]
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
model_oneformer_coco = None
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def oneformer_coco(img, res):
|
| 169 |
+
img = resize_image(HWC3(img), res)
|
| 170 |
+
global model_oneformer_coco
|
| 171 |
+
if model_oneformer_coco is None:
|
| 172 |
+
from annotator.oneformer import OneformerCOCODetector
|
| 173 |
+
model_oneformer_coco = OneformerCOCODetector()
|
| 174 |
+
result = model_oneformer_coco(img)
|
| 175 |
+
return [result]
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
model_oneformer_ade20k = None
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def oneformer_ade20k(img, res):
|
| 182 |
+
img = resize_image(HWC3(img), res)
|
| 183 |
+
global model_oneformer_ade20k
|
| 184 |
+
if model_oneformer_ade20k is None:
|
| 185 |
+
from annotator.oneformer import OneformerADE20kDetector
|
| 186 |
+
model_oneformer_ade20k = OneformerADE20kDetector()
|
| 187 |
+
result = model_oneformer_ade20k(img)
|
| 188 |
+
return [result]
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
model_content_shuffler = None
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def content_shuffler(img, res):
|
| 195 |
+
img = resize_image(HWC3(img), res)
|
| 196 |
+
global model_content_shuffler
|
| 197 |
+
if model_content_shuffler is None:
|
| 198 |
+
from annotator.shuffle import ContentShuffleDetector
|
| 199 |
+
model_content_shuffler = ContentShuffleDetector()
|
| 200 |
+
result = model_content_shuffler(img)
|
| 201 |
+
return [result]
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
model_color_shuffler = None
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def color_shuffler(img, res):
|
| 208 |
+
img = resize_image(HWC3(img), res)
|
| 209 |
+
global model_color_shuffler
|
| 210 |
+
if model_color_shuffler is None:
|
| 211 |
+
from annotator.shuffle import ColorShuffleDetector
|
| 212 |
+
model_color_shuffler = ColorShuffleDetector()
|
| 213 |
+
result = model_color_shuffler(img)
|
| 214 |
+
return [result]
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
model_inpaint = None
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def inpaint(image, invert):
|
| 221 |
+
# Gradio 4.x: ImageEditor returns dict with "background" and "layers"
|
| 222 |
+
# background: numpy array (H, W, 3) RGB
|
| 223 |
+
# layers: list of numpy arrays (H, W, 4) RGBA
|
| 224 |
+
if image is None:
|
| 225 |
+
return []
|
| 226 |
+
|
| 227 |
+
background = image.get("background")
|
| 228 |
+
layers = image.get("layers", [])
|
| 229 |
+
|
| 230 |
+
if background is None:
|
| 231 |
+
return []
|
| 232 |
+
|
| 233 |
+
color = HWC3(background)
|
| 234 |
+
|
| 235 |
+
if layers and layers[0] is not None:
|
| 236 |
+
layer = layers[0]
|
| 237 |
+
# Alpha channel is at index 3
|
| 238 |
+
if layer.shape[2] == 4:
|
| 239 |
+
alpha = layer[:, :, 3:4]
|
| 240 |
+
else:
|
| 241 |
+
# Fallback: no alpha, use white mask
|
| 242 |
+
alpha = np.ones((*layer.shape[:2], 1), dtype=np.uint8) * 255
|
| 243 |
+
else:
|
| 244 |
+
# No layer drawn: use fully transparent mask
|
| 245 |
+
alpha = np.zeros((*color.shape[:2], 1), dtype=np.uint8)
|
| 246 |
+
|
| 247 |
+
if invert:
|
| 248 |
+
alpha = 255 - alpha
|
| 249 |
+
|
| 250 |
+
# Resize alpha to match background if needed
|
| 251 |
+
if alpha.shape[:2] != color.shape[:2]:
|
| 252 |
+
alpha = cv2.resize(alpha, (color.shape[1], color.shape[0]))
|
| 253 |
+
alpha = alpha[:, :, np.newaxis] if alpha.ndim == 2 else alpha
|
| 254 |
+
|
| 255 |
+
result = np.concatenate([color, alpha], axis=2)
|
| 256 |
+
return [result]
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
custom_theme = gr.themes.Soft(primary_hue="blue", neutral_hue="slate").set(
|
| 260 |
+
button_primary_background_fill="*primary_500",
|
| 261 |
+
button_primary_background_fill_hover="*primary_600",
|
| 262 |
+
button_primary_text_color="white",
|
| 263 |
+
button_secondary_background_fill="*neutral_200",
|
| 264 |
+
button_secondary_background_fill_hover="*neutral_300",
|
| 265 |
+
button_secondary_text_color="*neutral_800",
|
| 266 |
+
)
|
| 267 |
+
custom_css = """
|
| 268 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 269 |
+
Base
|
| 270 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 271 |
+
|
| 272 |
+
.gradio-container {
|
| 273 |
+
max-width: 1400px !important;
|
| 274 |
+
margin: auto !important;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 278 |
+
Description
|
| 279 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 280 |
+
|
| 281 |
+
.app-description {
|
| 282 |
+
border-radius: 18px;
|
| 283 |
+
padding: 14px;
|
| 284 |
+
margin-bottom: 0.8rem;
|
| 285 |
+
|
| 286 |
+
background:
|
| 287 |
+
color-mix(
|
| 288 |
+
in srgb,
|
| 289 |
+
var(--background-fill-secondary) 88%,
|
| 290 |
+
transparent
|
| 291 |
+
);
|
| 292 |
+
|
| 293 |
+
border: 1px solid var(--border-color-primary);
|
| 294 |
+
|
| 295 |
+
box-shadow:
|
| 296 |
+
0 2px 10px rgba(0,0,0,0.04);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 300 |
+
Selector
|
| 301 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 302 |
+
|
| 303 |
+
.jump-selector {
|
| 304 |
+
|
| 305 |
+
position: sticky;
|
| 306 |
+
|
| 307 |
+
top: 0;
|
| 308 |
+
|
| 309 |
+
z-index: 1000;
|
| 310 |
+
|
| 311 |
+
margin-bottom: 1rem;
|
| 312 |
+
|
| 313 |
+
padding: 10px;
|
| 314 |
+
|
| 315 |
+
border-radius: 14px;
|
| 316 |
+
|
| 317 |
+
backdrop-filter: blur(10px);
|
| 318 |
+
|
| 319 |
+
background:
|
| 320 |
+
color-mix(
|
| 321 |
+
in srgb,
|
| 322 |
+
var(--background-fill-primary) 85%,
|
| 323 |
+
transparent
|
| 324 |
+
);
|
| 325 |
+
|
| 326 |
+
border:
|
| 327 |
+
1px solid
|
| 328 |
+
color-mix(
|
| 329 |
+
in srgb,
|
| 330 |
+
var(--border-color-primary) 75%,
|
| 331 |
+
transparent
|
| 332 |
+
);
|
| 333 |
+
}
|
| 334 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 335 |
+
Section Header
|
| 336 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 337 |
+
|
| 338 |
+
.section-header {
|
| 339 |
+
border-left: 5px solid var(--color-accent, #3b82f6);
|
| 340 |
+
|
| 341 |
+
border-radius: 0 12px 12px 0;
|
| 342 |
+
|
| 343 |
+
padding: 12px 18px !important;
|
| 344 |
+
|
| 345 |
+
margin-bottom: 10px !important;
|
| 346 |
+
|
| 347 |
+
background:
|
| 348 |
+
color-mix(
|
| 349 |
+
in srgb,
|
| 350 |
+
var(--color-accent, #3b82f6) 10%,
|
| 351 |
+
var(--background-fill-secondary)
|
| 352 |
+
);
|
| 353 |
+
|
| 354 |
+
border:
|
| 355 |
+
1px solid
|
| 356 |
+
color-mix(
|
| 357 |
+
in srgb,
|
| 358 |
+
var(--color-accent, #3b82f6) 25%,
|
| 359 |
+
var(--border-color-primary)
|
| 360 |
+
);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
.section-header h2 {
|
| 364 |
+
margin: 0 !important;
|
| 365 |
+
font-size: 1.15rem !important;
|
| 366 |
+
font-weight: 700 !important;
|
| 367 |
+
color: var(--body-text-color) !important;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
.section-header p {
|
| 371 |
+
margin-top: 6px !important;
|
| 372 |
+
margin-bottom: 0 !important;
|
| 373 |
+
|
| 374 |
+
font-size: 0.86rem !important;
|
| 375 |
+
|
| 376 |
+
color: var(--body-text-color-subdued) !important;
|
| 377 |
+
|
| 378 |
+
line-height: 1.45;
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 382 |
+
Section Card
|
| 383 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 384 |
+
.section-card {
|
| 385 |
+
border-radius: 18px;
|
| 386 |
+
padding: 14px;
|
| 387 |
+
margin-bottom: 0.8rem;
|
| 388 |
+
border:
|
| 389 |
+
1px solid
|
| 390 |
+
color-mix(
|
| 391 |
+
in srgb,
|
| 392 |
+
var(--border-color-primary) 75%,
|
| 393 |
+
transparent
|
| 394 |
+
);
|
| 395 |
+
background:
|
| 396 |
+
color-mix(
|
| 397 |
+
in srgb,
|
| 398 |
+
var(--background-fill-primary) 97%,
|
| 399 |
+
var(--background-fill-secondary)
|
| 400 |
+
);
|
| 401 |
+
box-shadow:
|
| 402 |
+
0 1px 6px rgba(0,0,0,0.035);
|
| 403 |
+
}
|
| 404 |
+
/* ダーク時は少し強め */
|
| 405 |
+
.dark .section-card {
|
| 406 |
+
box-shadow:
|
| 407 |
+
0 2px 10px rgba(0,0,0,0.18);
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 411 |
+
Input / Output Panels
|
| 412 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 413 |
+
|
| 414 |
+
.input-panel {
|
| 415 |
+
border-radius: 14px;
|
| 416 |
+
|
| 417 |
+
padding: 14px;
|
| 418 |
+
|
| 419 |
+
border: 1px solid var(--border-color-primary);
|
| 420 |
+
|
| 421 |
+
background:
|
| 422 |
+
color-mix(
|
| 423 |
+
in srgb,
|
| 424 |
+
var(--background-fill-secondary) 82%,
|
| 425 |
+
transparent
|
| 426 |
+
);
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
.output-panel {
|
| 430 |
+
border-radius: 14px;
|
| 431 |
+
|
| 432 |
+
padding: 14px;
|
| 433 |
+
|
| 434 |
+
border: 1px solid var(--border-color-primary);
|
| 435 |
+
|
| 436 |
+
background:
|
| 437 |
+
color-mix(
|
| 438 |
+
in srgb,
|
| 439 |
+
var(--color-accent, #3b82f6) 4%,
|
| 440 |
+
var(--background-fill-secondary)
|
| 441 |
+
);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 445 |
+
Run Button
|
| 446 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 447 |
+
|
| 448 |
+
.run-btn {
|
| 449 |
+
margin-top: 12px !important;
|
| 450 |
+
|
| 451 |
+
height: 46px !important;
|
| 452 |
+
|
| 453 |
+
border-radius: 12px !important;
|
| 454 |
+
|
| 455 |
+
font-size: 0.96rem !important;
|
| 456 |
+
|
| 457 |
+
font-weight: 700 !important;
|
| 458 |
+
|
| 459 |
+
letter-spacing: 0.02em !important;
|
| 460 |
+
|
| 461 |
+
transition:
|
| 462 |
+
transform 0.12s ease,
|
| 463 |
+
box-shadow 0.12s ease !important;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
.run-btn:hover {
|
| 467 |
+
transform: translateY(-2px) !important;
|
| 468 |
+
|
| 469 |
+
box-shadow:
|
| 470 |
+
0 8px 18px
|
| 471 |
+
color-mix(
|
| 472 |
+
in srgb,
|
| 473 |
+
var(--color-accent, #3b82f6) 35%,
|
| 474 |
+
transparent
|
| 475 |
+
) !important;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
.run-btn:active {
|
| 479 |
+
transform: translateY(0) !important;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 483 |
+
Gallery
|
| 484 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 485 |
+
|
| 486 |
+
.output-gallery {
|
| 487 |
+
border-radius: 14px !important;
|
| 488 |
+
|
| 489 |
+
border: 1px solid var(--border-color-primary) !important;
|
| 490 |
+
|
| 491 |
+
min-height: 280px;
|
| 492 |
+
|
| 493 |
+
overflow: hidden;
|
| 494 |
+
|
| 495 |
+
background:
|
| 496 |
+
color-mix(
|
| 497 |
+
in srgb,
|
| 498 |
+
var(--background-fill-primary) 92%,
|
| 499 |
+
transparent
|
| 500 |
+
);
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
/* Gallery image hover */
|
| 504 |
+
|
| 505 |
+
.output-gallery img {
|
| 506 |
+
transition:
|
| 507 |
+
transform 0.14s ease,
|
| 508 |
+
opacity 0.14s ease;
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
.output-gallery img:hover {
|
| 512 |
+
transform: scale(1.015);
|
| 513 |
+
opacity: 0.96;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 517 |
+
Sliders / Inputs
|
| 518 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 519 |
+
|
| 520 |
+
.gradio-slider {
|
| 521 |
+
padding-top: 4px !important;
|
| 522 |
+
padding-bottom: 4px !important;
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
.gradio-checkbox {
|
| 526 |
+
margin-top: 6px !important;
|
| 527 |
+
margin-bottom: 6px !important;
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
| 531 |
+
Divider
|
| 532 |
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
|
| 533 |
+
|
| 534 |
+
.section-divider {
|
| 535 |
+
border: none !important;
|
| 536 |
+
|
| 537 |
+
border-top:
|
| 538 |
+
1px solid
|
| 539 |
+
color-mix(
|
| 540 |
+
in srgb,
|
| 541 |
+
var(--border-color-primary) 70%,
|
| 542 |
+
transparent
|
| 543 |
+
) !important;
|
| 544 |
+
|
| 545 |
+
margin:
|
| 546 |
+
0.35rem 0
|
| 547 |
+
0.6rem !important;
|
| 548 |
+
|
| 549 |
+
opacity: 0.55;
|
| 550 |
+
}
|
| 551 |
+
"""
|
| 552 |
+
|
| 553 |
+
block = gr.Blocks().queue()
|
| 554 |
+
|
| 555 |
+
with block:
|
| 556 |
+
gr.Markdown(DESCRIPTION, elem_classes=["app-description"])
|
| 557 |
+
gr.HTML('''
|
| 558 |
+
<div class="jump-selector">
|
| 559 |
+
<label style="font-size:0.85rem; font-weight:600; color:var(--body-text-color-subdued); margin-bottom:4px; display:block;">Jump to Section</label>
|
| 560 |
+
<select id="section-jump-select" onchange="
|
| 561 |
+
var sectionId = this.value;
|
| 562 |
+
if (!sectionId) return;
|
| 563 |
+
setTimeout(function() {
|
| 564 |
+
var el = document.getElementById(sectionId);
|
| 565 |
+
if (!el) return;
|
| 566 |
+
function getScrollParent(node) {
|
| 567 |
+
if (!node || node === document.body) return window;
|
| 568 |
+
var style = getComputedStyle(node);
|
| 569 |
+
var overflow = style.overflow + style.overflowY;
|
| 570 |
+
if (/(auto|scroll)/.test(overflow) && node.scrollHeight > node.clientHeight) return node;
|
| 571 |
+
return getScrollParent(node.parentElement);
|
| 572 |
+
}
|
| 573 |
+
var container = getScrollParent(el.parentElement);
|
| 574 |
+
if (container === window) {
|
| 575 |
+
var top = el.getBoundingClientRect().top + window.scrollY - 8;
|
| 576 |
+
window.scrollTo({ top: top, behavior: 'smooth' });
|
| 577 |
+
} else {
|
| 578 |
+
var containerTop = container.getBoundingClientRect().top;
|
| 579 |
+
var elTop = el.getBoundingClientRect().top;
|
| 580 |
+
container.scrollBy({ top: elTop - containerTop - 8, behavior: 'smooth' });
|
| 581 |
+
}
|
| 582 |
+
}, 100);
|
| 583 |
+
" style="
|
| 584 |
+
width: 100%;
|
| 585 |
+
padding: 8px 12px;
|
| 586 |
+
border-radius: 8px;
|
| 587 |
+
border: 1px solid var(--border-color-primary);
|
| 588 |
+
background: var(--background-fill-primary);
|
| 589 |
+
color: var(--body-text-color);
|
| 590 |
+
font-size: 0.95rem;
|
| 591 |
+
cursor: pointer;
|
| 592 |
+
">
|
| 593 |
+
<option value="section-canny">Canny</option>
|
| 594 |
+
<option value="section-inpaint">Inpaint</option>
|
| 595 |
+
<option value="section-hed">HED</option>
|
| 596 |
+
<option value="section-pidi">Pidi</option>
|
| 597 |
+
<option value="section-mlsd">MLSD</option>
|
| 598 |
+
<option value="section-midas">MIDAS</option>
|
| 599 |
+
<option value="section-zoe">Zoe</option>
|
| 600 |
+
<option value="section-normalbae">NormalBae</option>
|
| 601 |
+
<option value="section-dwpose">DWPose</option>
|
| 602 |
+
<option value="section-openpose">OpenPose</option>
|
| 603 |
+
<option value="section-lineart-anime">Lineart Anime</option>
|
| 604 |
+
<option value="section-lineart">Lineart</option>
|
| 605 |
+
<option value="section-oneformer-coco">OneFormer COCO</option>
|
| 606 |
+
<option value="section-oneformer-ade20k">OneFormer ADE20K</option>
|
| 607 |
+
<option value="section-content-shuffle">Content Shuffle</option>
|
| 608 |
+
<option value="section-color-shuffle">Color Shuffle</option>
|
| 609 |
+
</select>
|
| 610 |
+
</div>
|
| 611 |
+
''')
|
| 612 |
+
|
| 613 |
+
# ── Canny ──────────────────────────────────────────────────────────────
|
| 614 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-canny"):
|
| 615 |
+
with gr.Row():
|
| 616 |
+
gr.Markdown("## Canny Edge", elem_classes=["section-header"])
|
| 617 |
+
with gr.Row():
|
| 618 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 619 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 620 |
+
low_threshold = gr.Slider(label="low_threshold", minimum=1, maximum=255, value=100, step=1)
|
| 621 |
+
high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
|
| 622 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 623 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 624 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 625 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 626 |
+
run_button.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold], outputs=[gallery])
|
| 627 |
+
|
| 628 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 629 |
+
|
| 630 |
+
# ── Inpaint ────────────────────────────────────────────────────────────
|
| 631 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-inpaint"):
|
| 632 |
+
with gr.Row():
|
| 633 |
+
gr.Markdown("## Inpaint \n<p>画像はツールのUpload buttonを押してアップロードして下さい。", elem_classes=["section-header"])
|
| 634 |
+
with gr.Row():
|
| 635 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 636 |
+
# Gradio 4.x: use ImageEditor instead of deprecated ImageMask
|
| 637 |
+
input_image_inpaint = gr.ImageEditor(
|
| 638 |
+
label="Input Image (draw mask)",
|
| 639 |
+
type="numpy",
|
| 640 |
+
height=480,
|
| 641 |
+
sources=["upload"],
|
| 642 |
+
brush=gr.Brush(colors=["#000000"], default_size=20),
|
| 643 |
+
layers=True,
|
| 644 |
+
)
|
| 645 |
+
invert = gr.Checkbox(label="Invert Mask", value=False)
|
| 646 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 647 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 648 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 649 |
+
run_button.click(fn=inpaint, inputs=[input_image_inpaint, invert], outputs=[gallery])
|
| 650 |
+
|
| 651 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 652 |
+
|
| 653 |
+
# ── HED ────────────────────────────────────────────────────────────────
|
| 654 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-hed"):
|
| 655 |
+
with gr.Row():
|
| 656 |
+
gr.Markdown('## HED Edge "SoftEdge"', elem_classes=["section-header"])
|
| 657 |
+
with gr.Row():
|
| 658 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 659 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 660 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 661 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 662 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 663 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 664 |
+
run_button.click(fn=hed, inputs=[input_image, resolution], outputs=[gallery])
|
| 665 |
+
|
| 666 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 667 |
+
|
| 668 |
+
# ── Pidi ───────────────────────────────────────────────────────────────
|
| 669 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-pidi"):
|
| 670 |
+
with gr.Row():
|
| 671 |
+
gr.Markdown('## Pidi Edge "SoftEdge"', elem_classes=["section-header"])
|
| 672 |
+
with gr.Row():
|
| 673 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 674 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 675 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 676 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 677 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 678 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 679 |
+
run_button.click(fn=pidi, inputs=[input_image, resolution], outputs=[gallery])
|
| 680 |
+
|
| 681 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 682 |
+
|
| 683 |
+
# ── MLSD ───────────────────────────────────────────────────────────────
|
| 684 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-mlsd"):
|
| 685 |
+
with gr.Row():
|
| 686 |
+
gr.Markdown("## MLSD Edge", elem_classes=["section-header"])
|
| 687 |
+
with gr.Row():
|
| 688 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 689 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 690 |
+
value_threshold = gr.Slider(label="value_threshold", minimum=0.01, maximum=2.0, value=0.1, step=0.01)
|
| 691 |
+
distance_threshold = gr.Slider(label="distance_threshold", minimum=0.01, maximum=20.0, value=0.1, step=0.01)
|
| 692 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
| 693 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 694 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 695 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 696 |
+
run_button.click(fn=mlsd, inputs=[input_image, resolution, value_threshold, distance_threshold], outputs=[gallery])
|
| 697 |
+
|
| 698 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 699 |
+
|
| 700 |
+
# ── MIDAS ──────────────────────────────────────────────────────────────
|
| 701 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-midas"):
|
| 702 |
+
with gr.Row():
|
| 703 |
+
gr.Markdown("## MIDAS Depth", elem_classes=["section-header"])
|
| 704 |
+
with gr.Row():
|
| 705 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 706 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 707 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=384, step=64)
|
| 708 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 709 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 710 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 711 |
+
run_button.click(fn=midas, inputs=[input_image, resolution], outputs=[gallery])
|
| 712 |
+
|
| 713 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 714 |
+
|
| 715 |
+
# ── Zoe ────────────────────────────────────────────────────────────────
|
| 716 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-zoe"):
|
| 717 |
+
with gr.Row():
|
| 718 |
+
gr.Markdown("## Zoe Depth", elem_classes=["section-header"])
|
| 719 |
+
with gr.Row():
|
| 720 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 721 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 722 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 723 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 724 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 725 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 726 |
+
run_button.click(fn=zoe, inputs=[input_image, resolution], outputs=[gallery])
|
| 727 |
+
|
| 728 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 729 |
+
|
| 730 |
+
# ── Normal Bae ─────────────────────────────────────────────────────────
|
| 731 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-normalbae"):
|
| 732 |
+
with gr.Row():
|
| 733 |
+
gr.Markdown("## Normal Bae", elem_classes=["section-header"])
|
| 734 |
+
with gr.Row():
|
| 735 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 736 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 737 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 738 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 739 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 740 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 741 |
+
run_button.click(fn=normalbae, inputs=[input_image, resolution], outputs=[gallery])
|
| 742 |
+
|
| 743 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 744 |
+
|
| 745 |
+
# ── DWPose ─────────────────────────────────────────────────────────────
|
| 746 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-dwpose"):
|
| 747 |
+
with gr.Row():
|
| 748 |
+
gr.Markdown("## DWPose", elem_classes=["section-header"])
|
| 749 |
+
with gr.Row():
|
| 750 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 751 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 752 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 753 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 754 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 755 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 756 |
+
run_button.click(fn=dwpose, inputs=[input_image, resolution], outputs=[gallery])
|
| 757 |
+
|
| 758 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 759 |
+
|
| 760 |
+
# ── Openpose ───────────────────────────────────────────────────────────
|
| 761 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-openpose"):
|
| 762 |
+
with gr.Row():
|
| 763 |
+
gr.Markdown("## Openpose", elem_classes=["section-header"])
|
| 764 |
+
with gr.Row():
|
| 765 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 766 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 767 |
+
hand_and_face = gr.Checkbox(label="Hand and Face", value=False)
|
| 768 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 769 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 770 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 771 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 772 |
+
run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])
|
| 773 |
+
|
| 774 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 775 |
+
|
| 776 |
+
# ── Lineart Anime ──────────────────────────────────────────────────────
|
| 777 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-lineart-anime"):
|
| 778 |
+
with gr.Row():
|
| 779 |
+
gr.Markdown("## Lineart Anime \n<p>Check Invert to use with Mochi Diffusion.", elem_classes=["section-header"])
|
| 780 |
+
with gr.Row():
|
| 781 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 782 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 783 |
+
invert = gr.Checkbox(label="Invert", value=True)
|
| 784 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 785 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 786 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 787 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 788 |
+
run_button.click(fn=lineart_anime, inputs=[input_image, resolution, invert], outputs=[gallery])
|
| 789 |
+
|
| 790 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 791 |
+
|
| 792 |
+
# ── Lineart ────────────────────────────────────────────────────────────
|
| 793 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-lineart"):
|
| 794 |
+
with gr.Row():
|
| 795 |
+
gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.", elem_classes=["section-header"])
|
| 796 |
+
with gr.Row():
|
| 797 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 798 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 799 |
+
coarse = gr.Checkbox(label="Using coarse model", value=False)
|
| 800 |
+
invert = gr.Checkbox(label="Invert", value=True)
|
| 801 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 802 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 803 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 804 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 805 |
+
run_button.click(fn=lineart, inputs=[input_image, resolution, coarse, invert], outputs=[gallery])
|
| 806 |
+
|
| 807 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 808 |
+
|
| 809 |
+
# ── Oneformer COCO ─────────────────────────────────────────────────────
|
| 810 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-oneformer-coco"):
|
| 811 |
+
with gr.Row():
|
| 812 |
+
gr.Markdown("## Oneformer COCO Segmentation", elem_classes=["section-header"])
|
| 813 |
+
with gr.Row():
|
| 814 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 815 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 816 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 817 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 818 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 819 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 820 |
+
run_button.click(fn=oneformer_coco, inputs=[input_image, resolution], outputs=[gallery])
|
| 821 |
+
|
| 822 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 823 |
+
|
| 824 |
+
# ── Oneformer ADE20K ───────────────────────────────────────────────────
|
| 825 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-oneformer-ade20k"):
|
| 826 |
+
with gr.Row():
|
| 827 |
+
gr.Markdown("## Oneformer ADE20K Segmentation", elem_classes=["section-header"])
|
| 828 |
+
with gr.Row():
|
| 829 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 830 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 831 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=640, step=64)
|
| 832 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 833 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 834 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 835 |
+
run_button.click(fn=oneformer_ade20k, inputs=[input_image, resolution], outputs=[gallery])
|
| 836 |
+
|
| 837 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 838 |
+
|
| 839 |
+
# ── Content Shuffle ────────────────────────────────────────────────────
|
| 840 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-content-shuffle"):
|
| 841 |
+
with gr.Row():
|
| 842 |
+
gr.Markdown("## Content Shuffle", elem_classes=["section-header"])
|
| 843 |
+
with gr.Row():
|
| 844 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 845 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 846 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 847 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 848 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 849 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 850 |
+
run_button.click(fn=content_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
| 851 |
+
|
| 852 |
+
# gr.HTML("<hr class='section-divider'>")
|
| 853 |
+
|
| 854 |
+
# ── Color Shuffle ──────────────────────────────────────────────────────
|
| 855 |
+
with gr.Group(elem_classes=["section-card"], elem_id="section-color-shuffle"):
|
| 856 |
+
with gr.Row():
|
| 857 |
+
gr.Markdown("## Color Shuffle", elem_classes=["section-header"])
|
| 858 |
+
with gr.Row():
|
| 859 |
+
with gr.Column(elem_classes=["input-panel"]):
|
| 860 |
+
input_image = gr.Image(label="Input Image", type="numpy", height=480)
|
| 861 |
+
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 862 |
+
run_button = gr.Button("▶ Run", elem_classes=["run-btn"])
|
| 863 |
+
with gr.Column(elem_classes=["output-panel"]):
|
| 864 |
+
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto", elem_classes=["output-gallery"])
|
| 865 |
+
run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
| 866 |
+
|
| 867 |
+
|
| 868 |
+
block.launch(
|
| 869 |
+
server_name="0.0.0.0",
|
| 870 |
+
theme=custom_theme,
|
| 871 |
+
css=custom_css
|
| 872 |
+
)
|