Instructions to use Baragi-AI/LPC-FourDirection-Walk-Flux-Klein-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use Baragi-AI/LPC-FourDirection-Walk-Flux-Klein-9B with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline from diffusers.utils import load_image # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-base-9B", dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("Baragi-AI/LPC-FourDirection-Walk-Flux-Klein-9B") prompt = "Turn this cat into a dog" input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png") image = pipe(image=input_image, prompt=prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
File size: 74,602 Bytes
4c3e3fc | 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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 | # THESIS: Turn five model tasks into one character-to-animation workbench;
# refuse the generic prompt form as the product's primary structure.
# OWN-WORLD: White proof sheets, near-black ink rails, cobalt registration
# marks, vermilion actions, square frame cells, and indexed palette strips.
# STORY: Choose a real LPC base, dress it, derive directions and walks, correct
# pixels and palette, then export; every result becomes the next stage's input.
# FIRST VIEWPORT: Source rail left, dominant active proof center, next action
# right, with the palette and proof log below.
# FORM: Screenprint registration workbench; staged per tab from approved comps
# A+B+C. Direction seed e120291a.
import argparse
import copy
import json
import os
import secrets
import shutil
import tempfile
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime
from pathlib import Path
from urllib.parse import urlsplit, urlunsplit
import gradio as gr
import requests
from dotenv import load_dotenv
from PIL import Image, ImageDraw
from postprocess import (
apply_shared_palette,
process_output,
reference_palette,
save_gif,
shared_palette,
)
ROOT = Path(__file__).parent
WORKFLOW = ROOT / "workflows" / "LPC_FourDirection_Walk_API.json"
BASE_DIR = ROOT / "assets" / "bases"
OUTPUT_DIR = ROOT / "outputs"
BASE_STANDING = BASE_DIR / "standing_south.png"
BASE_WALKS = {
"north": BASE_DIR / "walk_north_4x2.png",
"west": BASE_DIR / "walk_west_4x2.png",
"south": BASE_DIR / "walk_south_4x2.png",
"east": BASE_DIR / "walk_east_4x2.png",
}
DIRECTIONS = ("north", "west", "south", "east")
MAX_PARALLEL_REQUESTS = 4
DIRECTION_LABELS = {
"north": "๋ถ์ชฝ",
"west": "์์ชฝ",
"south": "๋จ์ชฝ",
"east": "๋์ชฝ",
}
def load_environment():
for directory in (ROOT, *ROOT.parents):
candidate = directory / ".env"
if candidate.exists():
load_dotenv(candidate, override=False)
return candidate
return None
ENV_PATH = load_environment()
TASKS = {
"Rotate standing character": (
"TASK_ROTATE_STANDING: Turn the south-facing standing female LPC "
"character to face {direction}. Preserve the exact hairstyle, hair "
"color, clothing, shoes and accessories. Keep the character centered "
"on a pure white background."
),
"Standing to walk frame 1": (
"TASK_STANDING_TO_WALK_FIRST_FRAME: Convert this {direction}-facing "
"standing LPC character into the first frame of the {direction}-facing "
"walking animation. Preserve the exact appearance and pure white background."
),
"Propagate frame 1 appearance": (
"TASK_PROPAGATE_APPEARANCE: Use frame 1 as the appearance reference. "
"Apply exactly the same hairstyle, hair color, clothing, shoes and "
"accessories to frames 2 through 8. Preserve every walking pose, frame "
"order, 4 by 2 layout and pure white background."
),
"Dress 4x2 walk sheet": (
"TASK_DRESS_WALK_SHEET: Dress the female LPC character in all 8 "
"{direction}-facing walking frames with {appearance}. Preserve every "
"pose, frame order, 4 by 2 layout and pure white background."
),
"Dress standing character": (
"TASK_DRESS_STANDING: Dress the south-facing standing female LPC "
"character with {appearance}. Preserve the pose and pure white background."
),
}
TASK_LABELS = {
"Rotate standing character": "Standing ๋ฐฉํฅ ๋ฐ๊พธ๊ธฐ",
"Standing to walk frame 1": "๊ฑท๊ธฐ ์ฒซ ํ๋ ์ ๋ง๋ค๊ธฐ",
"Propagate frame 1 appearance": "์ฒซ ํ๋ ์ ์ธํ ์ ํ",
"Dress 4x2 walk sheet": "4ร2 ๊ฑท๊ธฐ ์ํธ ๋จ์ฅ",
"Dress standing character": "Standing ์บ๋ฆญํฐ ๋จ์ฅ",
}
PALETTE_CHOICES = [
("๊ธฐ์ค ํ๋ ํธ ๊ณ ์ ", "Lock reference palette"),
("์ ์์ ํ์ฉ ยท ์ต์ข
32์", "Allow new colors (32)"),
]
RESOLUTION_CHOICES = [
("์
์ค์ผ์ผ ์ ์ง", "Upscaled"),
("LPC ์๋ณธ ํฌ๊ธฐ", "Native LPC"),
]
FORMAT_CHOICES = [
("PNG ์ํธ", "PNG sheet"),
("GIF ์ ๋๋ฉ์ด์
", "GIF"),
]
def initial_state():
return {
"active_standing": "",
"active_palette": "",
"directions": {},
"walks": {},
"history": [],
}
def state_copy(state):
return copy.deepcopy(state) if state else initial_state()
def make_prompt(task, direction, appearance):
if task not in TASKS:
raise ValueError(f"์ ์ ์๋ ์์
์
๋๋ค: {task}")
if task.startswith("Dress") and not appearance.strip():
raise ValueError("๋จธ๋ฆฌ, ์ท, ์ ๋ฐ, ์ฅ์์ ์ค๋ช
ํด ์ฃผ์ธ์.")
return TASKS[task].format(
direction=direction.lower(), appearance=appearance.strip()
)
def normalize_server(value):
raw = (value or "").strip()
if not raw:
raise ValueError("ComfyUI ์๋ฒ ์ฃผ์๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.")
if raw.count("://") != 1:
raise ValueError(
"์๋ฒ ์ฃผ์๊ฐ ์ค๋ณต๋์๊ฑฐ๋ ํ์์ด ์๋ชป๋์์ต๋๋ค. "
"์: https://cloud.comfy.org"
)
parsed = urlsplit(raw)
if parsed.scheme not in {"http", "https"} or not parsed.hostname:
raise ValueError("์๋ฒ ์ฃผ์๋ http:// ๋๋ https://๋ก ์์ํด์ผ ํฉ๋๋ค.")
clean = parsed._replace(query="", fragment="")
return urlunsplit(clean).rstrip("/")
def resolve_api_key(value):
return (
(value or "").strip()
or os.getenv("COMFY_API_KEY", "").strip()
or os.getenv("COMFY_CLOUD_API_KEY", "").strip()
)
def is_cloud(server):
return urlsplit(server).hostname == "cloud.comfy.org"
def headers(api_key):
return {"X-API-Key": api_key} if api_key else {}
def request_error(error):
if isinstance(error, requests.exceptions.ConnectionError):
return (
"์๋ฒ์ ์ฐ๊ฒฐํ์ง ๋ชปํ์ต๋๋ค. ์ฃผ์๊ฐ ์ค๋ณต ์
๋ ฅ๋์ง ์์๋์ง์ "
"์ธํฐ๋ท ์ฐ๊ฒฐ์ ํ์ธํด ์ฃผ์ธ์."
)
if isinstance(error, requests.exceptions.Timeout):
return "์๋ฒ ์๋ต ์๊ฐ์ด ์ด๊ณผ๋์์ต๋๋ค. ์ ์ ํ ๋ค์ ์๋ํด ์ฃผ์ธ์."
if isinstance(error, requests.exceptions.HTTPError):
status = error.response.status_code if error.response is not None else "์ ์ ์์"
if status in {401, 403}:
return "API ํค๊ฐ ๊ฑฐ๋ถ๋์์ต๋๋ค. Comfy Cloud ํค๋ฅผ ๋ค์ ํ์ธํด ์ฃผ์ธ์."
return f"ComfyUI๊ฐ HTTP {status} ์ค๋ฅ๋ฅผ ๋ฐํํ์ต๋๋ค."
return str(error)
def upload_image(server, api_key, image_path):
with open(image_path, "rb") as image:
response = requests.post(
f"{server}/api/upload/image",
headers=headers(api_key),
files={"image": (Path(image_path).name, image, "image/png")},
data={"type": "input", "overwrite": "true"},
timeout=120,
)
response.raise_for_status()
return response.json()["name"]
def submit(server, api_key, workflow):
response = requests.post(
f"{server}/api/prompt",
headers=headers(api_key),
json={"prompt": workflow},
timeout=120,
)
response.raise_for_status()
data = response.json()
return data.get("prompt_id") or data["job_id"]
def first_image(value):
if isinstance(value, dict):
if {"filename", "type"} <= value.keys():
return value
for child in value.values():
found = first_image(child)
if found:
return found
elif isinstance(value, list):
for child in value:
found = first_image(child)
if found:
return found
return None
def wait_for_result(server, api_key, job_id, cloud):
deadline = time.time() + 900
while time.time() < deadline:
if cloud:
response = requests.get(
f"{server}/api/jobs/{job_id}",
headers=headers(api_key),
timeout=60,
)
response.raise_for_status()
data = response.json()
status = data.get("status")
if status == "completed":
return data
if status in {"failed", "cancelled"}:
raise RuntimeError(data.get("error") or f"์์
์ด {status} ์ํ์
๋๋ค.")
else:
response = requests.get(
f"{server}/api/history/{job_id}",
headers=headers(api_key),
timeout=60,
)
response.raise_for_status()
data = response.json()
if job_id in data:
return data[job_id]
time.sleep(2)
raise TimeoutError("15๋ถ ์์ ์์ฑ์ด ์๋ฃ๋์ง ์์์ต๋๋ค.")
def download_image(server, api_key, output):
response = requests.get(
f"{server}/api/view",
headers=headers(api_key),
params={
"filename": output["filename"],
"subfolder": output.get("subfolder", ""),
"type": output.get("type", "output"),
},
timeout=120,
)
response.raise_for_status()
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as handle:
handle.write(response.content)
return handle.name
def persist(path, prefix):
OUTPUT_DIR.mkdir(exist_ok=True)
source = Path(path)
stamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
target = OUTPUT_DIR / f"{prefix}_{stamp}{source.suffix.lower()}"
shutil.copy2(source, target)
return str(target)
def add_history(state, path, label):
state["history"].insert(0, {"path": path, "label": label})
state["history"] = state["history"][:24]
def history_value(state):
return [
(entry["path"], entry["label"])
for entry in (state or {}).get("history", [])
if Path(entry["path"]).exists()
]
def direction_values(state):
directions = (state or {}).get("directions", {})
return tuple(directions.get(direction) for direction in DIRECTIONS)
def walk_value(state):
walks = (state or {}).get("walks", {})
return [
(walks[direction], f"{DIRECTION_LABELS[direction]} ๊ฑท๊ธฐ")
for direction in DIRECTIONS
if direction in walks and Path(walks[direction]).exists()
]
def palette_swatch(colors, prefix="palette"):
while len(colors) < 32:
colors.append(colors[-1])
swatch = 34
preview = Image.new("RGB", (swatch * 16, swatch * 2), "white")
draw = ImageDraw.Draw(preview)
for index, color in enumerate(colors[:32]):
x = (index % 16) * swatch
y = (index // 16) * swatch
draw.rectangle((x, y, x + swatch - 2, y + swatch - 2), fill=color)
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as handle:
preview.save(handle.name)
return persist(handle.name, prefix)
def palette_preview(image_path, prefix="palette"):
image = Image.open(image_path).convert("RGB").resize(
(64, 64), Image.Resampling.NEAREST
)
return palette_swatch(reference_palette(image), prefix)
def finalize_shared_palette(paths, prefix):
colors = shared_palette(paths.values())
outputs = apply_shared_palette(paths.values(), colors)
finalized = {
direction: persist(path, f"{prefix}_{direction}")
for direction, path in zip(paths, outputs)
}
return finalized, palette_swatch(colors, f"{prefix}_palette")
def animation_preview(sheet_path, fps=8):
sheet = Image.open(sheet_path).convert("RGB")
return persist(
save_gif(sheet, reference_palette(sheet), fps),
"walk_preview",
)
def generate(
server_value,
api_key_value,
image_path,
task,
direction,
appearance,
seed,
steps,
cfg,
lora_strength,
palette_reference_path=None,
palette_mode="Lock reference palette",
align_frames=True,
pixel_snap=True,
output_resolution="Upscaled",
output_format="PNG sheet",
fps=8,
prefix="result",
):
if not image_path:
raise ValueError("์
๋ ฅ ์ด๋ฏธ์ง๋ฅผ ์ ํํด ์ฃผ์ธ์.")
server = normalize_server(server_value)
api_key = resolve_api_key(api_key_value)
cloud = is_cloud(server)
if cloud and not api_key:
raise ValueError(
"Comfy Cloud API ํค๊ฐ ํ์ํฉ๋๋ค. ์ค์ ํญ ๋๋ .env์ "
"COMFY_API_KEY๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."
)
workflow = json.loads(WORKFLOW.read_text(encoding="utf-8"))
workflow["1"]["inputs"]["image"] = upload_image(server, api_key, image_path)
workflow["4"]["inputs"]["strength_model"] = float(lora_strength)
workflow["9"]["inputs"]["text"] = make_prompt(task, direction, appearance)
workflow["14"]["inputs"]["noise_seed"] = int(seed)
workflow["15"]["inputs"]["steps"] = int(steps)
workflow["17"]["inputs"]["cfg"] = float(cfg)
workflow["2"]["inputs"]["megapixels"] = (
2.0 if task in {"Dress 4x2 walk sheet", "Propagate frame 1 appearance"} else 1.0
)
job_id = submit(server, api_key, workflow)
result = wait_for_result(server, api_key, job_id, cloud)
output = first_image(result.get("outputs", result))
if not output:
raise RuntimeError("ComfyUI ์์
์ ๋๋ฌ์ง๋ง ์ด๋ฏธ์ง ์ถ๋ ฅ์ด ์์ต๋๋ค.")
raw_path = download_image(server, api_key, output)
final_path = process_output(
raw_path,
image_path,
task,
palette_reference_path,
palette_mode,
align_frames,
pixel_snap,
output_resolution,
output_format,
fps,
)
return persist(final_path, prefix), job_id
def compose_first_frame(first_frame_path, direction):
base = Image.open(BASE_WALKS[direction]).convert("RGB")
first = Image.open(first_frame_path).convert("RGB").resize(
(base.width // 4, base.height // 2), Image.Resampling.NEAREST
)
base.paste(first, (0, 0))
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as handle:
base.save(handle.name)
return handle.name
def dress_core(
source,
appearance,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
):
final, job_id = generate(
server,
api_key,
source,
"Dress standing character",
"south",
appearance,
seed,
steps,
cfg,
strength,
palette_mode="Allow new colors (32)",
align_frames=False,
prefix="standing_dressed",
)
state = state_copy(state)
palette = palette_preview(final)
state["active_standing"] = final
state["active_palette"] = palette
state["directions"] = {"south": final}
state["walks"] = {}
add_history(state, final, "Standing ์ธํ ์๋ฃ")
return state, final, palette, job_id
def direction_job(
direction,
index,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
):
if direction == "south":
return source, "๊ธฐ์กด Standing ์ฌ์ฉ"
return generate(
server,
api_key,
source,
"Rotate standing character",
direction,
"",
int(seed) + index,
steps,
cfg,
strength,
palette_mode="Defer shared palette",
prefix=f"standing_{direction}_pending",
)
def direction_results(
selected,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=None,
):
state = state if state is not None else initial_state()
source = source or state.get("active_standing")
if not source:
raise ValueError("๋จผ์ Standing ์บ๋ฆญํฐ๋ฅผ ์์ฑํด ์ฃผ์ธ์.")
selected = list(dict.fromkeys(selected or []))
if not selected:
raise ValueError("์์ฑํ ๋ฐฉํฅ์ ํ๋ ์ด์ ์ ํํด ์ฃผ์ธ์.")
for direction in selected:
state["directions"].pop(direction, None)
total = len(selected)
completed = 0
failures = []
workers = min(MAX_PARALLEL_REQUESTS, total)
with ThreadPoolExecutor(max_workers=workers) as executor:
futures = {
executor.submit(
direction_job,
direction,
index,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
): direction
for index, direction in enumerate(selected)
}
for future in as_completed(futures):
direction = futures[future]
try:
final, job_id = future.result()
except Exception as error:
failures.append(f"{DIRECTION_LABELS[direction]}: {request_error(error)}")
continue
state["directions"][direction] = final
completed += 1
add_history(
state,
final,
f"{DIRECTION_LABELS[direction]} Standing ยท ํ๋ ํธ ๋๊ธฐ ยท {job_id}",
)
if progress:
progress(
(completed, total),
desc=f"{DIRECTION_LABELS[direction]} ์๋ฃ ยท {completed}/{total}",
)
yield state, f"{DIRECTION_LABELS[direction]} ์๋ฃ ยท {completed}/{total}"
if failures:
raise RuntimeError(" / ".join(failures))
finalized, palette = finalize_shared_palette(
{direction: state["directions"][direction] for direction in selected},
"standing_shared",
)
state["directions"].update(finalized)
state["active_palette"] = palette
if "south" in finalized:
state["active_standing"] = finalized["south"]
for direction, path in finalized.items():
add_history(state, path, f"{DIRECTION_LABELS[direction]} Standing ยท ๊ณตํต ํ๋ ํธ")
if progress:
progress(1, desc="์ ์ฒด ๋ฐฉํฅ ๊ณตํต 32์ ํ๋ ํธ ์ ์ฉ")
yield state, "์ ์ฒด ๋ฐฉํฅ ์๋ฃ ยท ๊ณตํต 32์ ํ๋ ํธ๋ฅผ ์ ์ฉํ์ต๋๋ค."
def walk_job(
direction,
index,
standing,
server,
api_key,
seed,
steps,
cfg,
strength,
):
first, _ = generate(
server,
api_key,
standing,
"Standing to walk frame 1",
direction,
"",
int(seed) + index * 2,
steps,
cfg,
strength,
palette_mode="Defer shared palette",
align_frames=False,
prefix=f"walk_first_{direction}_pending",
)
composite = compose_first_frame(first, direction)
final, job_id = generate(
server,
api_key,
composite,
"Propagate frame 1 appearance",
direction,
"",
int(seed) + index * 2 + 1,
steps,
cfg,
strength,
palette_mode="Defer shared palette",
align_frames=True,
prefix=f"walk_{direction}_pending",
)
return final, job_id
def walk_results(
selected,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=None,
):
state = state if state is not None else initial_state()
selected = list(dict.fromkeys(selected or []))
if not selected:
raise ValueError("์์ฑํ ๋ฐฉํฅ์ ํ๋ ์ด์ ์ ํํด ์ฃผ์ธ์.")
missing = [
direction
for direction in selected
if direction not in state.get("directions", {})
]
if missing:
labels = ", ".join(DIRECTION_LABELS[direction] for direction in missing)
raise ValueError(f"๋จผ์ ๋ค์ ๋ฐฉํฅ์ Standing์ ๋ง๋ค์ด ์ฃผ์ธ์: {labels}")
for direction in selected:
state["walks"].pop(direction, None)
total = len(selected)
completed = 0
failures = []
workers = min(MAX_PARALLEL_REQUESTS, total)
with ThreadPoolExecutor(max_workers=workers) as executor:
futures = {
executor.submit(
walk_job,
direction,
index,
state["directions"][direction],
server,
api_key,
seed,
steps,
cfg,
strength,
): direction
for index, direction in enumerate(selected)
}
for future in as_completed(futures):
direction = futures[future]
try:
final, job_id = future.result()
except Exception as error:
failures.append(f"{DIRECTION_LABELS[direction]}: {request_error(error)}")
continue
state["walks"][direction] = final
completed += 1
add_history(
state,
final,
f"{DIRECTION_LABELS[direction]} ๊ฑท๊ธฐ ยท ํ๋ ํธ ๋๊ธฐ ยท {job_id}",
)
if progress:
progress(
(completed, total),
desc=f"{DIRECTION_LABELS[direction]} ๊ฑท๊ธฐ ์๋ฃ ยท {completed}/{total}",
)
yield state, f"{DIRECTION_LABELS[direction]} ๊ฑท๊ธฐ ์๋ฃ ยท {completed}/{total}"
if failures:
raise RuntimeError(" / ".join(failures))
finalized, palette = finalize_shared_palette(
{direction: state["walks"][direction] for direction in selected},
"walk_shared",
)
state["walks"].update(finalized)
state["active_palette"] = palette
for direction, path in finalized.items():
add_history(state, path, f"{DIRECTION_LABELS[direction]} ๊ฑท๊ธฐ ยท ๊ณตํต ํ๋ ํธ")
if progress:
progress(1, desc="์ ์ฒด ๋ฐฉํฅ ๊ณตํต 32์ ํ๋ ํธ ์ ์ฉ")
yield state, "์ ์ฒด ๊ฑท๊ธฐ ์๋ฃ ยท ๊ณตํต 32์ ํ๋ ํธ๋ฅผ ์ ์ฉํ์ต๋๋ค."
def format_failure(error):
return f"์ค๋ฅ ยท {request_error(error)}"
def ui_dress(
source,
appearance,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
):
try:
state, final, palette, job_id = dress_core(
source,
appearance,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
)
return (
final,
palette,
final,
f"์๋ฃ ยท Standing ์ธํ ์์ฑ ยท ์๋ {int(seed)} ยท {job_id}",
state,
history_value(state),
)
except Exception as error:
return None, None, None, format_failure(error), state, history_value(state)
def ui_directions(
selected,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=gr.Progress(),
):
try:
for state, message in direction_results(
selected,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress,
):
yield (
*direction_values(state),
f"{message} ยท ์๋ {int(seed)}",
state,
history_value(state),
)
except Exception as error:
yield (
*direction_values(state),
format_failure(error),
state,
history_value(state),
)
def ui_walks(
selected,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=gr.Progress(),
):
try:
for state, message in walk_results(
selected,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress,
):
available = [
state["walks"][direction]
for direction in selected or []
if direction in state["walks"]
]
latest = available[-1] if available else None
animation = animation_preview(latest) if latest else None
yield (
walk_value(state),
latest,
animation,
latest,
f"{message} ยท ์๋ {int(seed)}",
state,
history_value(state),
)
except Exception as error:
yield (
walk_value(state),
None,
None,
None,
format_failure(error),
state,
history_value(state),
)
def estimate_jobs(selected):
selected = selected or []
rotations = sum(direction != "south" for direction in selected)
total = 1 + rotations + len(selected) * 2
return (
f"์ ์ฒด ์คํ ์์: {total}๊ฐ ์์
"
f"(์ธํ 1 + ๋ฐฉํฅ {rotations} + ๊ฑท๊ธฐ {len(selected) * 2}) ยท "
"๋ฐฉํฅ๋ณ ์ต๋ 4๊ฐ ๋ณ๋ ฌ"
)
def new_seed():
return secrets.randbelow(2_147_483_647) + 1
def ui_run_all(
source,
appearance,
selected,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=gr.Progress(),
):
try:
if not selected:
raise ValueError("์์ฑํ ๋ฐฉํฅ์ ํ๋ ์ด์ ์ ํํด ์ฃผ์ธ์.")
total = 1 + sum(direction != "south" for direction in selected) + len(selected) * 2
progress((0, total), desc="Standing ์ธํ ์์ฑ")
state, active, palette, _ = dress_core(
source,
appearance,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
)
yield (
active,
palette,
*direction_values(state),
walk_value(state),
None,
None,
active,
"Standing ์๋ฃ ยท ๋ฐฉํฅ ์์
์ ๋ณ๋ ฌ๋ก ์์ํฉ๋๋ค.",
state,
history_value(state),
)
for state, message in direction_results(
selected,
active,
server,
api_key,
int(seed) + 100,
steps,
cfg,
strength,
state,
progress,
):
yield (
active,
state.get("active_palette") or palette,
*direction_values(state),
walk_value(state),
None,
None,
active,
message,
state,
history_value(state),
)
for state, message in walk_results(
selected,
server,
api_key,
int(seed) + 200,
steps,
cfg,
strength,
state,
progress,
):
available = [
state["walks"][direction]
for direction in selected
if direction in state["walks"]
]
latest = available[-1] if available else None
yield (
active,
state.get("active_palette") or palette,
*direction_values(state),
walk_value(state),
latest,
animation_preview(latest) if latest else None,
latest,
f"{message} ยท ์ ์ฒด {total}๊ฐ ์์
ยท ์๋ {int(seed)}",
state,
history_value(state),
)
except Exception as error:
yield (
(state or {}).get("active_standing") or None,
None,
*direction_values(state),
walk_value(state),
None,
None,
None,
format_failure(error),
state,
history_value(state),
)
def use_active(state):
path = (state or {}).get("active_standing")
if not path:
return None, "๋จผ์ Standing ์บ๋ฆญํฐ๋ฅผ ์์ฑํด ์ฃผ์ธ์."
return path, "ํ์ฑ ์บ๋ฆญํฐ๋ฅผ ์
๋ ฅ์ผ๋ก ๊ฐ์ ธ์์ต๋๋ค."
def walk_base(direction):
return str(BASE_WALKS[direction])
def ui_single_walk(
direction,
source,
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress=gr.Progress(),
):
state = state_copy(state)
if source:
state["directions"][direction] = source
if direction == "south" and not state.get("active_standing"):
state["active_standing"] = source
yield from ui_walks(
[direction],
server,
api_key,
seed,
steps,
cfg,
strength,
state,
progress,
)
def local_process(
source,
palette_source,
palette_mode,
align,
resolution,
output_format,
fps,
set_active,
state,
):
try:
if not source:
raise ValueError("์ฒ๋ฆฌํ ์ด๋ฏธ์ง๋ฅผ ์ ํํด ์ฃผ์ธ์.")
with Image.open(source) as image:
sheet = image.width >= image.height * 1.5
task = "Dress 4x2 walk sheet" if sheet else "Dress standing character"
final = process_output(
source,
source,
task,
palette_source,
palette_mode,
align and sheet,
True,
resolution,
output_format,
fps,
)
final = persist(final, "pixel_palette")
palette = palette_preview(palette_source or final, "palette")
state = state_copy(state)
state["active_palette"] = palette
if set_active and not sheet and output_format == "PNG sheet":
state["active_standing"] = final
state["directions"]["south"] = final
add_history(state, final, "ํฝ์
ยทํ๋ ํธ ์ฒ๋ฆฌ")
return (
final,
final,
palette,
palette,
"์๋ฃ ยท Perfect Pixel ๊ฒฉ์์ 32์ ํ๋ ํธ๋ฅผ ์ ์ฉํ์ต๋๋ค.",
state,
history_value(state),
state.get("active_standing") or None,
)
except Exception as error:
return (
None,
None,
None,
None,
format_failure(error),
state,
history_value(state),
(state or {}).get("active_standing") or None,
)
def check_connection(server_value, api_key_value):
try:
server = normalize_server(server_value)
api_key = resolve_api_key(api_key_value)
if is_cloud(server) and not api_key:
raise ValueError("Comfy Cloud API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
response = requests.get(
f"{server}/api/prompt",
headers=headers(api_key),
timeout=15,
)
response.raise_for_status()
return (
f"์ฐ๊ฒฐ ํ์ธ ยท {urlsplit(server).hostname} ์๋ต "
f"(HTTP {response.status_code})"
)
except Exception as error:
return format_failure(error)
def prompt_preview(task, direction, appearance):
try:
return make_prompt(task, direction, appearance)
except Exception as error:
return str(error)
def ui_advanced(
source,
task,
direction,
appearance,
server,
api_key,
seed,
steps,
cfg,
strength,
palette_source,
palette_mode,
align,
resolution,
output_format,
fps,
state,
):
try:
final, job_id = generate(
server,
api_key,
source,
task,
direction,
appearance,
seed,
steps,
cfg,
strength,
palette_source,
palette_mode,
align,
True,
resolution,
output_format,
fps,
prefix="advanced",
)
state = state_copy(state)
add_history(state, final, f"๊ณ ๊ธ ๋จ์ผ ์์
ยท {TASK_LABELS[task]}")
return (
final,
final,
f"์๋ฃ ยท {TASK_LABELS[task]} ยท {job_id}",
state,
history_value(state),
)
except Exception as error:
return None, None, format_failure(error), state, history_value(state)
def render_stage_strip(state):
state = state or initial_state()
direction_count = len(state.get("directions", {}))
walk_count = len(state.get("walks", {}))
if not state.get("active_standing"):
current = 0
elif direction_count < 4:
current = 2
elif walk_count < 4:
current = 3
else:
current = 4
stages = [
("๋ฒ ์ด์ค", "์ค์ LPC ์๋ณธ ์ ํ"),
("์ธํ", "๋จธ๋ฆฌยท๋ณต์ฅยท์ฅ์"),
("๋ฐฉํฅ", f"{direction_count}/4 ์๋ฃ"),
("๊ฑท๊ธฐ", f"{walk_count}/4 ์๋ฃ"),
("๋ด๋ณด๋ด๊ธฐ", "PNGยทGIF"),
]
items = "".join(
f'<div class="stage {"complete" if index < current else "current" if index == current else ""}">'
f"<b>{title}</b><span>{detail}</span></div>"
for index, (title, detail) in enumerate(stages)
)
return f'<div class="stage-strip" aria-label="LPC ์ ์ ๋จ๊ณ">{items}</div>'
def project_rail(state):
state = state or initial_state()
return (
render_stage_strip(state),
state.get("active_palette") or None,
"ํ์ฌ ํ๋ก์ ํธ ยท "
f"Standing {'์๋ฃ' if state.get('active_standing') else '๋๊ธฐ'} ยท "
f"๋ฐฉํฅ {len(state.get('directions', {}))}/4 ยท "
f"๊ฑท๊ธฐ {len(state.get('walks', {}))}/4",
)
CSS = """
:root {
--paper: #f4f3ed;
--proof: #ffffff;
--ink: #171918;
--muted: #5d625f;
--line: #c9cbc5;
--steel: #e2e3de;
--blue: #2458d6;
--blue-deep: #173b94;
--red: #d13f2d;
--red-deep: #b62f21;
--success: #18723a;
}
body, .gradio-container {
background: var(--paper) !important;
color: var(--ink) !important;
font-family: "Segoe UI", "Noto Sans KR", Arial, sans-serif !important;
}
.gradio-container { max-width: 1760px !important; margin: 0 auto !important; }
#app-shell { border: 1px solid var(--ink); background: var(--proof); }
.app-header {
display: grid;
grid-template-columns: minmax(260px, 1fr) auto;
align-items: end;
gap: 24px;
padding: 22px 26px 18px;
border-bottom: 4px solid var(--ink);
background: var(--proof);
}
.app-header h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.7rem); line-height: 1; letter-spacing: -0.03em; }
.app-header p { max-width: 70ch; margin: 8px 0 0; color: var(--muted); }
.connection-note { color: var(--success); font-weight: 700; white-space: nowrap; }
.stage-strip {
display: grid;
grid-template-columns: repeat(5, 1fr);
border: 1px solid var(--ink);
background: var(--ink);
gap: 1px;
}
.stage { min-height: 68px; padding: 12px 14px; background: var(--proof); }
.stage b, .stage span { display: block; }
.stage b { font-size: 1rem; }
.stage span { margin-top: 4px; color: var(--muted); font-size: .82rem; }
.stage.current { background: var(--blue); color: white; }
.stage.current span { color: #eef3ff; }
.stage.complete { box-shadow: inset 0 -5px 0 var(--success); }
.proof, .tool-rail, .contact-sheet, .settings-panel {
background: var(--proof) !important;
border: 1px solid var(--ink) !important;
border-radius: 2px !important;
}
.proof { position: relative; padding: 12px !important; }
.proof::before, .proof::after {
content: "";
position: absolute;
width: 18px;
height: 18px;
border: 2px solid var(--blue);
border-radius: 50%;
pointer-events: none;
}
.proof::before { top: 10px; left: 10px; }
.proof::after { right: 10px; bottom: 10px; }
.pixel-preview img, .pixel-gallery img, .proof img { image-rendering: pixelated !important; }
.tool-rail { padding: 14px !important; }
.registration-label {
font-family: Consolas, "Courier New", monospace;
color: var(--blue-deep);
font-size: .78rem;
letter-spacing: .02em;
}
.status-line textarea, .status-line input {
font-weight: 700 !important;
color: var(--ink) !important;
background: var(--steel) !important;
}
button.primary {
background: var(--red) !important;
border: 1px solid var(--red-deep) !important;
color: white !important;
border-radius: 2px !important;
font-weight: 800 !important;
}
button.primary:hover { background: var(--red-deep) !important; }
button.secondary { border-radius: 2px !important; border-color: var(--ink) !important; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [role="tab"]:focus-visible {
outline: 3px solid var(--blue) !important;
outline-offset: 2px !important;
}
[role="tablist"] { gap: 0 !important; border-bottom: 1px solid var(--ink); }
[role="tab"] { border-radius: 0 !important; font-weight: 750 !important; min-height: 48px; }
[role="tab"][aria-selected="true"] { background: var(--blue) !important; color: white !important; }
.direction-board { background: var(--proof); border: 1px solid var(--ink); padding: 10px !important; }
.direction-board .gr-image { border-color: var(--blue) !important; }
.palette-strip img { image-rendering: pixelated !important; min-height: 68px; object-fit: contain; }
.proof-log { border-top: 4px solid var(--ink) !important; }
.advanced-panel { border-top: 1px dashed var(--muted) !important; }
footer { display: none !important; }
@media (max-width: 900px) {
.app-header { grid-template-columns: 1fr; }
.connection-note { white-space: normal; }
.stage-strip { grid-template-columns: 1fr; }
.stage { min-height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
"""
def build_ui():
env_note = (
"๋ก์ปฌ ํ๊ฒฝ ์ค์ ๊ฐ์ง"
if ENV_PATH and resolve_api_key("")
else "์ค์ ํญ์์ Comfy ์ฐ๊ฒฐ ํ์"
)
default_server = os.getenv("COMFY_URL", "https://cloud.comfy.org")
base_gallery_value = [(str(BASE_STANDING), "์ฌ์ฑ ๊ธฐ๋ณธ Standing ยท ๋จ์ชฝ")]
with gr.Blocks(
title="LPC ์ฌ๋ฐฉํฅ ์ ์ ์์
๋",
fill_width=True,
delete_cache=(86400, 86400),
) as demo:
project_state = gr.State(initial_state())
gr.HTML(
f"""
<header class="app-header" id="app-shell">
<div>
<div class="registration-label">LPC / FOUR-DIRECTION / PROOF WORKBENCH</div>
<h1>LPC ์ฌ๋ฐฉํฅ ์ ์ ์์
๋</h1>
<p>๋ฒ ์ด์ค ์บ๋ฆญํฐ์์ ์ธํ, ๋ฐฉํฅ, 8ํ๋ ์ ๊ฑท๊ธฐ, 32์ ๋ด๋ณด๋ด๊ธฐ๊น์ง ํ ํ๋ฆ์ผ๋ก ๋ง๋ญ๋๋ค.</p>
</div>
<div class="connection-note">{env_note}</div>
</header>
"""
)
with gr.Row(elem_classes="settings-panel"):
gr.Markdown(
"**๊ณตํต LoRA ๊ฐ๋** ยท ๋ชจ๋ ์์ฑ ์์
์ ์ ์ฉ๋ฉ๋๋ค. "
"`0`์ LoRA ๋นํ์ฑํ, `1.0`์ ๊ธฐ๋ณธ ๊ฐ๋์
๋๋ค."
)
strength = gr.Slider(
0,
1.5,
value=1,
step=0.05,
label="LoRA ๊ฐ๋",
scale=2,
)
with gr.Tabs():
with gr.Tab("๋น ๋ฅธ ์ ์", id="quick"):
quick_stage_strip = gr.HTML(render_stage_strip(initial_state()))
with gr.Row(equal_height=True):
with gr.Column(scale=3, elem_classes="tool-rail"):
gr.Markdown("### ์ค์ LPC ๋ฒ ์ด์ค")
quick_base_gallery = gr.Gallery(
base_gallery_value,
columns=1,
rows=1,
height=250,
label="๋ด์ฅ ๋ฒ ์ด์ค",
show_label=False,
elem_classes="pixel-gallery",
)
quick_source = gr.Image(
value=str(BASE_STANDING),
type="filepath",
label="์ ํ๋ ๋ฒ ์ด์ค",
elem_classes="pixel-preview",
)
gr.Markdown(
"ํ์ต์ ์ฌ์ฉํ ์ฌ์ฑ ๊ธฐ๋ณธ ์ฒดํ๊ณผ ํค๋์
๋๋ค. "
"๋ค๋ฅธ ์ฒดํ์ ํ์ฌ ๋ชจ๋ธ์ ๋ณด์ฅ ๋ฒ์๊ฐ ์๋๋๋ค."
)
with gr.Column(scale=5, elem_classes="proof"):
gr.Markdown("### ํ์ฑ ์บ๋ฆญํฐ ๊ต์ ์")
active_proof = gr.Image(
type="filepath",
label="ํ์ฌ Standing ์บ๋ฆญํฐ",
height=560,
elem_classes="pixel-preview",
)
quick_palette = gr.Image(
type="filepath",
label="ํ์ฑ 32์ ํ๋ ํธ",
height=90,
elem_classes="palette-strip",
)
with gr.Column(scale=4, elem_classes="tool-rail"):
gr.Markdown("### ๋ค์ ์์
ยท ์ธํ ๋ง๋ค๊ธฐ")
quick_appearance = gr.Textbox(
label="์ํ๋ ์ธํ",
lines=5,
placeholder=(
"์: ํ๋ ๋จ๋ฐ๋จธ๋ฆฌ, ๋ถ์ ๊ธดํ ์์, "
"๋จ์ ๋ฐ์ง, ๊ฐ์ ๋ถ์ธ , ๊ธ์ ์๊ฒฝ"
),
)
quick_directions = gr.CheckboxGroup(
choices=[
(DIRECTION_LABELS[direction], direction)
for direction in DIRECTIONS
],
value=list(DIRECTIONS),
label="๋ง๋ค ๋ฐฉํฅ",
)
quick_estimate = gr.Textbox(
value=estimate_jobs(list(DIRECTIONS)),
label="์ ์ฒด ์คํ ์์
์",
interactive=False,
)
quick_dress_button = gr.Button(
"1๋จ๊ณ ยท Standing ์ธํ ๋ง๋ค๊ธฐ",
variant="primary",
elem_classes="primary",
)
quick_dress_reroll = gr.Button(
"์ ์๋๋ก 1๋จ๊ณ ๋ค์ ๋ง๋ค๊ธฐ",
elem_classes="secondary",
)
quick_direction_button = gr.Button(
"2๋จ๊ณ ยท ์ ํ ๋ฐฉํฅ ๋ง๋ค๊ธฐ",
elem_classes="secondary",
)
quick_direction_reroll = gr.Button(
"์ ์๋๋ก 2๋จ๊ณ ๋ค์ ๋ง๋ค๊ธฐ",
elem_classes="secondary",
)
quick_walk_button = gr.Button(
"3๋จ๊ณ ยท ๊ฑท๊ธฐ ๋ง๋ค๊ธฐ",
elem_classes="secondary",
)
quick_walk_reroll = gr.Button(
"์ ์๋๋ก 3๋จ๊ณ ๋ค์ ๋ง๋ค๊ธฐ",
elem_classes="secondary",
)
with gr.Accordion("์ ์ฒด ์๋ ์คํ", open=False):
gr.Markdown(
"๋จ๊ณ ์์๋ ์ ์งํ๊ณ , ๊ฐ์ ๋จ๊ณ์ ๋ฐฉํฅ ์์
์ "
"์ต๋ 4๊ฐ๊น์ง ๋ณ๋ ฌ ์คํํฉ๋๋ค."
)
quick_all_button = gr.Button(
"์ ์ฒด ์คํ",
variant="stop",
elem_classes="primary",
)
quick_file = gr.File(label="์ต๊ทผ ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
gr.Markdown("### ๋ฐฉํฅ ๊ต์ ์")
with gr.Column(elem_classes="direction-board"):
with gr.Row():
quick_north = gr.Image(
label="๋ถ์ชฝ", type="filepath", elem_classes="pixel-preview"
)
with gr.Row():
quick_west = gr.Image(
label="์์ชฝ", type="filepath", elem_classes="pixel-preview"
)
quick_south = gr.Image(
label="๋จ์ชฝ", type="filepath", elem_classes="pixel-preview"
)
quick_east = gr.Image(
label="๋์ชฝ", type="filepath", elem_classes="pixel-preview"
)
quick_walks = gr.Gallery(
label="๋ฐฉํฅ๋ณ 4ร2 ๊ฑท๊ธฐ ์ํธ",
columns=2,
type="filepath",
elem_classes="pixel-gallery contact-sheet",
)
quick_animation = gr.Image(
type="filepath",
label="์ต๊ทผ ์์ฑ ์ํธ ์ ๋๋ฉ์ด์
",
height=300,
elem_classes="pixel-preview",
)
quick_status = gr.Textbox(
value="์ค๋น ยท ์ค์ LPC ๋ฒ ์ด์ค๋ฅผ ์ ํํ๊ณ ์ธํ์ ์ค๋ช
ํด ์ฃผ์ธ์.",
label="์์
์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Tab("Standing ์ธํ", id="standing"):
with gr.Row(equal_height=True):
with gr.Column(scale=4, elem_classes="tool-rail"):
gr.Markdown("### ์๋ณธ ๊ต์ ์")
standing_source = gr.Image(
value=str(BASE_STANDING),
type="filepath",
label="Standing ์
๋ ฅ",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
with gr.Column(scale=4, elem_classes="tool-rail"):
gr.Markdown("### ์ธํ ์ง์")
standing_appearance = gr.Textbox(
label="๋จธ๋ฆฌยท์์ยทํ์ยท์ ๋ฐยท์ฅ์",
lines=8,
placeholder=(
"์: ์ง์ ๋ณด๋ผ์ ์จ์ด๋ธ ๋จธ๋ฆฌ, ํฐ ๋ธ๋ผ์ฐ์ค, "
"๊ฒ์ ์น๋ง, ๊ฒ์ ๋ถ์ธ , ์์ ๋จธ๋ฆฌํ"
),
)
standing_button = gr.Button(
"Standing ์ธํ ์์ฑ",
variant="primary",
elem_classes="primary",
)
standing_reroll = gr.Button(
"์ ์๋๋ก ๋ค์ ์์ฑ",
elem_classes="secondary",
)
standing_status = gr.Textbox(
label="์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Column(scale=5, elem_classes="proof"):
gr.Markdown("### ์์ฑ ๊ต์ ์")
standing_output = gr.Image(
type="filepath",
label="์์ฑ Standing",
height=520,
elem_classes="pixel-preview",
)
standing_palette = gr.Image(
type="filepath",
label="์์ฑ๋ 32์ ํ๋ ํธ",
height=90,
elem_classes="palette-strip",
)
standing_file = gr.File(label="Standing ๋ค์ด๋ก๋")
with gr.Tab("๋ฐฉํฅ ๋ง๋ค๊ธฐ", id="directions"):
with gr.Row():
with gr.Column(scale=3, elem_classes="tool-rail"):
direction_source = gr.Image(
type="filepath",
label="๊ธฐ์ค Standing",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
use_active_direction = gr.Button(
"ํ์ฑ ์บ๋ฆญํฐ ๊ฐ์ ธ์ค๊ธฐ",
elem_classes="secondary",
)
direction_choices = gr.CheckboxGroup(
choices=[
(DIRECTION_LABELS[direction], direction)
for direction in DIRECTIONS
],
value=list(DIRECTIONS),
label="์์ฑ ๋ฐฉํฅ",
)
direction_button = gr.Button(
"์ ํ ๋ฐฉํฅ ๋จ๊ณ๋ณ ์์ฑ",
variant="primary",
elem_classes="primary",
)
direction_reroll = gr.Button(
"์ ์๋๋ก ์ ํ ๋ฐฉํฅ ๋ค์ ์์ฑ",
elem_classes="secondary",
)
direction_status = gr.Textbox(
label="์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Column(scale=9, elem_classes="direction-board"):
gr.Markdown("### ์ฌ๋ฐฉํฅ ํด์ด๋ผ์ด๋ ๊ต์ ํ")
with gr.Row():
direction_north = gr.Image(
label="๋ถ์ชฝ",
type="filepath",
elem_classes="pixel-preview",
)
with gr.Row():
direction_west = gr.Image(
label="์์ชฝ",
type="filepath",
elem_classes="pixel-preview",
)
direction_south = gr.Image(
label="๋จ์ชฝ",
type="filepath",
elem_classes="pixel-preview",
scale=2,
)
direction_east = gr.Image(
label="๋์ชฝ",
type="filepath",
elem_classes="pixel-preview",
)
with gr.Tab("๊ฑท๊ธฐ ๋ง๋ค๊ธฐ", id="walk"):
with gr.Row(equal_height=True):
with gr.Column(scale=3, elem_classes="tool-rail"):
walk_direction = gr.Dropdown(
choices=[
(DIRECTION_LABELS[direction], direction)
for direction in DIRECTIONS
],
value="south",
label="๋ฐฉํฅ",
)
walk_source = gr.Image(
type="filepath",
label="ํด๋น ๋ฐฉํฅ Standing",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
use_active_walk = gr.Button(
"ํ์ฑ ๋จ์ชฝ ์บ๋ฆญํฐ ๊ฐ์ ธ์ค๊ธฐ",
elem_classes="secondary",
)
walk_button = gr.Button(
"์ฒซ ํ๋ ์ โ 8ํ๋ ์ ์์ฑ",
variant="primary",
elem_classes="primary",
)
walk_reroll = gr.Button(
"์ ์๋๋ก ๋ค์ ์์ฑ",
elem_classes="secondary",
)
walk_status = gr.Textbox(
label="์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Column(scale=4, elem_classes="proof"):
gr.Markdown("### ๋ด์ฅ 4ร2 ์์ธ ๋ฒ ์ด์ค")
walk_base_preview = gr.Image(
value=str(BASE_WALKS["south"]),
type="filepath",
label="๋ฐฉํฅ๋ณ ๋ฒ ์ด์ค",
elem_classes="pixel-preview",
)
with gr.Column(scale=5, elem_classes="proof"):
gr.Markdown("### ์์ฑ 4ร2 ๊ฑท๊ธฐ ๊ต์ ์")
walk_output = gr.Image(
type="filepath",
label="์์ฑ ๊ฑท๊ธฐ ์ํธ",
elem_classes="pixel-preview",
)
walk_animation = gr.Image(
type="filepath",
label="ํ์ฌ ์ํธ ์ ๋๋ฉ์ด์
",
height=300,
elem_classes="pixel-preview",
)
walk_file = gr.File(label="๊ฑท๊ธฐ ์ํธ ๋ค์ด๋ก๋")
walk_gallery = gr.Gallery(
label="ํ์ฌ ํ๋ก์ ํธ์ ๋ฐฉํฅ๋ณ ๊ฑท๊ธฐ",
columns=2,
type="filepath",
elem_classes="pixel-gallery contact-sheet",
)
with gr.Tab("ํฝ์
ยทํ๋ ํธ", id="pixel"):
with gr.Row(equal_height=True):
with gr.Column(scale=4, elem_classes="tool-rail"):
pixel_source = gr.Image(
type="filepath",
label="์ฒ๋ฆฌํ Standing ๋๋ 4ร2 ์ํธ",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
use_active_pixel = gr.Button(
"ํ์ฑ ์บ๋ฆญํฐ ๊ฐ์ ธ์ค๊ธฐ",
elem_classes="secondary",
)
palette_source = gr.Image(
type="filepath",
label="๊ณ ์ ํ ํ๋ ํธ ๊ธฐ์ค ์ด๋ฏธ์ง",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
palette_mode = gr.Radio(
PALETTE_CHOICES,
value="Allow new colors (32)",
label="ํ๋ ํธ ๋ฐฉ์",
)
with gr.Column(scale=3, elem_classes="tool-rail"):
pixel_align = gr.Checkbox(
value=True,
label="4ร2 ํ๋ ์ ๋ฐ ์์น ์ ๋ ฌ",
)
pixel_resolution = gr.Radio(
RESOLUTION_CHOICES,
value="Native LPC",
label="ํด์๋",
)
pixel_format = gr.Radio(
FORMAT_CHOICES,
value="PNG sheet",
label="์ถ๋ ฅ ํ์",
)
pixel_fps = gr.Slider(
1, 20, value=8, step=1, label="GIF FPS"
)
set_active = gr.Checkbox(
value=True,
label="Standing ๊ฒฐ๊ณผ๋ฅผ ํ์ฑ ์บ๋ฆญํฐ๋ก ์ง์ ",
)
pixel_button = gr.Button(
"Perfect Pixel ๊ฒฉ์ยท32์ ์ ์ฉ",
variant="primary",
elem_classes="primary",
)
pixel_status = gr.Textbox(
label="์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Column(scale=5, elem_classes="proof"):
pixel_output = gr.Image(
type="filepath",
label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ",
elem_classes="pixel-preview",
)
pixel_palette = gr.Image(
type="filepath",
label="32์ ํ๋ ํธ",
height=90,
elem_classes="palette-strip",
)
with gr.Row():
pixel_file = gr.File(label="์ด๋ฏธ์ง ๋ค์ด๋ก๋")
palette_file = gr.File(label="ํ๋ ํธ PNG")
with gr.Tab("๊ฒฐ๊ณผยท์ค์ ", id="settings"):
with gr.Row():
with gr.Column(scale=7, elem_classes="proof-log"):
gr.Markdown("### ์ต๊ทผ ๊ฒฐ๊ณผ")
history_gallery = gr.Gallery(
label="์ด ์ธ์
์์ ์์ฑํ ํ์ผ",
columns=4,
type="filepath",
elem_classes="pixel-gallery",
)
with gr.Column(scale=5, elem_classes="settings-panel"):
gr.Markdown("### Comfy ์ฐ๊ฒฐ")
server = gr.Textbox(
value=default_server,
label="ComfyUI ์๋ฒ",
placeholder="https://cloud.comfy.org",
)
api_key = gr.Textbox(
type="password",
label="Comfy Cloud API ํค",
placeholder=(
"๋น์๋๋ฉด .env์ COMFY_API_KEY๋ฅผ ์ฌ์ฉํฉ๋๋ค."
),
)
connection_button = gr.Button(
"์ฐ๊ฒฐ ํ์ธ",
elem_classes="secondary",
)
connection_status = gr.Textbox(
value=(
"ํ๊ฒฝ ์ค์ ์ค๋น๋จ"
if ENV_PATH
else "๋ก์ปฌ .env๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค."
),
label="์ฐ๊ฒฐ ์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Accordion("์์ฑ ํ์ง ์ค์ ", open=False):
seed = gr.Number(
value=710001, precision=0, label="Seed"
)
steps = gr.Slider(
12, 40, value=28, step=1, label="Steps"
)
cfg = gr.Slider(
1, 8, value=5, step=0.1, label="CFG"
)
with gr.Accordion(
"๊ณ ๊ธ ๋จ์ผ ์์
ยท ์์ด Task ํ๋กฌํํธ",
open=False,
elem_classes="advanced-panel",
):
with gr.Row():
advanced_source = gr.Image(
type="filepath",
label="์
๋ ฅ ์ด๋ฏธ์ง",
sources=["upload", "clipboard"],
elem_classes="pixel-preview",
)
advanced_output = gr.Image(
type="filepath",
label="๊ฒฐ๊ณผ",
elem_classes="pixel-preview",
)
with gr.Row():
advanced_task = gr.Dropdown(
choices=[
(label, task) for task, label in TASK_LABELS.items()
],
value="Rotate standing character",
label="์์
",
)
advanced_direction = gr.Dropdown(
choices=[
(DIRECTION_LABELS[direction], direction)
for direction in DIRECTIONS
],
value="north",
label="๋ฐฉํฅ",
)
advanced_appearance = gr.Textbox(
label="์ธํ ์ค๋ช
",
lines=3,
)
preview_button = gr.Button(
"์์ด ํ๋กฌํํธ ํ์ธ",
elem_classes="secondary",
)
advanced_prompt = gr.Textbox(
label="์ค์ ์์ด Task ํ๋กฌํํธ",
lines=6,
interactive=False,
)
with gr.Row():
advanced_palette_source = gr.Image(
type="filepath",
label="ํ๋ ํธ ๊ธฐ์ค",
elem_classes="pixel-preview",
)
advanced_palette_mode = gr.Radio(
PALETTE_CHOICES,
value="Lock reference palette",
label="ํ๋ ํธ",
)
with gr.Row():
advanced_align = gr.Checkbox(
value=True,
label="4ร2 ๋ฐ ์์น ์ ๋ ฌ",
)
advanced_resolution = gr.Radio(
RESOLUTION_CHOICES,
value="Upscaled",
label="ํด์๋",
)
advanced_format = gr.Radio(
FORMAT_CHOICES,
value="PNG sheet",
label="์ถ๋ ฅ",
)
advanced_fps = gr.Slider(
1, 20, value=8, step=1, label="GIF FPS"
)
advanced_button = gr.Button(
"๊ณ ๊ธ ๋จ์ผ ์์
์คํ",
variant="primary",
elem_classes="primary",
)
advanced_file = gr.File(label="๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
advanced_status = gr.Textbox(
label="์ํ",
interactive=False,
elem_classes="status-line",
)
with gr.Row(elem_classes="proof-log"):
project_palette_bar = gr.Image(
type="filepath",
label="ํ๋ก์ ํธ 32์ ํ๋ ํธ",
height=90,
elem_classes="palette-strip",
scale=3,
)
project_summary = gr.Textbox(
value="ํ์ฌ ํ๋ก์ ํธ ยท Standing ๋๊ธฐ ยท ๋ฐฉํฅ 0/4 ยท ๊ฑท๊ธฐ 0/4",
label="ํ๋ก์ ํธ ์ํ",
interactive=False,
elem_classes="status-line",
scale=2,
)
quick_base_gallery.select(
lambda: (
str(BASE_STANDING),
str(BASE_STANDING),
str(BASE_STANDING),
),
outputs=[quick_source, standing_source, pixel_source],
)
quick_directions.change(
estimate_jobs,
inputs=quick_directions,
outputs=quick_estimate,
)
common_generation = [server, api_key, seed, steps, cfg, strength]
def bind_generation(button, reroll, fn, inputs, outputs):
normal = button.click(fn, inputs=inputs, outputs=outputs)
repeated = reroll.click(new_seed, outputs=seed).then(
fn,
inputs=inputs,
outputs=outputs,
)
return normal, repeated
def forward_active(state):
active = state.get("active_standing") or None
return active, active, active
bind_generation(
quick_dress_button,
quick_dress_reroll,
ui_dress,
[
quick_source,
quick_appearance,
*common_generation,
project_state,
],
[
active_proof,
quick_palette,
quick_file,
quick_status,
project_state,
history_gallery,
],
)
bind_generation(
quick_direction_button,
quick_direction_reroll,
ui_directions,
[
quick_directions,
active_proof,
*common_generation,
project_state,
],
[
quick_north,
quick_west,
quick_south,
quick_east,
quick_status,
project_state,
history_gallery,
],
)
bind_generation(
quick_walk_button,
quick_walk_reroll,
ui_walks,
[
quick_directions,
*common_generation,
project_state,
],
[
quick_walks,
walk_output,
quick_animation,
quick_file,
quick_status,
project_state,
history_gallery,
],
)
quick_all_button.click(
ui_run_all,
inputs=[
quick_source,
quick_appearance,
quick_directions,
*common_generation,
project_state,
],
outputs=[
active_proof,
quick_palette,
quick_north,
quick_west,
quick_south,
quick_east,
quick_walks,
walk_output,
quick_animation,
quick_file,
quick_status,
project_state,
history_gallery,
],
)
standing_events = bind_generation(
standing_button,
standing_reroll,
ui_dress,
[
standing_source,
standing_appearance,
*common_generation,
project_state,
],
[
standing_output,
standing_palette,
standing_file,
standing_status,
project_state,
history_gallery,
],
)
for event in standing_events:
event.then(
forward_active,
inputs=project_state,
outputs=[active_proof, direction_source, pixel_source],
)
use_active_direction.click(
use_active,
inputs=project_state,
outputs=[direction_source, direction_status],
)
bind_generation(
direction_button,
direction_reroll,
ui_directions,
[
direction_choices,
direction_source,
*common_generation,
project_state,
],
[
direction_north,
direction_west,
direction_south,
direction_east,
direction_status,
project_state,
history_gallery,
],
)
use_active_walk.click(
use_active,
inputs=project_state,
outputs=[walk_source, walk_status],
)
walk_direction.change(
walk_base,
inputs=walk_direction,
outputs=walk_base_preview,
)
bind_generation(
walk_button,
walk_reroll,
ui_single_walk,
[
walk_direction,
walk_source,
*common_generation,
project_state,
],
[
walk_gallery,
walk_output,
walk_animation,
walk_file,
walk_status,
project_state,
history_gallery,
],
)
use_active_pixel.click(
use_active,
inputs=project_state,
outputs=[pixel_source, pixel_status],
)
pixel_button.click(
local_process,
inputs=[
pixel_source,
palette_source,
palette_mode,
pixel_align,
pixel_resolution,
pixel_format,
pixel_fps,
set_active,
project_state,
],
outputs=[
pixel_output,
pixel_file,
pixel_palette,
palette_file,
pixel_status,
project_state,
history_gallery,
active_proof,
],
)
connection_button.click(
check_connection,
inputs=[server, api_key],
outputs=connection_status,
)
preview_button.click(
prompt_preview,
inputs=[
advanced_task,
advanced_direction,
advanced_appearance,
],
outputs=advanced_prompt,
)
advanced_button.click(
ui_advanced,
inputs=[
advanced_source,
advanced_task,
advanced_direction,
advanced_appearance,
*common_generation,
advanced_palette_source,
advanced_palette_mode,
advanced_align,
advanced_resolution,
advanced_format,
advanced_fps,
project_state,
],
outputs=[
advanced_output,
advanced_file,
advanced_status,
project_state,
history_gallery,
],
)
project_state.change(
project_rail,
inputs=project_state,
outputs=[quick_stage_strip, project_palette_bar, project_summary],
)
return demo
def self_check():
assert normalize_server("https://cloud.comfy.org/#project") == (
"https://cloud.comfy.org"
)
try:
normalize_server("https://cloud.comfy.orghttps://cloud.comfy.org")
except ValueError:
pass
else:
raise AssertionError("Repeated server URLs must be rejected.")
assert make_prompt("Rotate standing character", "west", "").startswith(
"TASK_ROTATE_STANDING:"
)
assert "4 by 2" in make_prompt(
"Dress 4x2 walk sheet", "east", "blue hair and black clothes"
)
assert estimate_jobs(list(DIRECTIONS)).startswith("์ ์ฒด ์คํ ์์: 12๊ฐ")
assert MAX_PARALLEL_REQUESTS == 4
assert 1 <= new_seed() <= 2_147_483_647
assert 'class="stage current"' in render_stage_strip(initial_state())
assert BASE_STANDING.exists() and all(path.exists() for path in BASE_WALKS.values())
workflow = json.loads(WORKFLOW.read_text(encoding="utf-8"))
assert workflow["4"]["class_type"] == "LoraLoaderModelOnly"
assert workflow["4"]["inputs"]["model"] == ["3", 0]
first = Image.new("RGB", (64, 64), "red")
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as handle:
first.save(handle.name)
composed = compose_first_frame(handle.name, "south")
with Image.open(composed) as sheet:
assert sheet.size == (2048, 1024)
assert sheet.getpixel((10, 10)) == (255, 0, 0)
Path(handle.name).unlink(missing_ok=True)
Path(composed).unlink(missing_ok=True)
print("self-check passed")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
if args.check:
self_check()
else:
OUTPUT_DIR.mkdir(exist_ok=True)
build_ui().queue(default_concurrency_limit=1).launch(
css=CSS,
allowed_paths=[str(BASE_DIR), str(OUTPUT_DIR)],
ssr_mode=False,
)
|